0
votes

I'm trying to get something simple going with CMake and I'm running into issues.

I have an Application that needs to link to a DLL that itself links to a Static library. Each of these modules resides in its own folder with its own CMakeLists.txt file.

I use add_subdirectory() to build a project hierarchy, so that the DLL add_subdirectory() adds the Static lib (and links to Static) and the App uses add_subdirectory() to add to the DLL project.

Now, the problem is that in the final project, the CMake makes the App link both to the DLL and the Static Library, although I explicitly ask it in the CMakeLists.txt file to only link to the DLL. Obviously, I don't want the App to link to Static if the DLL already does.

I suspect it has something to do with add_subdirectory() but I don't see how to fix this. Can someone please point me to what I'm doing wrong?

1

1 Answers

0
votes

By default, linkage of the "library1" to the "library2" is propagated to all users of "library1" (e.g., an application). This is done whenever "library2" is SHARED or STATIC.

For supress linkage propagation use PRIVATE linking:

target_link_libraries(library1 PRIVATE library2)