[CMake] strange feature(?) of library cmake generator and build types question

Brad King brad.king at kitware.com
Mon Jul 31 11:21:01 EDT 2006


speedy wrote:
>   VC++ 6 generator -
[snip]
>     // add libraries to executables and dlls (but never include
>     // a library in a library, bad recursion)
>     // NEVER LINK STATIC LIBRARIES TO OTHER STATIC LIBRARIES
>     if ((target.GetType() != cmTarget::SHARED_LIBRARY
>          && target.GetType() != cmTarget::STATIC_LIBRARY 
>          && target.GetType() != cmTarget::MODULE_LIBRARY) || 
>         (target.GetType()==cmTarget::SHARED_LIBRARY && libName != j->first) ||
>         (target.GetType()==cmTarget::MODULE_LIBRARY && libName != j->first))
>       {  
> 
>    Can anyone explain why is this restriction in place - it assumes
>    that user would allways be linking target-to-target (which produces
>    "bad recursion" - actually linking of the same output .lib twice
>    because of VC++ built in project dependencies), but misses a valid
>    use case when user is linking external .lib library to the target.

Currently linking a static library into another library is not supported
because no one has thought through the implementation on all platforms.
 However the link dependency is still preserved and propagated through
to an executable.  Linking an executable to the outer library will
automatically link the inner library to it also.

>    I've actually stumbled on this path trying to separate linking of
>    external libraries for different build types, which is supported
>    only(?) by TARGET_LINK_LIBRARIES() debug & optimized keywords.

Currently this is the only way to control per-configuration linking.
There should really be a way to specify link rules (among others) for
each configuration but this has not been implemented yet.

>    Is there any other way to specify target source files which are
>    specificaly bound to a certain build type?
> 
>    ie. I want debug.cpp & debug.lib to be excluded from all but
>    "Debug" build type?

The build system generators do not support different source lists for
each configuration.  However you can do this:

# CMakeLists.txt
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DMY_DEBUG")
ADD_EXECUTABLE(myexe ... debug_only.cpp)
TARGET_LINK_LIBRARIES(myexe debug my_debug_lib)

// debug_only.cpp
#ifdef MY_DEBUG
# include "debug.cpp"
#endif

-Brad



More information about the CMake mailing list