[Cmake] What if I _don't_ want link libraries propgated to SUBDIRS?

Brad King brad.king at kitware.com
Thu, 15 Jan 2004 17:11:39 -0500 (EST)


On Thu, 15 Jan 2004, Terry Lorber wrote:

> I'm developing with MS VS 6 and Cmake 1.8 patch 3.
>
> Generally my project tree should link against the multithreaded using
> dll libraries (msvcrt, msvcrtd).  However, in one subdirectory I'd like
> to link against the single-threaded library (libc, libcd).  I've used
> the SET command to set the compiler flags correctly, but I haven't been
> able to get rid of the default libraries.
>
> Here's what I'm doing at my top-level make:
> IF(WIN32)
>    IF(NOT CYGWIN)
>      SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Zi /Zl /O2")
>      SET(CMAKE_CXX_FLAGS_RELEASE "/MD /Zl /O2")
>      SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MD /Zl /O1")
>      SET(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Zl /Od /GZ")
>
>      LINK_LIBRARIES(
>        debug mfcs42d debug msvcrtd
>        optimized mfcs42 optimized msvcrt
>        )
>    ENDIF(NOT CYGWIN)
> ENDIF(WIN32)

The LINK_LIBRARIES command will add libraries to every target listed after
it in that directory and in any subdirectories.  Generally we do not
recommend that it be used, but it is present for backward compatibility.

You should consider using TARGET_LINK_LIBRARIES to specifically add
libraries to each target.  Then no propagation into subdirectories will
occur.  The command is documented in the "Mastering CMake" book and here:

http://www.cmake.org/HTML/Documentation.html

-Brad