Does CMAKE_BUILD_TYPE=Release imply -DNDEBUG?

不问归期 提交于 2019-12-22 01:37:58

问题


Does CMAKE_BUILD_TYPE=Release implicitly imply -DNDEBUG?

If not: isn't it reasonable to expect that this implication takes place?

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()

回答1:


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.



来源:https://stackoverflow.com/questions/34302265/does-cmake-build-type-release-imply-dndebug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!