1
If you interested in assert
functionality only in your own code then the simple one solution
is to provide custom assert. For instance:
#if (MY_DEBUG)
# define MY_ASSERT(A) ... checks here ...
#else
# define MY_ASSERT(A) ... ignore A ...
#endif
Use option
to enable/disable assert:
# CMakeLists.txt
option(ENABLE_MY_ASSERT "Turn on MY_ASSERT checks" OFF)
if(ENABLE_MY_ASSERT)
add_definitions(-DMY_DEBUG=1)
else()
add_definitions(-DMY_DEBUG=0)
endif()
In this case you have full control over your checks, you can verify one
component and ignore others:
... FOO_DEBUG=0 BOO_DEBUG=1 BAR_DEBUG=0 ...
2
Add custom CMAKE_BUILD_TYPE (also see CMAKE_CONFIGURATION_TYPES):
cmake_minimum_required(VERSION 2.8.12)
project(foo)
set(CMAKE_CXX_FLAGS_MYREL "-O3")
add_library(foo foo.cpp)
output:
# Debug
# ... -g ...
# Release
# ... -O3 -DNDEBUG ...
# RelWithDebInfo
# ... -O2 -g -DNDEBUG ...
# MyRel
# ... -O3 ...
CMAKE_CXX_RELEASE_FLAGS
, obviously. – arrowdassert
might be the wrong tool for the job (although there are still valid use cases for your question, for instance debugging a problem that only occurs in Release). Consider introducing additional diagnostic macros that have weaker semantics than assert (which de facto specifies a condition that must never fail) that but can still be enabled selectively (for instance, a condition that can fail if the user passes invalid arguments to a function). – ComicSansMS