Default compile definition: how to get rid of those

Hello guys,

I am using cmake generator ninja to build my project.
cmake / ninja adds a compile definition: -DNDEBUG automatically and it breaks the build.

What is the method to get rid of this default specifically and any in general?
This happens also for compile options and linker options.
what is the recommended way to stay in control of those?

Thanks,
Serge

Why does -DNDEBUG break your build? This is a standards-defined preprocessor symbol that changes the behavior of the assert macro. If you really want to remove it, you’ll have to string(REPLACE) on the _FLAGS variables.

As Ben already said, this is a define from the C Standard which should not break your build.

But if your project was never built as a Release, only for Debugging purposes, then switching the CMAKE_BUILD_TYPE to Debug helps.

https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html

Thanks Ben / Joseph,

I agree NDEBUG should not break the build but it does and the reason is quite complicated as we are replacing and rebuilding standard libraries taken from another package and this could be challenging of getting into the root cause of the build break.
Can you elaborate a little bit about string(REPLACE) - do you mean resetting CMAKE_<CXX/C>_FLAGS_RELEASE since I could not see that this affects the compile command and its -D options.

Thanks,
Serge

Taking back what I said above: setting CMAKE_CXX_FLAGS_RELEASE to -O3 (instead of ‘-O3 -NDEBUG’ which was the default) solved the problem.
I somehow last week tried to do something similar and it did not help.
Probably a mixup.

Thanks for your help,
Serge