From 7fb447d3821049c81666786c946686dee5e89d45 Mon Sep 17 00:00:00 2001
From: Raphael Isemann <teemperor@gmail.com>
Date: Wed, 6 Sep 2017 14:05:16 +0200
Subject: [PATCH] Properly implement the memory_termination build option

It seems my last commit doesn't properly implement the way we
add a define to the dictionary. It seems this is the proper way
to do it instead of just calling add_definitions.
---
 CMakeLists.txt                        | 5 -----
 cmake/modules/RootConfiguration.cmake | 5 +++++
 config/RConfigure.in                  | 1 +
 configure                             | 5 +++++
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1581290083c..903dab3d231 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,11 +103,6 @@ if (JEMALLOC_FOUND)
   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ljemalloc -L ${JEMALLOC_LIBRARY_PATH}")
 endif()
 
-#---Add the define for the experimental deallocation code when memory_termination is on---------
-if(memory_termination)
-  add_definitions(-DR__COMPLETE_MEM_TERMINATION)
-endif()
-
 #---Populate the configure arguments returned by 'root-config --config'-------------------------
 get_cmake_property(variables CACHE_VARIABLES)
 foreach(var ${variables})
diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake
index cb26f0f15d5..f2f16985b59 100644
--- a/cmake/modules/RootConfiguration.cmake
+++ b/cmake/modules/RootConfiguration.cmake
@@ -507,6 +507,11 @@ if(gcctoolchain)
 else()
   set(setgcctoolchain undef)
 endif()
+if(memory_termination)
+  set(memory_term define)
+else()
+  set(memory_term undef)
+endif()
 
 CHECK_CXX_SOURCE_COMPILES("#include <string_view>
   int main() { char arr[3] = {'B', 'a', 'r'}; std::string_view strv(arr, sizeof(arr)); return 0;}" found_stdstringview)
diff --git a/config/RConfigure.in b/config/RConfigure.in
index ee8c0f48233..ecc88357416 100644
--- a/config/RConfigure.in
+++ b/config/RConfigure.in
@@ -37,6 +37,7 @@
 #@hasstdinvoke@ R__HAS_STD_INVOKE /**/
 #@hasllvm@ R__EXTERN_LLVMDIR @llvmdir@
 #@useimt@ R__USE_IMT   /**/
+#@memory_term@ R__COMPLETE_MEM_TERMINATION /**/
 
 #if defined(R__HAS_VECCORE) && defined(R__HAS_VC)
 #ifndef VECCORE_ENABLE_VC
diff --git a/configure b/configure
index bc137a53a6f..26fe09ab31d 100755
--- a/configure
+++ b/configure
@@ -2804,6 +2804,10 @@ if test "x$enable_cxxmodules" = "xyes"; then
     fi
 fi
 
+######################################################################
+# Destruct global/static variables. Always off in classic build.
+memory_term="undef"
+
 ######################################################################
 #
 ### echo %%% libc++ - compile and link using libc++
@@ -8188,6 +8192,7 @@ sed \
     -e "s|@usec++14@|$usecxx14|"           \
     -e "s|@usec++17@|$usecxx17|"           \
     -e "s|@usecxxmodules@|$usecxxmodules|" \
+    -e "s|@memory_term@|$memory_term|"     \
     -e "s|@uselibc++@|$uselibcxx|"         \
     -e "s|@hasstdstringview@|$hasstdstringview|"       \
     -e "s|@hasstdexpstringview@|$hasstdexpstringview|" \
-- 
GitLab