Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CMAKE_BUILD_TYPE=Release imply -DNDEBUG?

Tags:

c

assert

cmake

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() 
like image 912
patryk.beza Avatar asked Dec 16 '15 00:12

patryk.beza


People also ask

What is Cmake_build_type?

Specifies the build type on single-configuration generators. This statically specifies what build type (configuration) will be built in this build tree. Possible values are empty, Debug , Release , RelWithDebInfo and MinSizeRel .

What is RelWithDebInfo?

exerpt: "RelwithDebInfo is quite similar to Release mode. It produces fully optimized code, but also builds the program database, and inserts debug line information to give a debugger a good chance at guessing where in the code you are at any time."

How do you clean after CMake?

Simply delete the CMakeFiles/ directory inside your build directory. rm -rf CMakeFiles/ cmake --build . This causes CMake to rerun, and build system files are regenerated. Your build will also start from scratch.

What is default CMake build type?

In this answer, it says Debug is the default cmake build configuration.


1 Answers

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.

like image 167
usr1234567 Avatar answered Oct 04 '22 05:10

usr1234567