且构网

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

如何在使用CMake的特定构建配置中为特定目标设置特定的编译器标志?

更新时间:2023-10-17 07:59:34

2.8.12我添加了一个target_compile_options命令来满足这个需求:

In CMake 2.8.12 I added a target_compile_options command to address this need:

http://public.kitware.com/Bug/view.php?id=6493

http://www.cmake.org/cmake/help/git-master/manual/cmake- generator-expressions.7.html

target_compile_options(tgt PRIVATE "/MD$<$<CONFIG:Debug>:d>")

请参阅

http:// www.cmake.org/cmake/help/git-next/manual/cmake-buildsystem.7.html#build-specification-with-generator-expressions

更多关于CMAKE_BUILD_TYPE以及生成器表达式更好的几个原因(例如IMPORTED目标配置映射)。

for more relating to CMAKE_BUILD_TYPE and several reasons why the generator expression is better (eg IMPORTED target config mapping).