[CMake] Question about transitive dependencies

Robert Dailey rcdailey at gmail.com
Thu Dec 4 17:01:24 EST 2008


On Thu, Dec 4, 2008 at 3:47 PM, David Cole <david.cole at kitware.com> wrote:

> I think you're looking at Visual Studio project dependencies and not link
> dependencies. It should not build *without* target_link_libraries calls.
> They are necessary to get correct linker command lines. add_dependencies
> does not link any libraries to anything, it just guarantees project building
> order...


However, visual studio's option to "Link Library Dependencies" is enabled
for project C, so this shows up as my command line for project C:

*/OUT:"C:\IT\work\cmaketest\Debug\C.exe" /VERSION:0.0 /INCREMENTAL /NOLOGO
/LIBPATH:".\Debug" /LIBPATH:"." /MANIFEST
/MANIFESTFILE:"C.dir\Debug\C.exe.intermediate.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG
/PDB:"C:/IT/work/cmaketest/Debug/C.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE
/NXCOMPAT /IMPLIB:"C:\IT\work\cmaketest\Debug\C.lib" /ERRORREPORT:PROMPT
kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  myClb.lib ".\debug\b.lib"
".\debug\z.lib" ".\debug\a.lib"*

Notice that both b.lib, z.lib, and a.lib are linked to C here. I'm only
using add_dependencies() and this happens. You state that it only guarantees
project building order, but why (for visual studio, at least) is it
providing link dependencies as well? Is this just an artifact of visual
studio? Can I expect this behavior to be portable to other CMake outputs?

I've also noticed another weird behavior that I can't seem to work around.
I've modified the code I previously posted to this:

cmake_minimum_required( VERSION 2.6 )

link_directories( ${CMAKE_CURRENT_SOURCE_DIR} )

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

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 )
target_link_libraries( B Blb Bfoo )

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

If you look at the command line I pasted earlier for project C, notice that
only myClb.lib is on the command line. I'm expecting to see Blb.lib,
Bfoo.lib, and Zlb.lib there as well. If I go to project B's command line, I
only see this:

*/OUT:"C:\IT\work\cmaketest\Debug\B.lib" /NOLOGO*

It's not even linking against Blb.lib or Bfoo.lib! Why are these target link
libraries being ignored?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081204/8946f173/attachment-0001.htm>


More information about the CMake mailing list