[CMake] custom configuration types and linking with 3rd-party libs

Brad King brad.king at kitware.com
Mon Aug 25 19:59:04 EDT 2008


cyril_wobow wrote:
> Unfortunately, there is a showstopper : when it comes to linking, tell 
> me if I am wrong, there is no way to express which configuration type 
> should link against which library. In particular, all my configuration 
> types end up linking against the release version of my 3rd party libraries.
> 
> 1st possible solution :
> Is there a way to specify libraries to link with, using a 
> XX_<CONFIG>-style variable ?

Use an IMPORTED library.  This is supported in CMake 2.6:

   add_library(xx_lib STATIC IMPORTED)
   set_target_properties(xx_lib PROPERTIES
     IMPORTED_CONFIGURATIONS "DEBUG;RELEASE"
     IMPORTED_LOCATION_GUIDEBUG ${XX_DEBUG}
     IMPORTED_LOCATION_GUIRELEASE ${XX_RELEASE}
     MAP_IMPORTED_CONFIG_GUIRELEASE RELEASE
     MAP_IMPORTED_CONFIG_CONSOLERELEASE RELEASE
     MAP_IMPORTED_CONFIG_GUIDEBUG DEBUG
     MAP_IMPORTED_CONFIG_CONSOLEDEBUG DEBUG
     )
   # ...
   target_link_libraries(myexe xx_lib)

See related documentation here:

http://www.cmake.org/Wiki/CMake_2.6_Notes#Importing_Targets
http://www.cmake.org/HTML/cmake-2.6.html#command:add_library
http://www.cmake.org/HTML/cmake-2.6.html#prop_tgt:IMPORTED_LOCATION_CONFIG
http://www.cmake.org/HTML/cmake-2.6.html#prop_tgt:MAP_IMPORTED_CONFIG_CONFIG

-Brad



More information about the CMake mailing list