I'm trying to migrate from Visual Studio towards Jetbrains' (awesome) CLion IDE which uses CMake to organize the projects.
Until now, the transition has been smooth: creating CMake projects and importing them into CLion is easy, and I can begin coding on one plateform then continue on another one without problems.
However, one aspect of Visual Studio that I couldn't find an equivalent to in CMake is property sheets: I use them mainly for holding the include directories' paths and the linking libs for libraries (i.e. one .vsprops
file for each library, e.g. OpenCV.vsprops
, Boost.vsprops
, etc.).
This way, in VS, I could share a library's .vsprops
file between different projects without having to configure the paths/libs each time.
Does CMake have a similar mechanism to Visual Studio's property sheets ? How is it possible to store a library's includes/libs in a CMake-parsable file then "import" it in CMakeLists.txt in order to link against the library ?
Basically, what I want to do is:
- Create a "cmake property sheet" (for lack of a better name) for a given library.
- Then, in CMakeLists.txt, write something like
link_target_to_libs(myTarget "path/to/propertySheet1" "path/to/propertySheet2" ...)
.
Since I really want to make the libraries' inclusion/linking into a one-line command, and as far as my (basic) knowledge of CMake goes, I think that some compromise should be made -- mainly sharing the target name's variable between
CMakeLists.txt
and the "property sheets". So this is my solution... until someone proposes a simpler/cleaner one:.cmake
text file,TARGET
-- designates the target (i.e. the first argument ofadd_executable()
),.cmake
file contains a call totarget_include_directories(${TARGET} PRIVATE ${PATH_TO_INCLUDE_DIR})
andtarget_link_libraries(${TARGET} ${LIST_OF_LIBS})
,include("path/to/.cmake")
inCMakeLists.txt
.I have successfully built and executed a simple program that uses X11 and OpenCV with the following files:
x11.cmake
opencv.cmake
CMakeLists.txt
main.cpp
Now, each time I want to use OpenCV in a project/program, I just have to put
include("opencv.cmake")
in the correspondingCMakeLists.txt
.