cmakelist中區分debug和release下對應的庫版本
add_library(${LIBRARY_NAME} ${SOURCES} ${HEADERS})
//生成一個對應的Debug庫,用來與Release版本的庫區分
set_target_properties(${LIBRARY_NAME} PROPERTIES OUTPUT_NAME "${LIBRARY_NAME}$<$<CONFIG:Debug>:_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.