From fab12d74d704ecd0b7bfccf5a69ae14ffe1684ec Mon Sep 17 00:00:00 2001
From: kraus <christof.kraus@psi.ch>
Date: Sun, 28 Feb 2021 17:12:33 +0100
Subject: [PATCH] don't disable glibcxx_assertions when the build type is
 Release but if the variable BUILD_FOR_PRODUCTION is ON

---
 CMakeLists.txt      | 11 ++++++++++-
 ippl/CMakeLists.txt |  5 ++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6c53cdbe6..1366b8838 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,13 @@ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ")
 set (CMAKE_CXX_FLAGS_RELEASE "-O3")
 set (CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")
 
+string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
+if (uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELWITHDEBINFO)$")
+    option (BUILD_FOR_PRODUCTION "Disable all assertion checks; Only use for production" OFF)
+else()
+    option (BUILD_FOR_PRODUCTION "Disable all assertion checks; Only use for production" ON)
+endif()
+
 # Resolve all library dependencies
 set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")
 
@@ -101,7 +108,9 @@ elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
 
     # Enables extra error checking in the form of precondition assertion, such
     # as bounds checking and null pointer checks when dereferencing smart pointers
-    add_compile_options(-Wp,-D_GLIBCXX_ASSERTIONS)
+    if (NOT ${BUILD_FOR_PRODUCTION})
+        add_compile_options(-Wp,-D_GLIBCXX_ASSERTIONS)
+    endif()
 else ()
     message (STATUS "Unknown C++ compiler. Please use the GNU or Intel compiler, if you are having problems.")
 endif ()
diff --git a/ippl/CMakeLists.txt b/ippl/CMakeLists.txt
index 38846d4f2..aa422ad29 100644
--- a/ippl/CMakeLists.txt
+++ b/ippl/CMakeLists.txt
@@ -6,7 +6,7 @@ set (IPPL_VERSION_NAME "V${IPPL_VERSION_MAJOR}.${IPPL_VERSION_MINOR}")
 
 set (IPPL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 
-if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
+if (${BUILD_FOR_PRODUCTION})
     add_definitions (-DNOPAssert)
 endif ()
 
@@ -28,5 +28,4 @@ install (
     FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
     DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
     RENAME ${PROJECT_NAME}Config.cmake
-    )
-
+    )
\ No newline at end of file
-- 
GitLab