On Thu, Dec 4, 2008 at 3:38 PM, Bill Hoffman <span dir="ltr"><<a href="mailto:bill.hoffman@kitware.com">bill.hoffman@kitware.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Robert Dailey wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
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()?<br>
<br>
</blockquote>
<br></div>
Sounds like you should be using target_link_libraries instead of add_dependency.</blockquote></div><br>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:<br>
<br>
cmake_minimum_required( VERSION 2.6 )<br>
<br>
project( Z )<br>
add_library( Z STATIC Z.cpp )<br>
<br>
project( A )<br>
add_library( A STATIC A.cpp )<br>
add_dependencies( A Z )<br>
<br>
project( B )<br>
add_library( B STATIC B.cpp )<br>
add_dependencies( B A;Z )<br>
<br>
project( C )<br>
add_executable( C C.cpp )<br>
add_dependencies( C B )<br>
<br>
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.<br>