[CMake] How do I use install() with targets that might not be built?
My project consists of a lot of "module" style targets (static libraries, more or less), but only a few top-level targets that a user would actually want to build. The "all" target is empty, that is, every target has "EXCLUDE_FROM_ALL" set. The user will, at compile time, decide to build whichever target they need. A single target may depend on a couple of others, so the end result of a single target being built might be eg. an exe file plus a dll plus a couple of other things. But I also want to provide installation capabilities, so users don't have to hunt down exes and libs scattered throughout CMake's build tree. I might want to create installers using CPack at some point too. How do I do this if all of my targets are EXCLUDE_FROM_ALL? According to the documentation, even if I use the OPTIONAL flag in install(), the behaviour is undefined. Better not do that. The only other option I see is to create custom commands (POST_BUILD style) for every target that copies it to some designated output directory. But then I can't take advantage of CMake's other installation capabilities, and I think that would be invisible to CPack. Is there some other way? I'm using CMake 3.12 on Windows 10/Ubuntu 18.04, if that's relevant. Cheers, Jason -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] CMAKE doesn't pass NVCC flags?
I think you are mixing old and new approaches. Since you have enabled the CUDA language (via your project(...) call), you should be using either CUDAFLAGS or CMAKE_CUDA_FLAGS. I think CUDA_NVCC_FLAGS is only used for the old cuda_add_library or executable functions. Note that finding the cuda package should no longer be necessary. If you support non-CUDA builds you should use CheckLanguage and enable_language(CUDA), and remove CUDA from the project(...) call. Currently if nvcc is not found, configuration will fail because you have CUDA in the project command which makes it required. Hope that helps! -Stephen On Tue, Jul 24, 2018, 1:48 PM Quang Ha wrote: > So, it doesn't seem that my setting in NVCC flags is being used: > > In CMakeLists.txt: > > project(tangram LANGUAGES CXX CUDA) > [...] > > FIND_PACKAGE(CUDA REQUIRED) > if(CUDA_FOUND) > add_definitions(-DCUDA_CALLABLE="__host__ __device__") > set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-Xcompiler="-fopenmp -fPIC") > set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--std=c++11 > --expt-relaxed-constexpr) > set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode > arch=compute_70,code=sm_70) > set(CUDA_PROPAGATE_HOST_FLAGS ON) > set(CUDA_SEPARABLE_COMPILATION OFF) > message(STATUS "CUDA include directories ${CUDA_INCLUDE_DIRS}") > message(STATUS "Overwriting THRUST_DIR to point to > ${CUDA_INCLUDE_DIRS}/thrust") > set(THRUST_DIR "${CUDA_INCLUDE_DIRS}") > set(EXTRA_LIBS ${CUDA_LIBRARIES}) > message("CUDA flags" ${CUDA_NVCC_FLAGS}) > else(CUDA_FOUND) > message(FATAL "CUDA not found") > endif(CUDA_FOUND) > [...] > > Then, at cmake stage: > [...] > -- Overwriting THRUST_DIR to point to > /projects/opt/centos7/cuda/9.0/include/thrust > CUDA flags-Xcompiler="-fopenmp > -fPIC"--std=c++11--expt-relaxed-constexpr-gencodearch=compute_70,code=sm_70 > -- Adding application directory app > [...] > > But then, build fail, and when I do make VERBOSE=1: > [...] > [ 60%] Building CUDA object > app/simple-vfgen-cuda/CMakeFiles/simple-vfgen-cuda.dir/simple-vfgen-cuda.cu.o > cd /home/qth20/develop/tangram/build/app/simple-vfgen-cuda && > /projects/opt/centos7/cuda/9.0/bin/nvcc -DCUDA_CALLABLE="\"__host__ > __device__\"" -DHAVE_LAPACKE -DTHRUST > -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA > -DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_OMP -I/home/qth20/develop/tangram > -I/home/qth20/develop/tangram/build > -I/home/qth20/develop/tangram/cinch/logging > -I/home/qth20/installed/jali/include > -I/home/qth20/installed/jali-tpls/include > -I/home/qth20/installed/jali-tpls/trilinos-12-10-1/include > -I/projects/opt/centos7/openmpi/3.1.0-gcc_8.1.0/include > -I/home/qth20/installed/jali-tpls/trilinos-12-10-1/lib/cmake/Zoltan/../../../include > -I/home/qth20/installed/jali-tpls/include/UnitTest++ -I/usr/include/lapacke > -I/home/qth20/installed/xmof2d/include > -I/projects/opt/centos7/cuda/9.0/include -O3 -DNDEBUG -std=c++11 -x cu > -c /home/qth20/develop/tangram/app/simple-vfgen-cuda/simple-vfgen-cuda.cu > -o CMakeFiles/simple-vfgen-cuda.dir/simple-vfgen-cuda.cu.o > [...] > > None of the flags was passed into nvcc. This is with cmake/3.11.1. Does > upgrading to 3.12 recommended to solve the issue? > > Thanks, > Quang > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
[CMake] CMAKE doesn't pass NVCC flags?
So, it doesn't seem that my setting in NVCC flags is being used: In CMakeLists.txt: project(tangram LANGUAGES CXX CUDA) [...] FIND_PACKAGE(CUDA REQUIRED) if(CUDA_FOUND) add_definitions(-DCUDA_CALLABLE="__host__ __device__") set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-Xcompiler="-fopenmp -fPIC") set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--std=c++11 --expt-relaxed-constexpr) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_70,code=sm_70) set(CUDA_PROPAGATE_HOST_FLAGS ON) set(CUDA_SEPARABLE_COMPILATION OFF) message(STATUS "CUDA include directories ${CUDA_INCLUDE_DIRS}") message(STATUS "Overwriting THRUST_DIR to point to ${CUDA_INCLUDE_DIRS}/thrust") set(THRUST_DIR "${CUDA_INCLUDE_DIRS}") set(EXTRA_LIBS ${CUDA_LIBRARIES}) message("CUDA flags" ${CUDA_NVCC_FLAGS}) else(CUDA_FOUND) message(FATAL "CUDA not found") endif(CUDA_FOUND) [...] Then, at cmake stage: [...] -- Overwriting THRUST_DIR to point to /projects/opt/centos7/cuda/9.0/include/thrust CUDA flags-Xcompiler="-fopenmp -fPIC"--std=c++11--expt-relaxed-constexpr-gencodearch=compute_70,code=sm_70 -- Adding application directory app [...] But then, build fail, and when I do make VERBOSE=1: [...] [ 60%] Building CUDA object app/simple-vfgen-cuda/CMakeFiles/simple-vfgen-cuda.dir/simple-vfgen-cuda.cu.o cd /home/qth20/develop/tangram/build/app/simple-vfgen-cuda && /projects/opt/centos7/cuda/9.0/bin/nvcc -DCUDA_CALLABLE="\"__host__ __device__\"" -DHAVE_LAPACKE -DTHRUST -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA -DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_OMP -I/home/qth20/develop/tangram -I/home/qth20/develop/tangram/build -I/home/qth20/develop/tangram/cinch/logging -I/home/qth20/installed/jali/include -I/home/qth20/installed/jali-tpls/include -I/home/qth20/installed/jali-tpls/trilinos-12-10-1/include -I/projects/opt/centos7/openmpi/3.1.0-gcc_8.1.0/include -I/home/qth20/installed/jali-tpls/trilinos-12-10-1/lib/cmake/Zoltan/../../../include -I/home/qth20/installed/jali-tpls/include/UnitTest++ -I/usr/include/lapacke -I/home/qth20/installed/xmof2d/include -I/projects/opt/centos7/cuda/9.0/include -O3 -DNDEBUG -std=c++11 -x cu -c /home/qth20/develop/tangram/app/simple-vfgen-cuda/simple-vfgen-cuda.cu -o CMakeFiles/simple-vfgen-cuda.dir/simple-vfgen-cuda.cu.o [...] None of the flags was passed into nvcc. This is with cmake/3.11.1. Does upgrading to 3.12 recommended to solve the issue? Thanks, Quang -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] Is this an intended change to cmake behavior in cmake 3.12?
On 07/24/2018 10:28 AM, Brad King wrote: > If no project() command appears anywhere in the top-level CMakeLists.txt > file then one is injected on line zero. FWIW, see this note in the project command docs: https://cmake.org/cmake/help/v3.12/command/project.html "The top-level CMakeLists.txt file for a project must contain a literal, direct call to the project() command..." While we can look into the issue, please also update your project to follow this recommendation. -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] Is this an intended change to cmake behavior in cmake 3.12?
On 07/20/2018 11:48 AM, Buster, James wrote: > Using cmake 3.12: the second “cmake .” issues the following warning: > CMake Warning (dev) in CMakeLists.txt: > Policy CMP0048 is not set: project() command manages VERSION variables. Thanks. I opened an issue for it: https://gitlab.kitware.com/cmake/cmake/issues/18202 Please see that issue for further discussion. > See the “test_project2” macro in CMakeLists.txt? Simply uncomment it. > Even though it isn’t called, uncommenting that macro causes the > “Policy CMP0048” warning to disappear. If no project() command appears anywhere in the top-level CMakeLists.txt file then one is injected on line zero. That is the one that causes the warning. When it is present in the inline macro then no injection is done. It's strange but that's how things evolved. -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] Parallel builds and auto generated header files
I use essentially the technique in the answer below, except with `add_custom_target` instead of `add_custom_command`, so that the hash-generation is always run regardless of whether the temp file is successfully deleted: https://stackoverflow.com/a/41750028/508431 I also use a dummy `add_custom_command` which depends on GITVER_FILE as in the above. IIRC the reason was that in my use case GITVER_FILE is passed as part of a sources list to a macro, and defining the custom command was the only way I could find to properly enforce an ordering dependency in parallel builds: # dummy output so we can depend on it in the external macro, because CMake. add_custom_command(OUTPUT "${GITVER_FILE}" DEPENDS _GEN_GITVER) (I think it was fine running `add_executable`/`add_library` directly in the current CMakeList, but ordering didn't work when passing to a macro -- at least in the version of cmake where I developed this) On Mon, Jul 23, 2018 at 2:50 PM Andrew Fuller wrote: > Using configure_file() at CMake time will appear to work at first glance, > but you'll wind up with stale information when you change revisions without > any CMake change. CMake won't re-run automatically and thus your header > file won't get updated. You'll need to do it at build time to ensure it's > always up-to-date. > > How do the translation units obtain the generated header? There needs to > be some form of dependency between the generated header and the > consumer(s). If you add the generated header as an input to another > target, then CMake should ensure the file is generated before processing > the dependant target. > > Also note that AFAICT add_custom_command will not re-run if the output > file already exists (unless invalidated by a dependency). Since you're > grabbing dynamic information like the commit hash, then you likely want it > to run _every_ time. add_custom_target might be better suited for your > needs. > -- > *From:* CMake on behalf of Robert Dailey < > rcdailey.li...@gmail.com> > *Sent:* July 19, 2018 8:05:06 AM > *To:* CMake > *Subject:* [CMake] Parallel builds and auto generated header files > > I have a Version.hpp file that I have a custom command tied to which > basically runs CMake in script mode to perform configure_file() on it > during build time. The reason it does this is because it builds > Version.hpp using dynamic information, such as defining a macro with > the current SHA1 being built, etc. > > I notice in parallel builds, this header file gets built too late, > because of parallel builds. What if a file includes the header and its > translation unit is built before Version.hpp is generated by the > custom command? Would it be better/simpler to do configure_file() at > configuration time instead of at build time as a custom command? > Here's the logic (some variables are defined elsewhere, but should > give you the gist): > > > set( generated_source_dir ${CMAKE_CURRENT_BINARY_DIR}/Source ) > set( version_file_in ${CMAKE_CURRENT_SOURCE_DIR}/Version.cpp.in ) > set( version_file_out ${generated_source_dir}/Main/Version.cpp ) > > add_custom_command( > OUTPUT ${version_file_out} > COMMAND ${CMAKE_COMMAND} > -D IN_FILE=${version_file_in} > -D OUT_FILE=${version_file_out} > -D GIT_EXECUTABLE=${GIT_EXECUTABLE} > -D BUILD_VERSION=${ZIOSK_BUILD_VERSION} > -P ${CMAKE_CURRENT_SOURCE_DIR}/build_version_header.cmake > WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} > ) > > source_group( Generated FILES ${version_file_out} ) > list( APPEND source_files ${version_file_out} ) > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > -- Powered by www.kitware.com Please keep messages on-topic and che