[CMake] Help on first cmake project
Florian Lindner
mailinglists at xgm.de
Fri Jul 7 02:45:35 EDT 2017
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
More information about the CMake
mailing list