jpo38
jpo38

Reputation: 21514

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

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

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?

Upvotes: 7

Views: 1429

Answers (1)

lubgr
lubgr

Reputation: 38267

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)

Upvotes: 7

Related Questions