cmake: enable assertions by default
Users can disable this by setting -DCMAKE_C_FLAGS=-DNDEBUG or -DCMAKE_CXX_FLAGS=-DNDEBUG to disable assertions as desired.
This commit is contained in:
parent
b348a02b85
commit
0c49e5d56e
|
@ -41,7 +41,6 @@ set(PACKAGE_VERSION "${PROJECT_VERSION}")
|
|||
HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH})
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
# Note that RelWithDebInfo disables assertions, use Debug or None to keep them.
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the build type" FORCE)
|
||||
|
||||
# Include "None" as option to disable any additional (optimization) flags,
|
||||
|
@ -102,6 +101,14 @@ if(ENABLE_LIB_ONLY)
|
|||
set(ENABLE_PYTHON_BINDINGS OFF)
|
||||
endif()
|
||||
|
||||
# Do not disable assertions based on CMAKE_BUILD_TYPE.
|
||||
foreach(_build_type "Release" "MinSizeRel" "RelWithDebInfo")
|
||||
foreach(_lang C CXX)
|
||||
string(TOUPPER "CMAKE_${_lang}_FLAGS_${_build_type}" _var)
|
||||
string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" "" ${_var} "${${_var}}")
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
#
|
||||
# If we're running GCC or clang define _U_ to be "__attribute__((unused))"
|
||||
# so we can use _U_ to flag unused function parameters and not get warnings
|
||||
|
|
Loading…
Reference in New Issue