On Thu, Dec 4, 2008 at 4:20 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;">
Robert Dailey wrote:<div><div></div><div class="Wj3C7c"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Thu, Dec 4, 2008 at 4:06 PM, Alexander Neundorf <<a href="mailto:a.neundorf-work@gmx.net" target="_blank">a.neundorf-work@gmx.net</a> <mailto:<a href="mailto:a.neundorf-work@gmx.net" target="_blank">a.neundorf-work@gmx.net</a>>> wrote:<br>
<br>
But, if you do in cmake:<br>
target_link_libraries(staticLibB staticLibA)<br>
this will not really link (as it would for a shared lib), but it will<br>
nevertheless keep track of the dependencies.<br>
So when liking<br>
target_link_libraries(myApp staticLibB)<br>
cmake knows that it has to add staticLibA to the linker command.<br>
<br>
<br>
But that's one of the things that really bothers me. This is that redundancy I was talking about earlier. If I do:<br>
<br>
add_dependencies( C B )<br>
target_link_libraries( C staticLibB )<br>
<br>
It's a bit pointless. For example, CMake should be smart enough to know that by adding a dependency to B, it should look at the library that it is outputting (In this case, staticLibB.lib) and add that to an implicit call to target_link_libraries(). I only want to use target_link_libraries() to link against external third party libraries that aren't explicitly represented as a project in my CMake build process.<br>
<br>
If I decide to change the output name for the static library B outputs, I'm forced to then revisit all of the target_link_libraries() calls and rename staticLibB. This is a management issue (amongst other things).<br>
<br>
<br>
</blockquote></div></div>
You are missing something. The output name has nothing to do with the name used in target_link_libraries. add_dependencies has nothing to do with linking. It adds an artificial depend between two targets to make sure one is built before the other one for whatever reason needed. If you want to link something, you should use target_link_libraries. For arguments to target_link_libraries you should use the name of the target.<br>
<br>
<br>
add_library(A ...)<br>
add_library(B ...)<div class="Ih2E3d"><br>
target_link_libraries(B A)<br></div>
add_executable(C ...)<div class="Ih2E3d"><br>
target_link_libraries(C B)<br>
<br></div>
The above will link C to B and A. The output names of B and A will be correctly used when linking C.</blockquote></div><br>In your sample code above, I noticed you didn't use add_dependencies(). Does target_link_libraries() guarantee build order when targets are specified instead of libraries?<br>