From 0df8f67a0c8e55f47017253227b4eceac2b241af Mon Sep 17 00:00:00 2001
From: Pere Mato <pere.mato@cern.ch>
Date: Fri, 17 Jun 2016 18:45:16 +0200
Subject: [PATCH] Fix for ROOT-8231 - _GLIBCXX_USE_CXX11_ABI=0 should be
 propagated into root-config --cflags

---
 CMakeLists.txt                         | 48 ++------------------------
 cmake/modules/CaptureCommandLine.cmake | 48 ++++++++++++++++++++++++++
 cmake/modules/RootConfiguration.cmake  |  3 ++
 3 files changed, 53 insertions(+), 46 deletions(-)
 create mode 100644 cmake/modules/CaptureCommandLine.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fe4539b7703..7114a14344e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,52 +1,8 @@
-#
-# Try to capture the initial set of cmake command line args passed by
-# the user for configuration.
-# Original Recipe taken from http://stackoverflow.com/questions/10205986/how-to-capture-cmake-command-line-arguments
-#
-# Note: The entries will live on CMakeCache.txt, so re-configuring with
-# a command line that doesn't include an option won't remove it. You need
-# to remove the CMakeCache.txt file, or override the value via the command line.
-#
-#
-GET_CMAKE_PROPERTY(CACHE_VARS CACHE_VARIABLES)
-FOREACH(CACHE_VAR ${CACHE_VARS})
-    GET_PROPERTY(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
-    IF(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.")
-        GET_PROPERTY(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)
-        IF(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED")
-            SET(CACHE_VAR_TYPE)
-        ELSE(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED")
-            SET(CACHE_VAR_TYPE :${CACHE_VAR_TYPE})
-        ENDIF()
-        SET(CMAKE_INVOKE_ARGS "${CMAKE_INVOKE_ARGS} -D${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"")
-    ENDIF()
-ENDFOREACH(CACHE_VAR ${CACHE_VARS})
-# Record the full command line invocation.
-SET(CMAKE_INVOKE "${CMAKE_COMMAND} ${CMAKE_INVOKE_ARGS} ${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING "Command used to invoke cmake" FORCE)
-# Create a simple shell script that allows us to reinvoke cmake with the captured command line.
-IF (NOT WIN32)
-    if (NOT ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
-        set(RECMAKE_GENERATOR "-G ${CMAKE_GENERATOR}")
-    endif()
-    SET(RECMAKE_REPLAY_FILE ${CMAKE_BINARY_DIR}/recmake_replay.sh)
-    SET(RECMAKE_INITIAL_FILE ${CMAKE_BINARY_DIR}/recmake_initial.sh)
-    if (NOT EXISTS ${RECMAKE_INITIAL_FILE})
-        FILE(WRITE ${RECMAKE_INITIAL_FILE} "#!/bin/sh\n"
-                "rm -f CMakeCache.txt\n"
-                "${CMAKE_INVOKE} ${RECMAKE_GENERATOR}\n")
-    endif()
-    if (EXISTS ${RECMAKE_REPLAY_FILE})
-        FILE(APPEND ${RECMAKE_REPLAY_FILE} "${CMAKE_INVOKE}\n")
-    else()
-        FILE(WRITE ${RECMAKE_REPLAY_FILE} "#!/bin/sh\n"
-            "rm -f CMakeCache.txt\n"
-            "${CMAKE_INVOKE} ${RECMAKE_GENERATOR}\n")
-    endif()
-ENDIF (NOT WIN32)
-
 #---Check if cmake has the required version-----------------------------------------------------
 cmake_minimum_required(VERSION 3.4.3 FATAL_ERROR)
 cmake_policy(SET CMP0005 NEW)
+include(cmake/modules/CaptureCommandLine.cmake)
+
 #---Set name of the project to "ROOT". Has to be done after check of cmake version--------------
 project(ROOT)
 set(IntegratedBuild ON)
diff --git a/cmake/modules/CaptureCommandLine.cmake b/cmake/modules/CaptureCommandLine.cmake
new file mode 100644
index 00000000000..3ca9ae62fcc
--- /dev/null
+++ b/cmake/modules/CaptureCommandLine.cmake
@@ -0,0 +1,48 @@
+#
+# Try to capture the initial set of cmake command line args passed by
+# the user for configuration.
+# Original Recipe taken from http://stackoverflow.com/questions/10205986/how-to-capture-cmake-command-line-arguments
+#
+# Note: The entries will live on CMakeCache.txt, so re-configuring with
+# a command line that doesn't include an option won't remove it. You need
+# to remove the CMakeCache.txt file, or override the value via the command line.
+#
+
+get_cmake_property(CACHE_VARS CACHE_VARIABLES)
+foreach(CACHE_VAR ${CACHE_VARS})
+  get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
+  if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.")
+    get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)
+    if(CACHE_VAR_TYPE STREQUAL UNINITIALIZED)
+      set(CACHE_VAR_TYPE)
+    else()
+      set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE})
+    endif()
+    set(CMAKE_INVOKE_ARGS "${CMAKE_INVOKE_ARGS} -D${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"")
+    # Record the variable also in the cache    
+    set(${CACHE_VAR}-CACHED "${${CACHE_VAR}}" CACHE STRING "" FORCE)
+  endif()
+endforeach()
+
+# Record the full command line invocation.
+set(CMAKE_INVOKE "${CMAKE_COMMAND} ${CMAKE_INVOKE_ARGS} ${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING "Command used to invoke cmake" FORCE)
+# Create a simple shell script that allows us to reinvoke cmake with the captured command line.
+if(NOT WIN32)
+  if (NOT ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
+    set(RECMAKE_GENERATOR "-G ${CMAKE_GENERATOR}")
+  endif()
+  set(RECMAKE_REPLAY_FILE ${CMAKE_BINARY_DIR}/recmake_replay.sh)
+  set(RECMAKE_INITIAL_FILE ${CMAKE_BINARY_DIR}/recmake_initial.sh)
+  if (NOT EXISTS ${RECMAKE_INITIAL_FILE})
+      FILE(WRITE ${RECMAKE_INITIAL_FILE} "#!/bin/sh\n"
+              "rm -f CMakeCache.txt\n"
+              "${CMAKE_INVOKE} ${RECMAKE_GENERATOR}\n")
+  endif()
+  if (EXISTS ${RECMAKE_REPLAY_FILE})
+    FILE(APPEND ${RECMAKE_REPLAY_FILE} "${CMAKE_INVOKE}\n")
+  else()
+    FILE(WRITE ${RECMAKE_REPLAY_FILE} "#!/bin/sh\n"
+          "rm -f CMakeCache.txt\n"
+          "${CMAKE_INVOKE} ${RECMAKE_GENERATOR}\n")
+  endif()
+ endif()
diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake
index 224cd66f4a0..afada195be3 100644
--- a/cmake/modules/RootConfiguration.cmake
+++ b/cmake/modules/RootConfiguration.cmake
@@ -641,6 +641,9 @@ else()
         "${libdir}" "-lCore" "-lRint" "${incdir}" "" "" "${ROOT_ARCHITECTURE}" "" "${explicitlink}" )
 endif()
 
+#---Get the value of CMAKE_CXX_FLAGS provided by the user in the command line
+set(usercflags ${CMAKE_CXX_FLAGS-CACHED})
+
 configure_file(${CMAKE_SOURCE_DIR}/config/root-config.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/root-config @ONLY NEWLINE_STYLE UNIX)
 configure_file(${CMAKE_SOURCE_DIR}/config/memprobe.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/memprobe @ONLY NEWLINE_STYLE UNIX)
 configure_file(${CMAKE_SOURCE_DIR}/config/thisroot.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/thisroot.sh @ONLY NEWLINE_STYLE UNIX)
-- 
GitLab