cmakelist中区分debug和release下对应的库版本

add_library(${LIBRARY_NAME} ${SOURCES} ${HEADERS})
//生成一个对应的Debug库,用来与Release版本的库区分
set_target_properties(${LIBRARY_NAME} PROPERTIES OUTPUT_NAME "${LIBRARY_NAME}$<$:_d>" )

这样,如果是release下编译,生成的库没有_d的后缀,只有*.lib,如果用debug编译,就会生成带_d的库,*_d.lib

 

另见一处其他方法

Viroleau, Vincent (SCR US EXT) wrote:
 I'm working with Cmake and VS2005, and I would like to have, in the same project, a different name of the library I'm building depending on if I'm on Debug or Release configuration.
 
 For example, if I'm on Debug mode, I would like the output to be mylib_d.dll, and if I'm on Release mode : mylib.dll
 
 I would like also to be able to link with different library depending on the build status.
 
 For example :
 
 When I'm on Debug mode : TARGET_LINK_LIBRARIES(MyLib_d depend_d)
 And on the Release mode : TARGET_LINK_LIBRARIES(MyLib depend)
 
 Here is my Cmakelist :
 
 PROJECT(MyLib)
 
 SET(SRCS init.cpp)
 SET(HEADS init.h)
 
 SET(CMAKE_DEBUG_POSTFIX _d)
 ADD_LIBRARY(MyLib SHARED ${SRCS} ${HEADS})
 
 TARGET_LINK_LIBRARIES(MyLib depend)

If "depend" is built by the same project then it should just work.  If 
it is an outside library then you need

TARGET_LINK_LIBRARIES(MyLib debug depend_d optimized depend)

FYI, CVS CMake has much better support for this, and it will be included in the next release.  CMake 2.2 and earlier were a bit flaky with 
CMAKE_DEBUG_POSTFIX.

你可能感兴趣的:(ubuntu,c++点点滴滴,工具,cmakelists,debug,release,ubuntu)