[CMake] debug- and release options

Brad King brad.king at kitware.com
Mon Feb 6 17:00:32 EST 2006


Filipe Sousa wrote:
> Alexander Neundorf wrote:
>>And that  
>>target_link_libraries(testapp libx optimized liby debug libz ) 
>> 
>>libx is linked in all cases 
>>liby is linked if buildtype is not set and if buildtype==release 
>>libz is only linked if buildtype==debug ? 
> 
> Yes. The default build type is Release IIRC

There is no default, if the build type is not set then _neither_ will be 
linked.  The reason there is no default is a bit complicated (I once 
looked at making Release the default) and I don't have time to explain 
it now.  We have plans to address this problem but for now the "right" 
way is:

IF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
   SET(FOO_LIB optimized liby debug libz)
ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
   SET(FOO_LIB liby)
ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
target_link_libraries(testapp libx ${FOO_LIB})

Effectively one manually chooses the default on a per-library basis.

>>Is it possible to have e.g. a "_debug" appended to the names of all 
>>created libraries when doing a debug build ? 

SET(CMAKE_DEBUG_POSTFIX _debug)

-Brad


More information about the CMake mailing list