[CMake] How to specify library dependencies?

Michael Jackson mike.jackson at bluequartz.net
Tue Nov 25 17:21:35 EST 2008


On Nov 25, 2008, at 5:09 PM, Robert Dailey wrote:

> On Mon, Nov 24, 2008 at 4:39 PM, Michael Jackson <mike.jackson at bluequartz.net 
> > wrote:
> One of the better sources to look at is FindBoost.cmake:
>
> Here are some CMake Predefined variables that you will find useful:
> APPLE
> CYGWIN
> MSVC
> UNIX
> WIN32
>
> You can use the cmake --help-variable [variable] for more  
> information if you have the command line handy.
>
> You may also might need to parse the contents of the CMAKE_SYSTEM  
> variable or the CMAKE_HOST_SYSTEM variable. Look at the docs for the  
> differences between them.
>
> CMAKE_HOST_SYSTEM_NAME and CMAKE_SYSTEM_NAME may also come in handy.
>
> What about for library dependencies for different build  
> configurations, such as release and debug?
>
> Suppose I have a_d.lib and a_d.o for debug, and a.lib and a.o for  
> release. What would I do in this case? Must I use the if  
> conditionals for this as well? Not sure how CMake handles this  
> common scenario.


You can use the set_target_properties() to set the various names. Here  
is an excerpt from a CMake file I wrote for the expat code.

IF (BUILD_SHARED_LIBS)
     SET (EXPAT_BUILT_AS_DYNAMIC_LIB 1)
     IF (WIN32 AND NOT MINGW)
         SET(LIB_RELEASE_NAME "expatdll")
         SET(LIB_DEBUG_NAME "expatdll_D")
     ELSE (WIN32 AND NOT MINGW)
         SET(LIB_RELEASE_NAME "expat")
         SET(LIB_DEBUG_NAME "expat_debug")
     ENDIF(WIN32 AND NOT MINGW)
ELSE (BUILD_SHARED_LIBS)
     SET (EXPAT_BUILT_AS_DYNAMIC_LIB)
     IF (WIN32 AND NOT MINGW)
         SET(LIB_RELEASE_NAME "libexpat")
         SET(LIB_DEBUG_NAME "libexpat_D")
     ELSE (WIN32 AND NOT MINGW)
         SET(LIB_RELEASE_NAME "expat")
         SET(LIB_DEBUG_NAME "expat_debug")
     ENDIF(WIN32 AND NOT MINGW)
ENDIF (BUILD_SHARED_LIBS)

ADD_LIBRARY(expat ${LIB_TYPE} ${SOURCES} ${HEADERS})

SET_TARGET_PROPERTIES( expat
     PROPERTIES
     DEBUG_OUTPUT_NAME ${LIB_DEBUG_NAME}
     RELEASE_OUTPUT_NAME ${LIB_RELEASE_NAME}
)

That is one way to do it. I think there may be another.
_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio





More information about the CMake mailing list