From d4890e523ed0e766c36ff86f3de693de81a61b0f Mon Sep 17 00:00:00 2001
From: Matthias Maier <tamiko@43-1.org>
Date: Fri, 16 Sep 2016 20:06:00 -0500
Subject: [PATCH] CMake: Partially revert #1758

 - always set Debug, or Release build type (depending on availability
 - but allow for manually set DebugRelease
---
 ..._deal_ii_initialize_cached_variables.cmake | 35 ++++++++++++-------
 .../macro_deal_ii_invoke_autopilot.cmake      |  9 -----
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/cmake/macros/macro_deal_ii_initialize_cached_variables.cmake b/cmake/macros/macro_deal_ii_initialize_cached_variables.cmake
index 6f406c6356..fe22952598 100644
--- a/cmake/macros/macro_deal_ii_initialize_cached_variables.cmake
+++ b/cmake/macros/macro_deal_ii_initialize_cached_variables.cmake
@@ -37,19 +37,30 @@ MACRO(DEAL_II_INITIALIZE_CACHED_VARIABLES)
   ENDIF()
 
   #
-  # Set build type according to build type of deal.II
+  # Set build type according to available libraries
   #
-  SET(CMAKE_BUILD_TYPE ${DEAL_II_BUILD_TYPE} CACHE STRING
-    "Choose the type of build, options are: Debug, Release, DebugRelease")
+  IF(DEAL_II_BUILD_TYPE MATCHES "Debug")
+    SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING
+      "Choose the type of build, options are: Debug, Release"
+      )
+  ELSE()
+    SET(CMAKE_BUILD_TYPE "Release" CACHE STRING
+      "Choose the type of build, options are: Debug, Release"
+      )
+  ENDIF()
 
   #
-  # Reset build type if unsupported, i.e. if it is not (case insensitively
-  # equal to Debug or Release or unsupported by the current build type:
+  # Reset build type if unsupported, i.e. if it is not Debug, Release, or
+  # DebugRelease, or if the library doesn't support it
   #
-  STRING(TOLOWER "${CMAKE_BUILD_TYPE}" _cmake_build_type)
-
-  IF(NOT "${_cmake_build_type}" MATCHES "^(debug|release|debugrelease)$")
+  IF( NOT "${CMAKE_BUILD_TYPE}" MATCHES "^(Debug|Release|DebugRelease)$"
+      OR NOT "${DEAL_II_BUILD_TYPE}" MATCHES "${CMAKE_BUILD_TYPE}" )
 
+    IF("${DEAL_II_BUILD_TYPE}" STREQUAL "DebugRelease")
+      SET(_new_build_type "Debug")
+    ELSE()
+      SET(_new_build_type "${DEAL_II_BUILD_TYPE}")
+    ENDIF()
 
     MESSAGE(
 "###
@@ -57,14 +68,14 @@ MACRO(DEAL_II_INITIALIZE_CACHED_VARIABLES)
 #  WARNING:
 #
 #  CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\" unsupported by current installation!
-#  deal.II was built with CMAKE_BUILD_TYPE \"${DEAL_II_BUILD_TYPE}\".
+#  deal.II was configured with \"${DEAL_II_BUILD_TYPE}\".
 #
-#  CMAKE_BUILD_TYPE is forced to \"${DEAL_II_BUILD_TYPE}\".
+#  CMAKE_BUILD_TYPE was forced to \"${_new_build_type}\".
 #
 ###"
       )
-    SET(CMAKE_BUILD_TYPE ${DEAL_II_BUILD_TYPE} CACHE STRING
-      "Choose the type of build, options are: Debug, Release, DebugRelease"
+    SET(CMAKE_BUILD_TYPE "${_new_build_type}" CACHE STRING
+      "Choose the type of build, options are: Debug, Release"
       FORCE
       )
 
diff --git a/cmake/macros/macro_deal_ii_invoke_autopilot.cmake b/cmake/macros/macro_deal_ii_invoke_autopilot.cmake
index 4ff78eab1e..ac18d3f108 100644
--- a/cmake/macros/macro_deal_ii_invoke_autopilot.cmake
+++ b/cmake/macros/macro_deal_ii_invoke_autopilot.cmake
@@ -37,15 +37,6 @@
 
 MACRO(DEAL_II_INVOKE_AUTOPILOT)
 
-  # Set CMAKE_BUILD_TYPE=Debug if both 
-  # Debug and Release mode are given
-  IF("${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease")
-    SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING
-      "Choose the type of build, options are: Debug, Release"
-      FORCE)
-  ENDIF()
-
-
   # Generator specific values:
   IF(CMAKE_GENERATOR MATCHES "Ninja")
     SET(_make_command "$ ninja")
-- 
2.39.5