[CMake] Importing a static library, then adding dependencies. Should the dependencies be transitive? They aren't for me!

Nils Gladitz nilsgladitz at gmail.com
Tue Jan 26 16:23:33 EST 2016


On 26.01.2016 21:25, Johnson, Matt (GE Healthcare) wrote:
> I'm using the Visual Studio 2013 generator and cmake 3.4.3.
> Example:
> add_library(NS::a_lib STATIC IMPORTED)
> set_target_properties(NS::a_lib PROPERTIES IMPORTED_LOCATION ${a_lib_location})
> set_target_properties(NS::a_lib PROPERTIES INTERFACE_LINK_LIBRARIES "/path/to/a/another_lib.lib")
> set_target_properties(NS::a_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "an/include/dir")
>
> add_library(NS::b_lib STATIC IMPORTED)
> set_target_properties(NS::b_lib PROPERTIES IMPORTED_LOCATION ${b_lib_location})
> add_dependencies(NS::b_lib NS::a_lib)
>
> add_executable(test_exe main.cpp)
> target_link_libraries(test_exe NS::b_lib) #I expect to pull in all of A's stuff too.  Howver, it doesn't for me.
>
> Assume I have two libraries, A and B.  A has some libraries that it links to.  B depends on A.  I add import targets for both A and B.  I use add_dependencies to signal the B->A dependency.  When I use target_link_libraries for an executable and only list B, should it auto pull in A and A's dependencies?  For me, all I get is B.  I don't get any of its dependencies.  Nor do I get A's include directories.  Am I doing something wrong or misunderstanding the usage of these functions?
>
> I've done a lot of googling and searching the mailing list.  I do see a couple of bugs that revolved around this, but all of them seem to indicate that they are fixed and this is supported.  Am I wrong?  Do I have to manually set the INTERFACE_LINK_LIBRARIES of B?

Yes you have to set INTERFACE_LINK_LIBRARIES.
add_dependencies() is for order (not link) dependencies.

Nils



More information about the CMake mailing list