gil_mo
gil_mo

Reputation: 625

CMake dependencies on a common static lib

I have two separate projects, each builds a shared lib that links with a common static lib. In each of the shared libs' CMakeLists.txt I'll have:

add_dependencies(my_shared1 my_common_lib)

and

add_dependencies(my_shared2 my_common_lib)

The static lib has its own sources and resides in its own folder. What is the best way to define the common static cmake script?

Upvotes: 0

Views: 744

Answers (1)

Matthew
Matthew

Reputation: 2792

If your "projects" are tightly coupled (e.g. live in the same repository / have the same parent directory), just write a CMakeLists.txt above all three that calls add_subdirectory for each project's directory. If you use project in each, they should show up as separate entities in VS/XCode.

If not, just write your CMakeLists.txt for the static library like you normally would, have it export itself (check out export() and install(EXPORTS)) and use find_package in the consumers to find it, then just target_link_libraries the imported target.

If these need to live in separate repositories, but you also need somewhere to create a build that builds all three, then you'll want to look at External Projects.

Upvotes: 2

Related Questions