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

19 篇文章 1 订阅
15 篇文章 0 订阅

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.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值