且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Windows 上的 Cmake 中为调试和发布构建链接不同的库?

更新时间:2023-01-02 20:28:48

根据 CMake 文档:

target_link_libraries( [lib1 [lib2 [...]]] [[debug|optimized|general] ] ...)

调试"、优化"或常规"关键字表示库紧随其后使用仅适用于相应的构建配置.

所以你应该能够做到这一点:

add_executable( MyEXE ${SOURCES})target_link_libraries(MyEXE 调试 3PDebugLib)target_link_libraries(MyEXE优化的3PReleaseLib)

So I've got a library I'm compiling and I need to link different third party things in depending on if it's the debug or release build (specifically the release or debug versions of those libraries). Is there an easy way to do this in Cmake?

Edit: I should note I'm using visual studio

According to the CMake documentation:

target_link_libraries(<target> [lib1 [lib2 [...]]] [[debug|optimized|general] <lib>] ...)

A "debug", "optimized", or "general" keyword indicates that the library immediately following it is to be used only for the corresponding build configuration.

So you should be able to do this:

add_executable( MyEXE ${SOURCES})

target_link_libraries( MyEXE debug 3PDebugLib)
target_link_libraries( MyEXE optimized 3PReleaseLib)