Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake's equivalent to Visual Studio's Property Sheets (.vsprops)

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:

  1. Create a "cmake property sheet" (for lack of a better name) for a given library.
  2. Then, in CMakeLists.txt, write something like link_target_to_libs(myTarget "path/to/propertySheet1" "path/to/propertySheet2" ...) .
like image 653
maddouri Avatar asked Oct 19 '22 18:10

maddouri


1 Answers

In CMake, libraries can export a package with IMPORTED targets which other buildsystems import using find_package:

http://www.cmake.org/cmake/help/v3.1/manual/cmake-packages.7.html

http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html

http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#imported-targets

Instead of 'linking to property sheets', you link to the IMPORTED targets.

target_link_libraries(myTarget Dep1::Dep1 Dep2::Dep2)

Not all libraries create IMPORTED targets, and not all provide cmake config-file packages. In those cases (including OpenCV and Boost), CMake provides find modules:

http://www.cmake.org/cmake/help/v3.0/manual/cmake-developer.7.html#find-modules

which you use with find_package and link to the contents of variables.

like image 136
steveire Avatar answered Oct 30 '22 13:10

steveire