CMake is being used to compile some C++ files. There are assert
calls in the code. These calls are disabled in Release mode of CMake. It defines NDEBUG
in Release mode, I guess.
If I'm interested in having assert in Release mode of CMake, how do I enable it?
See this answer in the CMake FAQ, i.e.:
Fix it manually by changing the definition of the cache variables
CMAKE_C_FLAGS_RELEASE
andCMAKE_CXX_FLAGS_RELEASE
. This has to be done every time you set up a new build directory.To fix it permanently, create a custom CMake rules file in your source folder with the desired settings for the release flags (omit the option
/D NDEBUG
). Then in your outermost CMakeLists.txt point the variableCMAKE_USER_MAKE_RULES_OVERRIDE
to the custom CMake rules file.This would be a solution for the MSVC compiler:
A better option may be to enable asserts not in Release mode but in RelWithDebInfo mode instead:
But this depends on your project and preferences of course.
1
If you interested in
assert
functionality only in your own code then the simple one solution is to provide custom assert. For instance:Use
option
to enable/disable assert:In this case you have full control over your checks, you can verify one component and ignore others:
2
Add custom CMAKE_BUILD_TYPE (also see CMAKE_CONFIGURATION_TYPES):
output: