diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6c53cdbe6d9c011b142814ca48a7f7b1108d731f..dce5cb1b10705526fcad4d7a73902bb4e08346a8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -101,7 +101,10 @@ 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)
+    string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
+    if (uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELWITHDEBINFO)$")
+        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 ()