CMAKE_BUILD_TYPE =发布是否暗含-DNDEBUG? [英] Does CMAKE_BUILD_TYPE=Release imply -DNDEBUG?
问题描述
CMAKE_BUILD_TYPE=Release
隐式暗示 如果不是::期望发生这种暗示是否合理?
If not: isn't it reasonable to expect that this implication takes place?
我想知道在我的 CMakeLists.txt 中遵循 CMake 代码是否多余:
I want to know if following CMake code is redundant in my CMakeLists.txt:
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DNDEBUG)
endif()
推荐答案
是的,它是由CMake设置的.通过查看CMake代码可以发现,对于许多编译器来说,它是已设置的.可能他们只为接受此标志的这些编译器设置了它.这里是有关GCC的一行:
Yes, it is set by CMake. Grepping through the CMake code reveals, that for a host of compilers it is set. Probably they set it only for these compilers, which accepts this flag. Here one of the lines concerning GCC:
Modules/Compiler/GNU.cmake: set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
但是请注意,许多项目会在不保留初始设置的情况下覆盖发行/调试标志,并且还会覆盖用户的定义.
But be aware that many projects overwrite release/debug flags without preserving the initial setting and also overwriting user's definitions.
这篇关于CMAKE_BUILD_TYPE =发布是否暗含-DNDEBUG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!