Karnivaurus
Karnivaurus

Reputation: 24131

When to include a library in target_link_libraries

Suppose I have an executable Alpha, which must link with a shared library Beta. Beta itself is dependent on shared library Gamma. Gamma already exists for me, but I must compile Alpha and Beta myself, using cmake.

So, with the two CMakeLists.txt files, one for each of Alpha and Beta, I use the command target_link_libraries to indicate which libraries are needed for compilation. My question is: which of these two CMakeLists.txt files do I need to add Gamma?

Beta directly depends on Gamma, because code in Beta calls functions in Gamma. However, Alpha indirectly depends on Gamma too, so do I need to tell Alpha's CMakeLists.txt file about this?

Upvotes: 0

Views: 164

Answers (1)

John Zwinck
John Zwinck

Reputation: 249542

If CMake knows about the Beta->Gamma dependency, it should be able to make everything work. If there were a case where you built Beta without telling CMake about its dependency on Gamma (which is possible to do), you would then have to express the Alpha->Gamma dependency explicitly.

Upvotes: 1

Related Questions