[CMake] Question about transitive dependencies

Robert Dailey rcdailey at gmail.com
Thu Dec 4 16:43:51 EST 2008


On Thu, Dec 4, 2008 at 3:38 PM, Bill Hoffman <bill.hoffman at kitware.com>wrote:

> Robert Dailey wrote:
>
>> Hi,
>>
>> Currently I have 3 projects named A, B, and C. A and B are both static
>> libraries, and C is an executable. B depends on A, and C depends on B via
>> add_dependencies(). When I generate a visual studio 9 project from this
>> setup, how will the libraries be linked? The way I want this to work is for
>> C to link against both A and B, and B will not link against A (Since B's
>> dependencies should transfer to C). Is there a way to accomplish this
>> behavior? I want to avoid using target_link_libraries for the most part
>> because it's redundant. I'm already specifying B as a dependency of C
>> through add_dependency(), why should I have to list B's static library file
>> as a dependency of C's executable? Can't CMake pull this information from
>> the call to add_dependency()?
>>
>>
> Sounds like you should be using target_link_libraries instead of
> add_dependency.


I use target_link_libraries for only the case when I'm linking against
libraries that are not part of the CMake project itself. After a quick test
I found that John Doe's description of how this functions is correct. I
tried the following CMake script:

cmake_minimum_required( VERSION 2.6 )

project( Z )
add_library( Z STATIC Z.cpp )

project( A )
add_library( A STATIC A.cpp )
add_dependencies( A Z )

project( B )
add_library( B STATIC B.cpp )
add_dependencies( B A;Z )

project( C )
add_executable( C C.cpp )
add_dependencies( C B )

In this case, visual studio shows C to be linking against Z, A, and B. Both
A and B, however, do not link against Z, which is exactly what I wanted.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081204/03b6e2ed/attachment.htm>


More information about the CMake mailing list