Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: How to add a dependency that is not a "link" dependency

Tags:

c++

cmake

I have a project configured by CMake. It has a program and a some shared libraries.

  • Some shared libraries are linked by the program (using target_link_libraries statement).
  • Some other shared libraries are not linked by the program, kind of plugins: they are loaded at runtime through LoadLibrary Win32 API.

We use Visual Studio 2015 as CMake target compiler. But from this IDE, when I start my program (press F5) after I modified some code, only the program and linked shared libraries are compiled. The "plugins" to be loaded at runtime are not compiled and so the code do not match the binary.

Is there a way to add a "build dependency", saying that some libraries should be compiled if out-of-date before a program is executed, even if this last one does not link them?

like image 264
jpo38 Avatar asked Oct 17 '19 08:10

jpo38


People also ask

What does Target_link_libraries do in CMake?

Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated. Usage requirements of a target's dependencies affect compilation of its own sources.


1 Answers

There is a CMake command exactly for this purpose: add_dependencies. It should do what you are looking for. Example:

add_executable(mainTarget SomeSource.cpp)
add_library(linkedLib SomeOtherSource.cpp)
add_library(libToBeLoaded MODULE MoreSource.cpp)

target_link_libraries(mainTarget PRIVATE linkedLib)

# This is it:
add_dependencies(mainTarget libToBeLoaded)
like image 138
lubgr Avatar answered Oct 17 '22 14:10

lubgr