[CMake] Three short questions...

Philip Lowman philip at yhbt.com
Tue Jul 15 22:17:41 EDT 2008


On Tue, Jul 15, 2008 at 11:09 AM, Hauke Heibel <heibel at cs.tum.edu> wrote:

>  And the last question is, if it is possible to tell the FindQt.cmake
>> script to give me the plain libraries without the full path of them being
>> prepended (I am talking about the content of the QT_LIBRARIES variable). I
>> would rather like to use LINK_DIRECTORIES and TARGET_LINK_LIBRARIES
>> separately, i.e. I would prefer QtGuid4.lib over C:\Qt\lib\QtGuid4.lib.
>
>
> It should be possible to do this with STRING(REGEX REPLACE... ) if there is
> no better way.  I'm curious why you would need to do this though.  The use
> of TARGET_LINK_LIBRARIES() with full paths is highly desired over
> LINK_LIBRARIES() and TARGET_LINK_LIBRARIES() with a relative library
> filename.
>
> Ok, I see what you mean though I am wondering why in general not all CMake
> Find modules follow this paradigm. For instance all of my ITK libraries seem
> to be set via TARGET_LINK_LIBRARIES() without the path and the path (here
> luckily including the $(OutDir), which I just realized) seems to be set via
> LINK_DIRECTORIES(). Maybe it is done that way to support the multi-target
> MSVC generator because LINK_DIRECTORIES() does not (yet?) support the
> CONFIGURATIONS option.
>

This is probably a good theory as to why it's done this way.  It's one of
the downsides of CMake that using it for MSVC is not quite as
straightforward as using it on other compilers.

To really use CMake properly with VS generated libraries (which have the
release vs. release and debug vs. debug linking requirement) you either have
to add extra calls to FIND_LIBRARY() to find the Debug libraries with an
appended "d" (most CMake find modules don't do this on their own) or use a
hack like this:

FIND_LIBRARY(MYMATH_LIBRARY mymath)
ADD_EXECUTABLE(foo foo.cc)
IF(MSVC)
   STRING(REPLACE ".lib" "d.lib" MYMATH_DEBUG_LIBRARY ${MYMATH_LIBRARY})
   TARGET_LINK_LIBRARIES(foo optimized ${MYMATH_LIBRARY} debug
${MYMATH_DEBUG_LIBRARY})
ELSE()
   TARGET_LINK_LIBRARIES(foo ${MYMATH_LIBRARY})
ENDIF()


-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080715/190a1da8/attachment.htm>


More information about the CMake mailing list