在 add_compile_options()
的手册页中,我没有看到如何修改Release / Debug编译器标志 . Can you use add_compiler_options() to modify the Release/Debug compiler flags? If yes, how?
If no, is the recommended canonical method to modify the release/debug cmake variables[1] as described here ?
[1]即设置cmake变量CMAKE_ <LANG> FLAGS <TYPE>(对于lang c / c,它将是:CMAKE_CXX_FLAGS_RELEASE,CMAKE_CXX_FLAGS_DEBUG,CMAKE_C_FLAGS_RELEASE,CMAKE_C_FLAGS_DEBUG) .
1 回答
如果你想通过几个项目重用你的编译器设置,或者你需要区分C和C之间的编译器选项,我会建议
CMAKE_C_FLAGS
/CMAKE_CXX_FLAGS
变体与toolchain file用于每个支持的编译器(参见例如here或here) .但是如果你在项目中只需要一些额外的C编译器选项,那么采取add_compile_options(),target_compile_options()或target_compile_features()是可行的方法 .
是的,你可以在那里区分
DEBUG
和RELEASE
.Examples
add_compile_options()
命令确实需要generator expressions:要么
要么
或target_compile_features()给出compiler feature你的目标需求
References
CMake CMAKE_CXX_FLAGS enabled optimization unexpectly
Change default value of CMAKE_CXX_FLAGS_DEBUG and friends in CMake
CMake generator expression, differentiate C / C++ code