[CMake] Correct Boost version found, linked against wrong one
Hello, I have a simple cmake file for a small project. That project uses boost and links again a shared lib that also uses boost: find_library(precice precice PATHS $ENV{PRECICE_ROOT}/build $ENV{PRECICE_ROOT}/build/last) find_package(Boost 1.60.0 REQUIRED COMPONENTS system program_options filesystem) add_executable(preciceMap src/preciceMap.cpp src/common.cpp) target_include_directories(preciceMap PRIVATE ${Boost_INCLUDE_DIRS}) target_link_libraries(preciceMap ${Boost_LIBRARIES}) target_link_libraries(preciceMap ${precice}) output is: :~/software/aste/build> cmake .. -- The C compiler identification is GNU 8.2.0 -- The CXX compiler identification is GNU 8.2.0 -- Cray Programming Environment 2.5.17 C -- Check for working C compiler: /opt/cray/pe/craype/2.5.17/bin/cc -- Check for working C compiler: /opt/cray/pe/craype/2.5.17/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Cray Programming Environment 2.5.17 CXX -- Check for working CXX compiler: /opt/cray/pe/craype/2.5.17/bin/CC -- Check for working CXX compiler: /opt/cray/pe/craype/2.5.17/bin/CC -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Build configuration: Debug CMake Warning at /usr/share/cmake/Modules/FindBoost.cmake:725 (message): Imported targets not available for Boost version 106600 Call Stack (most recent call first): /usr/share/cmake/Modules/FindBoost.cmake:763 (_Boost_COMPONENT_DEPENDENCIES) /usr/share/cmake/Modules/FindBoost.cmake:1315 (_Boost_MISSING_DEPENDENCIES) CMakeLists.txt:21 (find_package) CMake Warning at /usr/share/cmake/Modules/FindBoost.cmake:725 (message): Imported targets not available for Boost version 106600 Call Stack (most recent call first): /usr/share/cmake/Modules/FindBoost.cmake:763 (_Boost_COMPONENT_DEPENDENCIES) /usr/share/cmake/Modules/FindBoost.cmake:1315 (_Boost_MISSING_DEPENDENCIES) CMakeLists.txt:21 (find_package) CMake Warning at /usr/share/cmake/Modules/FindBoost.cmake:725 (message): Imported targets not available for Boost version 106600 Call Stack (most recent call first): /usr/share/cmake/Modules/FindBoost.cmake:763 (_Boost_COMPONENT_DEPENDENCIES) /usr/share/cmake/Modules/FindBoost.cmake:1315 (_Boost_MISSING_DEPENDENCIES) CMakeLists.txt:21 (find_package) -- Boost version: 1.66.0 -- Found the following Boost libraries: -- system -- program_options -- filesystem -- Found MPI_C: /opt/cray/pe/craype/2.5.17/bin/cc -- Found MPI_CXX: /opt/cray/pe/craype/2.5.17/bin/CC -- Configuring done -- Generating done -- Build files have been written to: /zhome/academic/HLRS/ipv/ipvflind/software/aste/build :~/software/aste/build> make Scanning dependencies of target preciceMap [ 20%] Building CXX object CMakeFiles/preciceMap.dir/src/preciceMap.cpp.o [ 40%] Building CXX object CMakeFiles/preciceMap.dir/src/common.cpp.o [ 60%] Linking CXX executable preciceMap /usr/bin/ld: warning: libboost_system.so.1.66.0, needed by /zhome/academic/HLRS/ipv/ipvflind/software/precice/build/last/libprecice.so, may conflict with libboost_system.so.1.54.0 /usr/bin/ld: warning: libboost_filesystem.so.1.66.0, needed by /zhome/academic/HLRS/ipv/ipvflind/software/precice/build/last/libprecice.so, may conflict with libboost_filesystem.so.1.54.0 /usr/bin/ld: warning: libboost_program_options.so.1.66.0, needed by /zhome/academic/HLRS/ipv/ipvflind/software/precice/build/last/libprecice.so, may conflict with libboost_program_options.so.1.54.0 /usr/bin/ld: CMakeFiles/preciceMap.dir/src/common.cpp.o: undefined reference to symbol '_ZN5boost15program_options3argB5cxx11E' /opt/hlrs/tools/boost/1.66.0/lib/libboost_program_options.so.1.66.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status CMakeFiles/preciceMap.dir/build.make:124: recipe for target 'preciceMap' failed make[2]: *** [preciceMap] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/preciceMap.dir/all' failed make[1]: *** [CMakeFiles/preciceMap.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2 CMake finds boost 1.66 but why does it try to link against 1.54.0? $BOOST_ROOT is set and $LIBRARY_PATH, $LD_LIBRARY_PATH and $CPLUS_INCLUDE_PATH are also set appropriately. :~/software/aste/build> ls $BOOST_ROOT/lib/*filesystem* /opt/hlrs/tools/boost/1.66.0/lib/libboost_filesystem.a /opt/hlrs/tools/boost/1.66.0/lib/libboost_filesystem.so /opt/hlrs/tools/boost/1.66.0/lib/libboost_filesystem.so.1.66.0 :~/software/aste/build> ls /usr/lib64/*filesystem* /usr/lib64/libboost_filesystem-mt.so /usr/lib64/libboost_filesystem.so /usr/lib64/libboost_filesystem.so.1.54.0 Maybe it prefers the -mt variants? But how can I get it to link against the correct files, i.e., 1.66? Or is the "DSO missing from command line" another
[CMake] Finding a pkg-config file
Hello, on a really weird configured system (but I can't change it), there is a pkg-config file which I want to find with cmake: set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:$ENV{PETSC_DIR}/lib/pkgconfig") set(CMAKE_PREFIX_PATH "$ENV{PETSC_DIR}/lib/pkgconfig") find_package(PkgConfig REQUIRED) pkg_check_modules(PETSC REQUIRED craypetsc_real) but -- Checking for module 'craypetsc_real' -- No package 'craypetsc_real' found CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:363 (message): A required package was not found > cat $PETSC_DIR/lib/pkgconfig/craypetsc_real.pc VERSION=3.8.4.0 PE=GNU pe=gnu GENCOMP=7.1 CPU_TARGET=haswell install_prefix=/opt/cray/pe root=${install_prefix}/petsc/3.8.4.0/real prefix=${root}/${PE}/${GENCOMP}/${CPU_TARGET} libdir=${prefix}/lib includedir=${prefix}/include cray_as_needed= cray_no_as_needed= Name: craypetsc_real Description: Scientific libraries Version: ${VERSION} Libs: -L${libdir} ${cray_as_needed}-lcraypetsc_gnu_71_real${cray_no_as_needed} -fopenmp Libs.private: Requires: Requires.private: mpich >= 7.0 sci_mp >= 13.0 cray-tpsl >= 16.03.1 hdf5_parallel Conflicts: hdf5 Cflags: -I${includedir} pkg-config also finds it: > PKG_CONFIG_PATH=$PETSC_DIR/lib/pkgconfig pkg-config --print-variables > craypetsc_real cray_as_needed prefix libdir [...] CMakeError.log does not exist, CMakeOutput.log I have attached. Thanks! Florian The target system is: Hazelhen - - The host system is: Linux - 4.4.114-94.11-default - x86_64 Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded. Compiler: /opt/cray/pe/craype/2.5.15/bin/CC Build flags: -craympich-dpm Id flags: The output was: 0 Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out" The CXX compiler identification is GNU, found in "/zhome/academic/HLRS/ipv/ipvflind/software/precice/build/cmake-debug/CMakeFiles/3.5.2/CompilerIdCXX/a.out" Determining if the CXX compiler works passed with the following output: Change Dir: /zhome/academic/HLRS/ipv/ipvflind/software/precice/build/cmake-debug/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/gmake" "cmTC_7654f/fast" /usr/bin/gmake -f CMakeFiles/cmTC_7654f.dir/build.make CMakeFiles/cmTC_7654f.dir/build gmake[1]: Entering directory '/zhome/academic/HLRS/ipv/ipvflind/software/precice/build/cmake-debug/CMakeFiles/CMakeTmp' Building CXX object CMakeFiles/cmTC_7654f.dir/testCXXCompiler.cxx.obj /opt/cray/pe/craype/2.5.15/bin/CC -craympich-dpm-o CMakeFiles/cmTC_7654f.dir/testCXXCompiler.cxx.obj -c /zhome/academic/HLRS/ipv/ipvflind/software/precice/build/cmake-debug/CMakeFiles/CMakeTmp/testCXXCompiler.cxx Linking CXX executable cmTC_7654f /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7654f.dir/link.txt --verbose=1 /opt/cray/pe/craype/2.5.15/bin/CC -craympich-dpm CMakeFiles/cmTC_7654f.dir/testCXXCompiler.cxx.obj -o cmTC_7654f gmake[1]: Leaving directory '/zhome/academic/HLRS/ipv/ipvflind/software/precice/build/cmake-debug/CMakeFiles/CMakeTmp' Detecting CXX compiler ABI info compiled with the following output: Change Dir: /zhome/academic/HLRS/ipv/ipvflind/software/precice/build/cmake-debug/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/gmake" "cmTC_7b642/fast" /usr/bin/gmake -f CMakeFiles/cmTC_7b642.dir/build.make CMakeFiles/cmTC_7b642.dir/build gmake[1]: Entering directory '/zhome/academic/HLRS/ipv/ipvflind/software/precice/build/cmake-debug/CMakeFiles/CMakeTmp' Building CXX object CMakeFiles/cmTC_7b642.dir/CMakeCXXCompilerABI.cpp.obj /opt/cray/pe/craype/2.5.15/bin/CC -craympich-dpm-o CMakeFiles/cmTC_7b642.dir/CMakeCXXCompilerABI.cpp.obj -c /usr/share/cmake/Modules/CMakeCXXCompilerABI.cpp Linking CXX executable cmTC_7b642 /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7b642.dir/link.txt --verbose=1 /opt/cray/pe/craype/2.5.15/bin/CC -craympich-dpm-v CMakeFiles/cmTC_7b642.dir/CMakeCXXCompilerABI.cpp.obj -o cmTC_7b642 Using built-in specs. COLLECT_GCC=/opt/gcc/7.3.0/bin/../snos/bin/g++ COLLECT_LTO_WRAPPER=/opt/gcc/7.3.0/snos/libexec/gcc/x86_64-suse-linux/7.3.0/lto-wrapper Target: x86_64-suse-linux Configured with: ../cray-gcc-7.3.0-201801270210.d61239fc6000b/configure --prefix=/opt/gcc/7.3.0/snos --disable-nls --libdir=/opt/gcc/7.3.0/snos/lib --enable-languages=c,c++,fortran --with-gxx-include-dir=/opt/gcc/7.3.0/snos/include/g++ --with-slibdir=/opt/gcc/7.3.0/snos/lib --with-system-zlib --enable-shared --enable-__cxa_atexit --build=x86_64-suse-linux --with-ppl --with-cloog --disable-multilib Thread model: posix gcc version 7.3.0 20180125 (Cray Inc.) (GCC) COMPILER_PATH=/opt/gcc/7.3.0/snos/libexec/gcc/x86_64-suse-linux/7.3.0/:/opt/gcc/7.3.0/snos/libexec/gcc/x86_64-suse-linux/7.3.0/:/opt/gcc/7.3.0/snos/libexec/gcc/x86_64-suse-linux/:/opt/gcc/7.3.0/snos/lib/gcc/x86_64-suse-linux/7.3.0/:/opt/gcc/7.3.0/snos/lib/gcc/x86_64-suse-linux/
Re: [CMake] MPI: Undefined symbol
Hello, Am 20.08.18 um 17:49 schrieb Rafael Sadowski: > On Mon Aug 20, 2018 at 04:24:07PM +0200, Florian Lindner wrote: >> Hello, >> >> copied from a working MPI CMakeLists.txt: >> >> find_package(MPI REQUIRED) > > https://cmake.org/cmake/help/v3.0/module/FindMPI.html > > MPI__FOUND TRUE if FindMPI found MPI flags for > MPI__COMPILERMPI Compiler wrapper for > MPI__COMPILE_FLAGS Compilation flags for MPI programs > MPI__INCLUDE_PATHInclude path(s) for MPI header > MPI__LINK_FLAGS Linking flags for MPI programs > MPI__LIBRARIES All libraries to link MPI programs against > > Looks like you forgot . Should also work, versions without LANG are deprecated, but still supported. But still, I didn't know about the new version and updated my cmake file, but still getting the same error. find_package(MPI REQUIRED COMPONENTS CXX) include_directories(${MPI_CXX_INCLUDE_DIRS}) set(COMPILE_OPTIONS ${COMPILE_FLAGS} ${MPI_CXX_COMPILE_OPTIONS}) set(LINK_FLAGS ${LINK_FLAGS} ${MPI_CXX_LINK_FLAGS}) add_definitions(${MPI_CXX_COMPILE_DEFINTIONS}) add_executable(StructureSolverParallel "StructureSolver_Parallel/structureDataDisplay.cpp" "StructureSolver_Parallel/StructureSolver.cpp" "StructureSolver_Parallel/structureComputeSolution.cpp") target_link_libraries(StructureSolverParallel PUBLIC ${MPI_CXX_LBRARIES}) [ 61%] Building CXX object CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o /usr/bin/c++ -I/home/lindnefn/precice/src -I/opt/mpich/include -Wall -Wextra -Wno-unused-parameter -g -std=gnu++11 -o CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o -c /home/lindnefn/devel/elastictube1d/StructureSolver_Parallel/structureComputeSolution.cpp [ 69%] Linking CXX executable StructureSolverParallel /usr/bin/cmake -E cmake_link_script CMakeFiles/StructureSolverParallel.dir/link.txt --verbose=1 /usr/bin/c++ -Wall -Wextra -Wno-unused-parameter -g CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureDataDisplay.cpp.o CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o -o StructureSolverParallel /home/lindnefn/precice/build/last/libprecice.so /usr/bin/ld: CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o: undefined reference to symbol 'MPI_Init' /usr/bin/ld: /opt/mpich/lib/libmpi.so.12: error adding symbols: DSO missing from command line It doesn't seem to put the MPI_CXX_LIBRARIES at the end. Again, just adding -lmpi to the final command does the trick. Putting message(${MPI_CXX_LIBRARIES}) after the MPI block returns: /opt/mpich/lib/libmpicxx.so/opt/mpich/lib/libmpi.so Any more ideas? Thanks, Florian > >> include_directories(${MPI_INCLUDE_PATH}) >> set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) >> set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS}) >> >> >> add_executable(StructureSolverParallel >> "StructureSolver_Parallel/structureDataDisplay.cpp" >> "StructureSolver_Parallel/StructureSolver.cpp" >> "StructureSolver_Parallel/structureComputeSolution.cpp") >> >> target_link_libraries(StructureSolverParallel PUBLIC ${PRECICE_LIBRARY}) >> target_link_libraries(StructureSolverParallel PUBLIC ${MPI_LBRARIES}) >> >> configuration runs smooth: >> >> % cmake -DMPI_CXX_COMPILER=/opt/mpich/bin/mpicxx >> -DMPI_C_COMPILER=/opt/mpich/bin/mpicc . && make >> -- The CXX compiler identification is GNU 8.2.0 >> [...] >> -- Found MPI_CXX: /opt/mpich/lib/libmpicxx.so (found version "3.1") >> -- Found MPI: TRUE (found version "3.1") >> >> make however: >> >> [ 69%] Linking CXX executable StructureSolverParallel >> /usr/bin/cmake -E cmake_link_script >> CMakeFiles/StructureSolverParallel.dir/link.txt --verbose=1 >> /usr/bin/c++ -Wall -Wextra -Wno-unused-parameter -g >> CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureDataDisplay.cpp.o >> >> CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o >> >> CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o >> -o StructureSolverParallel /home/lindnefn/precice/build/last/libprecice.so >> /usr/bin/ld: >> CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o: >> undefined reference to symbol 'MPI_Init' >> /usr/bin/ld: /opt/mpich/lib/libmpi.so.12: error adding symbols: DSO missing >>
[CMake] MPI: Undefined symbol
Hello, copied from a working MPI CMakeLists.txt: find_package(MPI REQUIRED) include_directories(${MPI_INCLUDE_PATH}) set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS}) add_executable(StructureSolverParallel "StructureSolver_Parallel/structureDataDisplay.cpp" "StructureSolver_Parallel/StructureSolver.cpp" "StructureSolver_Parallel/structureComputeSolution.cpp") target_link_libraries(StructureSolverParallel PUBLIC ${PRECICE_LIBRARY}) target_link_libraries(StructureSolverParallel PUBLIC ${MPI_LBRARIES}) configuration runs smooth: % cmake -DMPI_CXX_COMPILER=/opt/mpich/bin/mpicxx -DMPI_C_COMPILER=/opt/mpich/bin/mpicc . && make -- The CXX compiler identification is GNU 8.2.0 [...] -- Found MPI_CXX: /opt/mpich/lib/libmpicxx.so (found version "3.1") -- Found MPI: TRUE (found version "3.1") make however: [ 69%] Linking CXX executable StructureSolverParallel /usr/bin/cmake -E cmake_link_script CMakeFiles/StructureSolverParallel.dir/link.txt --verbose=1 /usr/bin/c++ -Wall -Wextra -Wno-unused-parameter -g CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureDataDisplay.cpp.o CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/structureComputeSolution.cpp.o -o StructureSolverParallel /home/lindnefn/precice/build/last/libprecice.so /usr/bin/ld: CMakeFiles/StructureSolverParallel.dir/StructureSolver_Parallel/StructureSolver.cpp.o: undefined reference to symbol 'MPI_Init' /usr/bin/ld: /opt/mpich/lib/libmpi.so.12: error adding symbols: DSO missing from command line when I just take the last command line and -lmpi to it, it works. What could be missing there in CMakeLists? Thanks, Florian -- 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 finds libxml2 but still says its missing
Am 08.05.2018 um 15:12 schrieb Rolf Eike Beer: > Am 2018-05-08 14:51, schrieb Florian Lindner: >> Hello, >> >> I try to compile my software like >> >> cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchain.cmake -DBUILD_SHARED_LIBS=off >> ../.. >> >>> cat ../../toolchain.cmake >> SET(CMAKE_SYSTEM_NAME Hazelhen) >> SET(CMAKE_C_COMPILER cc) >> SET(CMAKE_CXX_COMPILER CC) >> SET(CMAKE_Fortran_COMPILER ftn) >> >> which gives me the error: >> >> CMake Error at >> /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 >> (message): >> Could NOT find LibXml2 (missing: LIBXML2_LIBRARIES) (found version "2.9.4") >> Call Stack (most recent call first): >> /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 >> (_FPHSA_FAILURE_MESSAGE) >> /usr/share/cmake/Modules/FindLibXml2.cmake:69 >> (FIND_PACKAGE_HANDLE_STANDARD_ARGS) >> CMakeLists.txt:73 (find_package) > > It can determine the version, e.g. because it can ask pkg-config or finds the > header, but it does not find the library > to link to. Ok, is there any way to get more information on that? CMakeOutput.log contains no reference at all to "xml". The library files are there: > ls /usr/lib/libxml* /usr/lib/libxml2.so.2 /usr/lib/libxml2.so.2.9.4 >> I am a bit puzzled, because it says it found libxml 2.9.4, but then >> again does not set the $LIBXML2_LIBRARIES. >> >> Usage is >> >> find_package(LibXml2 REQlesUIRED) > > sure? Haha, not really. Obviously was typing in the wrong window, in the file it's REQUIRED, of course. > Eike Best, Florian -- 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 finds libxml2 but still says its missing
Hello, I try to compile my software like cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchain.cmake -DBUILD_SHARED_LIBS=off ../.. > cat ../../toolchain.cmake SET(CMAKE_SYSTEM_NAME Hazelhen) SET(CMAKE_C_COMPILER cc) SET(CMAKE_CXX_COMPILER CC) SET(CMAKE_Fortran_COMPILER ftn) which gives me the error: CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message): Could NOT find LibXml2 (missing: LIBXML2_LIBRARIES) (found version "2.9.4") Call Stack (most recent call first): /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake/Modules/FindLibXml2.cmake:69 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:73 (find_package) I am a bit puzzled, because it says it found libxml 2.9.4, but then again does not set the $LIBXML2_LIBRARIES. Usage is find_package(LibXml2 REQlesUIRED) include_directories(${LIBXML2_INCLUDE_DIR}) and later target_link_libraries(foobar PUBLIC ${LIBXML2_LIBRARIES}) cmake version 3.5.2 Thanks! Florian -- 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 does not find module, though it's in MODULE_PATH
Hello, my CMake 3.6.2 complains about not finding FindEigen3.cmake CMake Error at CMakeLists.txt:62 (find_package): By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Eigen3", but CMake did not find one. Could not find a package configuration file provided by "Eigen3" with any of the following names: Eigen3Config.cmake eigen3-config.cmake Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set "Eigen3_DIR" to a directory containing one of the above files. If "Eigen3" provides a separate development package or SDK, be sure it has been installed. However, it's clearly there in ls $CMAKE_MODULE_PATH/FindEigen3.cmake I try to use it like find_package(Eigen3 REQUIRED) What else could be wrong there? Thanks! Florian -- 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] Cache variables from module
Hello, I have a third party FindPETSc.cmake module: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake The problem I have, is that variable PETSC_VERSION is not set when cmake is run for a second time https://github.com/jedbrown/cmake-modules/issues/28 What is best way to deal with that? Can an entire function be cached, e.g. petsc_get_version or is adding CACHE to the set calls of PETSC_VERSION the best way? Adding CACHE INTERNAL gives me error messages: set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}" CACHE INTERNAL "PETSc version" PARENT_SCOPE) CMake Error at tools/cmake-modules/FindPETSc.cmake:314 (if): if given arguments: "3.8.4" "CACHE" "INTERNAL" "PETSc version" "VERSION_LESS" "3.1" Unknown arguments specified Thanks! Florian -- 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] What is the default build type?
Hi, Am 01.08.2017 um 16:59 schrieb J Decker: > I like having something like this defines CMAKE_BUILD_TYPE to be a > droplist of choices... > > > > if( NOT CMAKE_CONFIGURATION_TYPES ) > set( CMAKE_CONFIGURATION_TYPES debug release ) > endif( NOT CMAKE_CONFIGURATION_TYPES ) > > set( CMAKE_BUILD_TYPE release CACHE STRING "Cached cmake build type" ) > set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS > ${CMAKE_CONFIGURATION_TYPES} ) The droplist is really cool! Can't understand why it's not the default this way. https://cmake.org/cmake/help/v3.0/variable/CMAKE_CONFIGURATION_TYPES.html says "This has reasonable defaults on most platforms...", but when I message(${CMAKE_CONFIGURATION_TYPES}) it is empty. Why that? That code also does not seem to set the default: if(NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo) endif() set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build Type") set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} ) So the first commands set the cached value of the string "Build type". The second commands sets the property STRINGS of the variable CMAKE_BUILD_TYPE. Is that correct? # if (NOT CMAKE_BUILD_TYPE) # set(CMAKE_BUILD_TYPE Debug) Uncommenting this sets the default non builds with cmake, but not on ccmake (at least not in the GUI). # endif() message(STATUS "Build configuration: " ${CMAKE_BUILD_TYPE}) Best Thanks, Florian > > > - > > https://cmake.org/cmake/help/v3.0/variable/CMAKE_CONFIGURATION_TYPES.html > > On Mon, Jul 31, 2017 at 9:28 PM, Michael Ellery <mellery...@gmail.com > <mailto:mellery...@gmail.com>> wrote: > > > > > On Jul 31, 2017, at 8:48 PM, Florian Lindner <mailingli...@xgm.de > <mailto:mailingli...@xgm.de>> wrote: > > > > Hello > > > > ccmake shows CMAKE_BUILD_TYPE as unset. From the compile commands it > looks like also nothing like Debug nor Release. > > > > Why is there no well-defined default set? How can I set a default? > > > > Thanks, > > Florian > > -- > > > > Powered by www.kitware.com <http://www.kitware.com> > > > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > <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 > <http://cmake.org/cmake/help/support.html> > > CMake Consulting: http://cmake.org/cmake/help/consulting.html > <http://cmake.org/cmake/help/consulting.html> > > CMake Training Courses: http://cmake.org/cmake/help/training.html > <http://cmake.org/cmake/help/training.html> > > > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > <http://www.kitware.com/opensource/opensource.html> > > > > Follow this link to subscribe/unsubscribe: > > http://public.kitware.com/mailman/listinfo/cmake > <http://public.kitware.com/mailman/listinfo/cmake> > > > my recollection is that an unspecified build type results in a build that > has no optimizations and no debug symbols > generated. I’m not sure what the motivation for those default flags is. > If you want to default to DEBUG, something > like this should work: > > if (NOT CMAKE_BUILD_TYPE) > set(CMAKE_BUILD_TYPE Debug) > endif() > > > -MIke > > -- > > Powered by www.kitware.com <http://www.kitware.com> > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > <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 > <http://cmake.org/cmake/help/support.html> > CMake Consulting: http://cmake.org/cmake/help/consulting.html > <http://cmake.org/cmake/help/consulting.html> > CMake Training Courses: http://cmake.org/cmake/help/training.html > <http://cmake.org/cmake/help/training.html> > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > <http://www.kitware.com/opensource/opensource.html> > > Follow this link to subscribe/unsubscribe: >
Re: [CMake] Source is not rebuild when header changes
Am 01.08.2017 um 21:18 schrieb David Cole: > And in your file "src/CMakeLists.txt" do you add > "${CMAKE_CURRENT_SOURCE_DIR}" (or anything else which resolves to the > "src" directory) to your include directories? No, there is none. I do not added one, since it built correctly. I have no added include_directories(${CMAKE_CURRENT_SOURCE_DIR}), but it still does not get changes to the header. The complete src/CMakeLists.txt: https://pastebin.com/tnQPF2Gj Again, ./CMakeLists.txt: https://pastebin.com/vfReTM1N % grep PetRadial CMakeFiles/precice.dir/* CMakeFiles/precice.dir/CXX.includecache:mapping/PetRadialBasisFctMapping.hpp CMakeFiles/precice.dir/CXX.includecache:/home/florian/precice/src/mapping/config/mapping/PetRadialBasisFctMapping.hpp > > The line which includes the header is > #include "mapping/..." > but there is no local subdirectory "mapping" relative to that file > (which is down in the mapping/config dir) Yes, the include is relative to ./src. Best Thanks, Florian > > > > > On Tue, Aug 1, 2017 at 6:47 AM, Florian Lindner <mailingli...@xgm.de> wrote: >> Hi, >> >> Am 01.08.2017 um 18:32 schrieb David Cole via CMake: >>> What source files include the header? >> >> It's included by src/mapping/config/MappingConfiguration.cpp >> >> https://github.com/precice/precice/blob/develop/src/mapping/config/MappingConfiguration.cpp >> >> https://github.com/precice/precice/blob/develop/src/mapping/PetRadialBasisFctMapping.hpp >> >>> Is one of them listed as a file in your project? >> >> Yes, it's also in the CMakeFiles: >> >> % ll >> build/cmake-debug/CMakeFiles/precice.dir/src/mapping/config/MappingConfiguration.cpp.o >> >> -rw-r--r-- 1 florian florian 1517472 1. Aug 15:08 >> build/cmake-debug/CMakeFiles/precice.dir/src/mapping/config/MappingConfiguration.cpp.o >> >>> Does the **including** file exist at CMake configure time, or is it >>> generated later by a build step? >> >> No, it's a standard plain file. >> >>> What do the lines of code that include the header look like? >> >> #include "mapping/PetRadialBasisFctMapping.hpp" >> >>> >>> CMake uses its own analysis of the source files to determine the >>> depends information, since it needs to generate it without invoking >>> the compiler. This leads to a less-than-100% rate of correctness in >>> the depends information, although usually, it is misses "in the other >>> direction" due to depending on a header file which is included in some >>> conditionally compiled block. (So the typical problem is an extra >>> dependency, not a missing one...) >> >> The header file is (not the including file or the #include itself) is >> guarded by a define >> >> #ifndef PRECICE_NO_PETSC >> >> which is not set. The build also contains the functionality which is guarded >> thereof. >> >>> Perhaps passing along the includers and the exact lines and context of >>> being included will give us a hint about why the dependency is not >>> generated properly in your case. >> >> I'm happy to provide whatever information I can. >> >> If you want to download the entire source of the project, tell me. Right now >> the CMake files are not yet in the >> repository, but I can create a branch and add them there. >> >> My CMake version is 3.8.2. >> >> Best, >> Florian >> >> >>> >>> >>> >>> On Tue, Aug 1, 2017 at 5:18 AM, Florian Lindner <mailingli...@xgm.de> wrote: >>>> Hello, >>>> >>>> on my project, which I'm currently testing with cmake, I just noticed, >>>> that when I modify a header, the project is not >>>> rebuilt. >>>> >>>> The CMakeLists.txt in the root dir is here: https://pastebin.com/vfReTM1N >>>> >>>> The other CMakeLists.txt resides in root/src and lists all the source >>>> (*.cpp) files using GLOBS and adds them to the >>>> parent scope: >>>> >>>> set (sourcesAllNoMain ${sourcesAllNoMain} PARENT_SCOPE) >>>> set (sourcesTests ${sourcesTests} PARENT_SCOPE) >>>> set (sourcesTarchTests ${sourcesTarchTests} PARENT_SCOPE) >>>> >>>> >>>> the questionable header file was not added recently, so I don't think its >>>> related to the GLOBs. >>>> >>>> The header file is also not listed in depends.make file. >>>> >>>> Wh
Re: [CMake] Source is not rebuild when header changes
Hi, Am 01.08.2017 um 18:32 schrieb David Cole via CMake: > What source files include the header? It's included by src/mapping/config/MappingConfiguration.cpp https://github.com/precice/precice/blob/develop/src/mapping/config/MappingConfiguration.cpp https://github.com/precice/precice/blob/develop/src/mapping/PetRadialBasisFctMapping.hpp > Is one of them listed as a file in your project? Yes, it's also in the CMakeFiles: % ll build/cmake-debug/CMakeFiles/precice.dir/src/mapping/config/MappingConfiguration.cpp.o -rw-r--r-- 1 florian florian 1517472 1. Aug 15:08 build/cmake-debug/CMakeFiles/precice.dir/src/mapping/config/MappingConfiguration.cpp.o > Does the **including** file exist at CMake configure time, or is it > generated later by a build step? No, it's a standard plain file. > What do the lines of code that include the header look like? #include "mapping/PetRadialBasisFctMapping.hpp" > > CMake uses its own analysis of the source files to determine the > depends information, since it needs to generate it without invoking > the compiler. This leads to a less-than-100% rate of correctness in > the depends information, although usually, it is misses "in the other > direction" due to depending on a header file which is included in some > conditionally compiled block. (So the typical problem is an extra > dependency, not a missing one...) The header file is (not the including file or the #include itself) is guarded by a define #ifndef PRECICE_NO_PETSC which is not set. The build also contains the functionality which is guarded thereof. > Perhaps passing along the includers and the exact lines and context of > being included will give us a hint about why the dependency is not > generated properly in your case. I'm happy to provide whatever information I can. If you want to download the entire source of the project, tell me. Right now the CMake files are not yet in the repository, but I can create a branch and add them there. My CMake version is 3.8.2. Best, Florian > > > > On Tue, Aug 1, 2017 at 5:18 AM, Florian Lindner <mailingli...@xgm.de> wrote: >> Hello, >> >> on my project, which I'm currently testing with cmake, I just noticed, that >> when I modify a header, the project is not >> rebuilt. >> >> The CMakeLists.txt in the root dir is here: https://pastebin.com/vfReTM1N >> >> The other CMakeLists.txt resides in root/src and lists all the source >> (*.cpp) files using GLOBS and adds them to the >> parent scope: >> >> set (sourcesAllNoMain ${sourcesAllNoMain} PARENT_SCOPE) >> set (sourcesTests ${sourcesTests} PARENT_SCOPE) >> set (sourcesTarchTests ${sourcesTarchTests} PARENT_SCOPE) >> >> >> the questionable header file was not added recently, so I don't think its >> related to the GLOBs. >> >> The header file is also not listed in depends.make file. >> >> What other information can I give? >> >> Thanks, >> Florian >> -- >> >> 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: >> http://public.kitware.com/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: http://public.kitware.com/mailman/listinfo/cmake
[CMake] Source is not rebuild when header changes
Hello, on my project, which I'm currently testing with cmake, I just noticed, that when I modify a header, the project is not rebuilt. The CMakeLists.txt in the root dir is here: https://pastebin.com/vfReTM1N The other CMakeLists.txt resides in root/src and lists all the source (*.cpp) files using GLOBS and adds them to the parent scope: set (sourcesAllNoMain ${sourcesAllNoMain} PARENT_SCOPE) set (sourcesTests ${sourcesTests} PARENT_SCOPE) set (sourcesTarchTests ${sourcesTarchTests} PARENT_SCOPE) the questionable header file was not added recently, so I don't think its related to the GLOBs. The header file is also not listed in depends.make file. What other information can I give? Thanks, Florian -- 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: http://public.kitware.com/mailman/listinfo/cmake
[CMake] What is the default build type?
Hello ccmake shows CMAKE_BUILD_TYPE as unset. From the compile commands it looks like also nothing like Debug nor Release. Why is there no well-defined default set? How can I set a default? Thanks, Florian -- 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: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Append to property COMPILE_DEFINITIONS
Am 22.07.2017 um 15:36 schrieb Craig Scott: > > On Tue, Jul 18, 2017 at 8:50 PM, Florian Lindner <mailingli...@xgm.de > <mailto:mailingli...@xgm.de>> wrote: > > #Works, but I would prefer to have it just once for all targets and at > the top of the file > set_property(TARGET testprecice APPEND > PROPERTY COMPILE_DEFINITIONS "FOO") > > > BTW, you don't include the -D when adding to COMPILE_DEFINITIONS, just > put FOO, not -DFOO. Have a read of the docs, they may give you other clues > for this property (e.g. using the ..._CONFIG variant of it). > > Yeah, I found out that I don't have to add -D. The docs say that > generator expressions are preferable to using _CONFIG > variant. > > > So just to be crystal clear, this is what I would have expected to work if > you wanted the symbol FOO to be defined for > Debug builds for all targets in the current directory and below: > > set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS > $<$:FOO>) Put that in my CMakeLists.txt. Works, but only when I build in the same directory where the CMakeLists.txt file is located, i.e. in source builds. That way: set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY COMPILE_DEFINITIONS $<$:FOO>) it works also out of tree. Still, I don't undertand what is wrong with: set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS $<$:-FOO>) ? Best, Florian > > Note that this directory property is NOT used to initialise the corresponding > target property. Rather, BOTH are combined > to give the final set of command line compile definitions. It does not matter > whether this directory property is set > before or after you call add_executable() within the same CMakeLists.txt file > (or more accurately, within the same > directory scope). > > > > > > > > > On Tue, Jul 18, 2017 at 1:21 PM, Florian Lindner <mailingli...@xgm.de > <mailto:mailingli...@xgm.de> <mailto:mailingli...@xgm.de > <mailto:mailingli...@xgm.de>>> wrote: > > > > Am 18.07.2017 um 10:59 schrieb Craig Scott: > > > You appear to be setting a GLOBAL property where you probably > meant DIRECTORY. You could also consider setting the > > > target property instead rather than applying it to all targets > (unless that's what you want). > > > > I tried to set the property on all targets, therefore I thought > GLOBAL is the right thing. > > > > However, > > > > set_property(DIRECTORY "${CMAKE_SOURCE_DIR}/src" APPEND > > PROPERTY COMPILE_DEFINITIONS "-DFOO") > > > > hasn't had any effect either. > > > > set_property(TARGET testprecice APPEND > > PROPERTY COMPILE_DEFINITIONS "FOO") > > > > works. But setting it on all targets is exactly what I want. How > can I do that? > > > > Best, > > Florian > > > > > > > > > > > On Tue, Jul 18, 2017 at 12:56 PM, Florian Lindner > <mailingli...@xgm.de <mailto:mailingli...@xgm.de> <mailto:mailingli...@xgm.de > <mailto:mailingli...@xgm.de>> > > <mailto:mailingli...@xgm.de <mailto:mailingli...@xgm.de> > <mailto:mailingli...@xgm.de <mailto:mailingli...@xgm.de>>>> wrote: > > > > > > Hello, > > > > > > I want to add compile definitions. Since I want to use > generator expressions, I can't use add_definitions, but > > have to > > > use the COMPILE_DEFINITIONS property, but neither: > > > > > > set_property(GLOBAL APPEND > > > PROPERTY COMPILE_DEFINITIONS "-DFOO") > > > > > > for testing > > > > > > or > > > > > > set_property(GLOBAL APPEND > > > PROPERTY COMPILE_DEFINITIONS $<$:-DDebug>) > > > > > > which should be final result, produces any -DFOO compiler > switches. > > > > > > I also tried placing it before and after the add_executable > call. > > > > > > What is wrong with that call? > > > > > > Thanks, > > > Florian > > > -- > Craig Scott > Melbourne, Australia > https://crascit.com -- 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: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Append to property COMPILE_DEFINITIONS
Am 18.07.2017 um 18:08 schrieb Craig Scott: > It might be easier if you showed the whole CMakeLists.txt file so we can see > the full picture. Is it available somewhere > you can link to, or even better if it's small enough, just post it inline > here. Sure! It's not too long, so I'll paste it here cmake_minimum_required (VERSION 3.1) project(preCICE) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR/CMake}) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") endif() # set_property(GLOBAL APPEND # PROPERTY COMPILE_DEFINITIONS $<$:-DDebug>) option(PETSC "Enable use of the PETSc linear algebra library." ON) if (PETSC) find_library(petsc petsc PATHS $ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib) if(NOT petsc) message(FATAL_ERROR "PETSc was not found") else() message(STATUS "Using PETSc: $ENV{PETSC_ARCH}") endif() endif() find_package (Threads REQUIRED) find_package(Boost 1.60.0 REQUIRED COMPONENTS log log_setup program_options system thread unit_test_framework) add_definitions(-DBOOST_SPIRIT_USE_PHOENIX_V3 -DBOOST_ALL_DYN_LINK) option(MPI "Enables MPI-based communication and running coupling tests." ON) if (MPI) find_package(MPI REQUIRED) include_directories(${MPI_INCLUDE_PATH}) set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS}) endif() find_package(Eigen3 REQUIRED) include_directories(${EIGEN3_INCLUDE_DIR}) option(PYTHON "Python support" ON) if (PYTHON) set(Python_ADDITIONAL_VERSIONS "2.7") find_package(PythonLibs 2.7 REQUIRED) include_directories(${PYTHON_INCLUDE_DIRS}) add_definitions(-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION) else() add_definitions(-DPRECICE_NO_PYTHON) endif() # Fills the sources* variables add_subdirectory("src") # Much target_link_libraries boilerplate add_library(solib ${sourcesAllNoMain}) set_target_properties(solib PROPERTIES OUTPUT_NAME libprecice) target_link_libraries(solib ${PYTHON_LIBRARIES}) target_link_libraries(solib ${MPI_LIBRARIES}) target_link_libraries(solib ${Boost_LIBRARIES}) target_link_libraries(solib ${petsc}) add_library(staticlib ${sourcesAllNoMain}) set_target_properties(staticlib PROPERTIES OUTPUT_NAME libprecice) target_link_libraries(staticlib ${PYTHON_LIBRARIES}) target_link_libraries(staticlib ${MPI_LIBRARIES}) target_link_libraries(staticlib ${Boost_LIBRARIES}) target_link_libraries(staticlib ${petsc}) add_executable(precice "src/drivers/main.cpp" ${sourcesAllNoMain} ${sourcesTarchTests}) target_link_libraries(precice Threads::Threads) target_link_libraries(precice ${PYTHON_LIBRARIES}) target_link_libraries(precice ${MPI_LIBRARIES}) target_link_libraries(precice ${Boost_LIBRARIES}) target_link_libraries(precice ${petsc}) add_executable(testprecice "src/testing/main.cpp" ${sourcesAllNoMain} ${sourcesTests}) target_link_libraries(testprecice Threads::Threads) target_link_libraries(testprecice ${PYTHON_LIBRARIES}) target_link_libraries(testprecice ${MPI_LIBRARIES}) target_link_libraries(testprecice ${Boost_LIBRARIES}) target_link_libraries(testprecice ${petsc}) #Works, but I would prefer to have it just once for all targets and at the top of the file set_property(TARGET testprecice APPEND PROPERTY COMPILE_DEFINITIONS "FOO") > BTW, you don't include the -D when adding to COMPILE_DEFINITIONS, just put > FOO, not -DFOO. Have a read of the docs, they may give you other clues for > this property (e.g. using the ..._CONFIG variant of it). Yeah, I found out that I don't have to add -D. The docs say that generator expressions are preferable to using _CONFIG variant. Best, Florian > > > On Tue, Jul 18, 2017 at 1:21 PM, Florian Lindner <mailingli...@xgm.de > <mailto:mailingli...@xgm.de>> wrote: > > Am 18.07.2017 um 10:59 schrieb Craig Scott: > > You appear to be setting a GLOBAL property where you probably meant > DIRECTORY. You could also consider setting the > > target property instead rather than applying it to all targets (unless > that's what you want). > > I tried to set the property on all targets, therefore I thought GLOBAL is > the right thing. > > However, > > set_property(DIRECTORY "${CMAKE_SOURCE_DIR}/src" APPEND > PROPERTY COMPILE_DEFINITIONS "-DFOO") > > hasn't had any effect either. > > set_property(TARGET testprecice APPEND > PROPERTY COMPILE_DEFINITIONS "FOO") > > works. But setting it on all targets is exactly what I want. How can I do > that? > > Best, > Florian &
Re: [CMake] Append to property COMPILE_DEFINITIONS
Am 18.07.2017 um 10:59 schrieb Craig Scott: > You appear to be setting a GLOBAL property where you probably meant > DIRECTORY. You could also consider setting the > target property instead rather than applying it to all targets (unless that's > what you want). I tried to set the property on all targets, therefore I thought GLOBAL is the right thing. However, set_property(DIRECTORY "${CMAKE_SOURCE_DIR}/src" APPEND PROPERTY COMPILE_DEFINITIONS "-DFOO") hasn't had any effect either. set_property(TARGET testprecice APPEND PROPERTY COMPILE_DEFINITIONS "FOO") works. But setting it on all targets is exactly what I want. How can I do that? Best, Florian > > > On Tue, Jul 18, 2017 at 12:56 PM, Florian Lindner <mailingli...@xgm.de > <mailto:mailingli...@xgm.de>> wrote: > > Hello, > > I want to add compile definitions. Since I want to use generator > expressions, I can't use add_definitions, but have to > use the COMPILE_DEFINITIONS property, but neither: > > set_property(GLOBAL APPEND > PROPERTY COMPILE_DEFINITIONS "-DFOO") > > for testing > > or > > set_property(GLOBAL APPEND > PROPERTY COMPILE_DEFINITIONS $<$:-DDebug>) > > which should be final result, produces any -DFOO compiler switches. > > I also tried placing it before and after the add_executable call. > > What is wrong with that call? > > Thanks, > Florian > -- > > Powered by www.kitware.com <http://www.kitware.com> > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > <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 > <http://cmake.org/cmake/help/support.html> > CMake Consulting: http://cmake.org/cmake/help/consulting.html > <http://cmake.org/cmake/help/consulting.html> > CMake Training Courses: http://cmake.org/cmake/help/training.html > <http://cmake.org/cmake/help/training.html> > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > <http://www.kitware.com/opensource/opensource.html> > > Follow this link to subscribe/unsubscribe: > http://public.kitware.com/mailman/listinfo/cmake > <http://public.kitware.com/mailman/listinfo/cmake> > > > > > -- > Craig Scott > Melbourne, Australia > https://crascit.com -- 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: http://public.kitware.com/mailman/listinfo/cmake
[CMake] Append to property COMPILE_DEFINITIONS
Hello, I want to add compile definitions. Since I want to use generator expressions, I can't use add_definitions, but have to use the COMPILE_DEFINITIONS property, but neither: set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS "-DFOO") for testing or set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS $<$:-DDebug>) which should be final result, produces any -DFOO compiler switches. I also tried placing it before and after the add_executable call. What is wrong with that call? Thanks, Florian -- 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: http://public.kitware.com/mailman/listinfo/cmake
[CMake] How to add project files?
Hello, our project, which is currently using scons is structured like this ROOT - SConstruct - CMakeLists.txt - src/ - SConscript - CMAkeLists.txt - Module1 - somesourcefiles.cpp - tests/ - testsourcefiles.cpp - config/ - configsourcefile.cpp - Module2 (like Module1) - ... Right now the SConstruct calls SConscript sourcesModule1 = [ Glob('Module1/*.cpp'), Glob('Module2/config/*.cpp') ] The test files (Boost Test) are compiled to a standalone executable sourcesTests = [ Glob('*/tests/*.cpp'), File("testing/main.cpp") ] We currently have 4 targets. A static and dynamic lib (comprised of all modules), a binary (comprised of all modules + main.cpp) and the test binary (all modules, tests and test main.cpp). I was able to replicate that structure with CMake and it builds fine: src/CMakeLists.txt: file(GLOB sourcesAllNoMain "Module1/*.cpp" "Module1/config/*.cpp") file(GLOB sourcesTests "*/tests/*.cpp") set (sourcesAllNoMain ${sourcesAllNoMain} PARENT_SCOPE) set (sourcesTests ${sourcesTests} PARENT_SCOPE) ROOT/CMakeLists.txt: add_subdirectory("src") add_library(solib ${sourcesAllNoMain}) set_target_properties(solib PROPERTIES OUTPUT_NAME libprecice) target_link_libraries(solib ${PYTHON_LIBRARIES}) target_link_libraries(solib ${MPI_LIBRARIES}) target_link_libraries(solib ${Boost_LIBRARIES}) target_link_libraries(solib ${petsc}) Now, in the docs I everywhere read not to add the files using GLOB. However, I have found no definitive guide how to add project files in a large project with subdirs like that. How would you do it in cmakeish fashion? I know this might be a FAQ, but googled for days and found no suitable answer. Thanks a lot, Florian -- 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: http://public.kitware.com/mailman/listinfo/cmake
[CMake] Can not get C++ 11 support enabled
Hello, my complete cmake file looks like that: cmake_minimum_required (VERSION 3.1) project(Preallocation) add_executable(prealloc prealloc_parallel.cpp) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_compile_options(-std=c++11) find_library(petsc petsc PATHS $ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib) if(NOT petsc) message(FATAL_ERROR "petsc was not found") endif() target_link_libraries(prealloc ${petsc}) find_package(Boost 1.60.0 REQUIRED COMPONENTS program_options) target_link_libraries(prealloc ${Boost_LIBRARIES}) find_package(MPI REQUIRED) target_link_libraries(prealloc ${MPI_LIBRARIES}) set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS}) but still, cmake refused to enable c++11 support, make VERBOSE=1 shows [ 50%] Building CXX object CMakeFiles/prealloc.dir/prealloc_parallel.cpp.o /usr/bin/c++ -O3 -DNDEBUG -o CMakeFiles/prealloc.dir/prealloc_parallel.cpp.o -c /data/scratch/lindnefn/petsc_prealloc/prealloc_parallel.cpp In file included from /usr/include/c++/5/random:35:0, from /data/scratch/lindnefn/petsc_prealloc/prealloc_parallel.cpp:4: /usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support \ ^ In file included from /data/scratch/lindnefn/software/petsc/include/petscis.h:7:0, from /data/scratch/lindnefn/software/petsc/include/petscvec.h:9, from /data/scratch/lindnefn/software/petsc/include/petscmat.h:6, from /data/scratch/lindnefn/petsc_prealloc/prealloc_parallel.cpp:7: /data/scratch/lindnefn/software/petsc/include/petscsys.h:130:17: fatal error: mpi.h: No such file or directory compilation terminated. What is wrong here+ cmake 3.5.1 Thanks, Florian -- 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: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Help on first cmake project
Am 07.07.2017 um 16:47 schrieb J Decker: > > > On Thu, Jul 6, 2017 at 11:45 PM, Florian Lindner <mailingli...@xgm.de > <mailto:mailingli...@xgm.de>> wrote: > > Hello, > > coming from scons I want to take a look into cmake... > > My CMakeList.txt looks like: > > > cmake_minimum_required (VERSION 3.0) > project (ASTE) > > add_executable(readMesh readMesh.cpp) > > find_library(precice precice PATHS $ENV{PRECICE_ROOT}/build/last) > target_link_libraries(readMesh ${precice}) > set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} > $ENV{PRECICE_ROOT}/build/last) > > > find_package(Boost 1.60.0 > COMPONENTS program_options filesystem > REQUIRED) > target_link_libraries(readMesh ${Boost_LIBRARIES}) > > find_package(MPI REQUIRED) > target_link_libraries(readMesh ${MPI_LIBRARIES}) > set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) > set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS}) > > > and does it job, i.e. the target builds. precice is out own, > independently build library. > > However, I have several questions: > > * Can I make target_link_libraries add a library for all defined targets? > At the moment, there is only one, but in the > projekt there are multiple, very similiar targets built. > > No; each target needs to have target_link_libaries. You can build a list of > libs to add like set( common_deps > ${Boost_LIBRARIES} ${MPI_LIBRARIES} ) ; or appending to a variable like you > did with COMPILE_FLAGS. Ok, that would be nice feature I think. > * Can I make find_library to treat the library as required, as with > find_package? > > > can add if( -NOTFOUND ) message( ERROR "xxx not found" ) Ok. I am a bit surprised, that there is no REQUIRED flag, just like it is with the similar find_package. > can wrap that in a macro for simplification... > > macro( my_find_library var ) > find_library( ${var} ${ARGN} ) > if( ${var}-NOTFOUND ) > message( FATAL_ERROR "${ARG2} was not found" ) > endif() > endmacro() find_library(precice precice PATHS $ENV{PRECICE_ROOT}/build/last) if( precice-NOTFOUND ) message(FATAL_ERROR "preCICE was not found") endif() but the missing library is not caught and the subsequent call to target_link_libraries fails. Using if(NOT precice) instead made it working. > (assumes that you're using the single name version, and not multiple names > using NAME command in find_library) > > > * Can I reused the value of find_library's PATH setting? Especially if > there are multiple PATHs, wouldn't it be nice to > have a precice-LIBPATH that contains the path, where the library was > found? So I can add this to CMAKE_LIBRARY_PATH? Or > is there another function that does all that? > > Yes, these become available for all sub projects also. INCLUDE_DIRECTORIES() > and LINK_DIRECTORIES() will also get > inherited by child projects. Not sure if I got that, but we'll see... Best, Florian -- 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: http://public.kitware.com/mailman/listinfo/cmake
[CMake] Help on first cmake project
Hello, coming from scons I want to take a look into cmake... My CMakeList.txt looks like: cmake_minimum_required (VERSION 3.0) project (ASTE) add_executable(readMesh readMesh.cpp) find_library(precice precice PATHS $ENV{PRECICE_ROOT}/build/last) target_link_libraries(readMesh ${precice}) set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} $ENV{PRECICE_ROOT}/build/last) find_package(Boost 1.60.0 COMPONENTS program_options filesystem REQUIRED) target_link_libraries(readMesh ${Boost_LIBRARIES}) find_package(MPI REQUIRED) target_link_libraries(readMesh ${MPI_LIBRARIES}) set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS}) and does it job, i.e. the target builds. precice is out own, independently build library. However, I have several questions: * Can I make target_link_libraries add a library for all defined targets? At the moment, there is only one, but in the projekt there are multiple, very similiar targets built. * Can I make find_library to treat the library as required, as with find_package? * Can I reused the value of find_library's PATH setting? Especially if there are multiple PATHs, wouldn't it be nice to have a precice-LIBPATH that contains the path, where the library was found? So I can add this to CMAKE_LIBRARY_PATH? Or is there another function that does all that? * Is there a way to clean cmake cache, other than rm -rf CMakeFiles CMakeCache.txt. Would be nice, when playing around and frequently changing the CMakeLists.txt * I am a bit suprised that finding/or not finding MPI or precice is not printed out when executing cmake. * Any other advises you want to give me? Thanks for helping a beginner! Florian -- 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: http://public.kitware.com/mailman/listinfo/cmake