From f28f045a4dc1eb6dc77480cc97ceaf7324ef4fc8 Mon Sep 17 00:00:00 2001
From: Matthias Maier <tamiko@kyomu.43-1.org>
Date: Thu, 4 Oct 2012 20:11:37 +0000
Subject: [PATCH] Major overhaul of the auto configuration

git-svn-id: https://svn.dealii.org/branches/branch_cmake@26957 0785d39b-7218-0410-832d-ea1e28bc413d
---
 deal.II/README.CMAKE                          | 29 +++++---
 deal.II/cmake/configure/configure_1_mpi.cmake |  4 --
 deal.II/cmake/configure/configure_1_tbb.cmake |  4 --
 .../cmake/configure/configure_arpack.cmake    |  4 --
 .../cmake/configure/configure_doxygen.cmake   |  4 --
 .../cmake/configure/configure_lapack.cmake    |  5 --
 deal.II/cmake/configure/configure_metis.cmake |  4 --
 deal.II/cmake/configure/configure_mumps.cmake |  3 -
 .../cmake/configure/configure_netcdf.cmake    |  4 --
 deal.II/cmake/configure/configure_p4est.cmake |  4 --
 deal.II/cmake/configure/configure_petsc.cmake |  4 --
 .../cmake/configure/configure_trilinos.cmake  |  4 --
 .../cmake/configure/configure_umfpack.cmake   |  4 --
 deal.II/cmake/configure/configure_zlib.cmake  |  3 -
 .../macros/macro_configure_feature.cmake      | 66 +++++++++++--------
 deal.II/cmake/modules/FindMUMPS.cmake         |  2 +
 deal.II/cmake/setup_deal_ii.cmake             | 11 +---
 deal.II/cmake/setup_finalize.cmake            | 15 ++++-
 18 files changed, 75 insertions(+), 99 deletions(-)

diff --git a/deal.II/README.CMAKE b/deal.II/README.CMAKE
index a0614581cd..2753f246a3 100644
--- a/deal.II/README.CMAKE
+++ b/deal.II/README.CMAKE
@@ -222,16 +222,6 @@ CONFIGURATION
   forces the use of the bundled  library regardless whether
   DEAL_II_ALLOW_BUNDLED is set to OFF or an external library is found.
 
-
-  Autoconfiguration:
-
-  If the option DEAL_II_FEATURE_AUTODETECTION is enabled the
-  DEAL_II_WITH_<feature> toggles will be automatically set (overwriting any
-  previous configuration) depending on whether they can be supported or
-  not.
-  (Note: DEAL_II_FEATURE_AUTODETECTION will respect DEAL_II_ALLOW_BUNDLED
-  and DEAL_II_FORCE_BUNDLED_<feature>)
-
   REMARKS:
 
   - To ensure that no bundled library is used at all DEAL_II_ALLOW_BUNDLED,
@@ -242,6 +232,25 @@ CONFIGURATION
     separately.
 
 
+  Auto configuration:
+
+  As long as DEAL_II_WITH_<FEATURE> is not set to ON or OFF in the cache it
+  will be automatically configured. If a toggle DEAL_II_WITH_<FEATURE> is
+  defined it won't be altered.
+  This means that the very first configuration run will set all (at that
+  moment) available features to ON and the rest to OFF. In all subsequent
+  configuration steps DEAL_II_WITH_<FEATURE> have to be changed by hand.)
+
+  This behaviour can be controlled via the variables:
+
+    - DISABLE_AUTODETECTION=ON: This will disable any autoconfiguration by
+      setting undefined DEAL_II_WITH_<FEATURE> toggles to OFF:
+
+    - FORCE_AUTODETECTION=ON: This will force the reconfiguration of every
+      feature by undefining DEAL_II_WITH_<FEATURE> prior to configuration,
+      effectively overwriting _any_ supplied or cached value.
+
+
   External library locations
   ==========================
 
diff --git a/deal.II/cmake/configure/configure_1_mpi.cmake b/deal.II/cmake/configure/configure_1_mpi.cmake
index ff934f4a9c..adf42edd9e 100644
--- a/deal.II/cmake/configure/configure_1_mpi.cmake
+++ b/deal.II/cmake/configure/configure_1_mpi.cmake
@@ -16,10 +16,6 @@
 # Configuration for mpi support:
 #
 
-OPTION(DEAL_II_WITH_MPI
-  "Build deal.II with support for mpi."
-  OFF)
-
 
 MACRO(FEATURE_MPI_FIND_EXTERNAL var)
   FIND_PACKAGE(MPI)
diff --git a/deal.II/cmake/configure/configure_1_tbb.cmake b/deal.II/cmake/configure/configure_1_tbb.cmake
index 33eeb29c30..31b92f9c8c 100644
--- a/deal.II/cmake/configure/configure_1_tbb.cmake
+++ b/deal.II/cmake/configure/configure_1_tbb.cmake
@@ -16,10 +16,6 @@
 # Configuration for tbb support:
 #
 
-OPTION(DEAL_II_WITH_TBB
-  "Build deal.II with support for tbb. This will enable thread support in deal.II."
-  OFF)
-
 
 #
 # Set up genereal threading:
diff --git a/deal.II/cmake/configure/configure_arpack.cmake b/deal.II/cmake/configure/configure_arpack.cmake
index 8fb96d8a8d..9f67911072 100644
--- a/deal.II/cmake/configure/configure_arpack.cmake
+++ b/deal.II/cmake/configure/configure_arpack.cmake
@@ -16,10 +16,6 @@
 # Configuration for the ARPACK library:
 #
 
-OPTION(DEAL_II_WITH_ARPACK
-  "Build deal.II with support for arpack."
-  OFF)
-
 
 MACRO(FEATURE_ARPACK_FIND_EXTERNAL var)
   FIND_PACKAGE(ARPACK)
diff --git a/deal.II/cmake/configure/configure_doxygen.cmake b/deal.II/cmake/configure/configure_doxygen.cmake
index f982708c2c..b8e58e2d4d 100644
--- a/deal.II/cmake/configure/configure_doxygen.cmake
+++ b/deal.II/cmake/configure/configure_doxygen.cmake
@@ -16,10 +16,6 @@
 # Configuration for doxygen
 #
 
-OPTION(DEAL_II_WITH_DOXYGEN
-  "Build deal.II with support for doxygen and dot."
-  OFF)
-
 
 MACRO(FEATURE_DOXYGEN_FIND_EXTERNAL var)
   FIND_PACKAGE(Doxygen)
diff --git a/deal.II/cmake/configure/configure_lapack.cmake b/deal.II/cmake/configure/configure_lapack.cmake
index 0c3e6edd8c..2e7d48a32f 100644
--- a/deal.II/cmake/configure/configure_lapack.cmake
+++ b/deal.II/cmake/configure/configure_lapack.cmake
@@ -17,11 +17,6 @@
 #
 
 
-OPTION(DEAL_II_WITH_LAPACK
-  "Build deal.II with support for LAPACK."
-  OFF)
-
-
 MACRO(FEATURE_LAPACK_FIND_EXTERNAL var)
   FIND_PACKAGE(LAPACK)
 
diff --git a/deal.II/cmake/configure/configure_metis.cmake b/deal.II/cmake/configure/configure_metis.cmake
index 2a869da9ef..ddf4b8e34b 100644
--- a/deal.II/cmake/configure/configure_metis.cmake
+++ b/deal.II/cmake/configure/configure_metis.cmake
@@ -16,10 +16,6 @@
 # Configuration for the netcdf library:
 #
 
-OPTION(DEAL_II_WITH_METIS
-  "Build deal.II with support for Metis."
-  OFF)
-
 
 MACRO(FEATURE_METIS_FIND_EXTERNAL var)
   FIND_PACKAGE(METIS)
diff --git a/deal.II/cmake/configure/configure_mumps.cmake b/deal.II/cmake/configure/configure_mumps.cmake
index e0d95b65d8..2942b9a840 100644
--- a/deal.II/cmake/configure/configure_mumps.cmake
+++ b/deal.II/cmake/configure/configure_mumps.cmake
@@ -16,9 +16,6 @@
 # Configuration for the MUMPS library:
 #
 
-OPTION(DEAL_II_WITH_MUMPS
-  "Build deal.II with support for MUMPS."
-  OFF)
 
 SET(FEATURE_MUMPS_DEPENDS DEAL_II_WITH_MPI)
 
diff --git a/deal.II/cmake/configure/configure_netcdf.cmake b/deal.II/cmake/configure/configure_netcdf.cmake
index 0f55788cfe..cc5e4546ce 100644
--- a/deal.II/cmake/configure/configure_netcdf.cmake
+++ b/deal.II/cmake/configure/configure_netcdf.cmake
@@ -16,10 +16,6 @@
 # Configuration for the netcdf library:
 #
 
-OPTION(DEAL_II_WITH_NETCDF
-  "Build deal.II with support for netcdf."
-  OFF)
-
 
 MACRO(FEATURE_NETCDF_FIND_EXTERNAL var)
   FIND_PACKAGE(NETCDF)
diff --git a/deal.II/cmake/configure/configure_p4est.cmake b/deal.II/cmake/configure/configure_p4est.cmake
index 41c088c0c9..0c8c03fedc 100644
--- a/deal.II/cmake/configure/configure_p4est.cmake
+++ b/deal.II/cmake/configure/configure_p4est.cmake
@@ -16,10 +16,6 @@
 # Configuration for the p4est and sc libraries:
 #
 
-OPTION(DEAL_II_WITH_P4EST
-  "Build deal.II with support for p4est."
-  OFF)
-
 
 SET(FEATURE_P4EST_DEPENDS DEAL_II_WITH_MPI)
 
diff --git a/deal.II/cmake/configure/configure_petsc.cmake b/deal.II/cmake/configure/configure_petsc.cmake
index 43366cb15e..6247da4c62 100644
--- a/deal.II/cmake/configure/configure_petsc.cmake
+++ b/deal.II/cmake/configure/configure_petsc.cmake
@@ -16,10 +16,6 @@
 # Configuration for the petsc library:
 #
 
-OPTION(DEAL_II_WITH_PETSC
-  "Build deal.II with support for petsc."
-  OFF)
-
 
 MACRO(FEATURE_PETSC_FIND_EXTERNAL var)
 
diff --git a/deal.II/cmake/configure/configure_trilinos.cmake b/deal.II/cmake/configure/configure_trilinos.cmake
index ac3b560f38..f1eb7ad95f 100644
--- a/deal.II/cmake/configure/configure_trilinos.cmake
+++ b/deal.II/cmake/configure/configure_trilinos.cmake
@@ -16,10 +16,6 @@
 # Configuration for the trilinos library:
 #
 
-OPTION(DEAL_II_WITH_TRILINOS
-  "Build deal.II with support for trilinos."
-  OFF)
-
 
 MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var)
   FIND_PACKAGE(TRILINOS)
diff --git a/deal.II/cmake/configure/configure_umfpack.cmake b/deal.II/cmake/configure/configure_umfpack.cmake
index fcf594b8b9..9c926a48c9 100644
--- a/deal.II/cmake/configure/configure_umfpack.cmake
+++ b/deal.II/cmake/configure/configure_umfpack.cmake
@@ -16,10 +16,6 @@
 # Configuration for the umfpack and amd libraries:
 #
 
-OPTION(DEAL_II_WITH_UMFPACK
-  "Build deal.II with support for UMFPACK."
-  OFF)
-
 
 MACRO(FEATURE_UMFPACK_FIND_EXTERNAL var)
   FIND_PACKAGE(UMFPACK)
diff --git a/deal.II/cmake/configure/configure_zlib.cmake b/deal.II/cmake/configure/configure_zlib.cmake
index 069e9b9616..858d81f9ca 100644
--- a/deal.II/cmake/configure/configure_zlib.cmake
+++ b/deal.II/cmake/configure/configure_zlib.cmake
@@ -16,9 +16,6 @@
 # Configuration for the zlib library:
 #
 
-OPTION(DEAL_II_WITH_ZLIB
-  "Build deal.II with support for zlib."
-  OFF)
 
 MACRO(FEATURE_ZLIB_FIND_EXTERNAL var)
   FIND_PACKAGE(ZLIB)
diff --git a/deal.II/cmake/macros/macro_configure_feature.cmake b/deal.II/cmake/macros/macro_configure_feature.cmake
index ad37ccb3cf..a497af88a3 100644
--- a/deal.II/cmake/macros/macro_configure_feature.cmake
+++ b/deal.II/cmake/macros/macro_configure_feature.cmake
@@ -87,10 +87,11 @@ ENDMACRO()
 # A small macro to set the DEAL_II_WITH_${feature} variables:
 #
 MACRO(SET_CACHED_OPTION str value)
-  SET(${str}
+  STRING(TOLOWER "${str}" str_lower)
+  SET(DEAL_II_WITH_${str}
     ${value}
     CACHE BOOL
-    "Automatically set due to DEAL_II_FEATURE_AUTODETECTION"
+    "Build deal.II with support for ${str_lower}."
     FORCE)
 ENDMACRO()
 
@@ -145,10 +146,25 @@ MACRO(CONFIGURE_FEATURE feature)
     ENDIF()
   ENDFOREACH()
 
+
+  #
+  # Obey the user overrides:
+  #
+  IF(FORCE_AUTODETECTION)
+    UNSET(DEAL_II_WITH_${feature})
+  ENDIF()
+  IF(DISABLE_AUTODETECTION AND
+    (NOT DEFINED DEAL_II_WITH_${feature}) )
+    SET_CACHED_OPTION(${feature} OFF)
+  ENDIF()
+
+
   #
-  # Only try to configure ${feature} if we have to:
+  # Only try to configure ${feature} if we have to, i.e.
+  # DEAL_II_WITH_${feature} is set to true or not set at all.
   #
-  IF(DEAL_II_FEATURE_AUTODETECTION OR DEAL_II_WITH_${feature})
+  IF((NOT DEFINED DEAL_II_WITH_${feature}) OR
+     DEAL_II_WITH_${feature})
 
     #
     # Are all dependencies fullfilled?
@@ -156,17 +172,17 @@ MACRO(CONFIGURE_FEATURE feature)
     SET(macro_dependencies_ok TRUE)
     FOREACH(macro_dependency ${FEATURE_${feature}_DEPENDS})
       IF(NOT ${macro_dependency})
-        IF(DEAL_II_FEATURE_AUTODETECTION)
-          MESSAGE(STATUS
+        IF(DEAL_II_WITH_${feature})
+          MESSAGE(SEND_ERROR "\n"
             "DEAL_II_WITH_${feature} has unmet configuration requirements: "
-            "${macro_dependency} has to be set to \"ON\"."
+            "${macro_dependency} has to be set to \"ON\".\n\n"
             )
-          SET_CACHED_OPTION(DEAL_II_WITH_${feature} OFF)
         ELSE()
-          MESSAGE(SEND_ERROR "\n"
+          MESSAGE(STATUS
             "DEAL_II_WITH_${feature} has unmet configuration requirements: "
-            "${macro_dependency} has to be set to \"ON\".\n\n"
+            "${macro_dependency} has to be set to \"ON\"."
             )
+          SET_CACHED_OPTION(${feature} OFF)
         ENDIF()
         SET(macro_dependencies_ok FALSE)
       ENDIF()
@@ -186,9 +202,7 @@ MACRO(CONFIGURE_FEATURE feature)
             MESSAGE(STATUS
               "DEAL_II_WITH_${feature} successfully set up with bundled packages."
               )
-            IF(DEAL_II_FEATURE_AUTODETECTION)
-              SET_CACHED_OPTION(DEAL_II_WITH_${feature} ON)
-            ENDIF()
+            SET_CACHED_OPTION(${feature} ON)
           ELSE()
             # This should not happen. So give an error
             MESSAGE(SEND_ERROR
@@ -223,9 +237,7 @@ MACRO(CONFIGURE_FEATURE feature)
             MESSAGE(STATUS
               "DEAL_II_WITH_${feature} successfully set up with external dependencies."
               )
-            IF(DEAL_II_FEATURE_AUTODETECTION)
-              SET_CACHED_OPTION(DEAL_II_WITH_${feature} ON)
-            ENDIF()
+            SET_CACHED_OPTION(${feature} ON)
           ELSE()
             # This should not happen. So give an error
             MESSAGE(SEND_ERROR
@@ -248,7 +260,7 @@ MACRO(CONFIGURE_FEATURE feature)
                 "DEAL_II_WITH_${feature} successfully set up with bundled packages."
                 )
               IF(DEAL_II_FEATURE_AUTODETECTION)
-                SET_CACHED_OPTION(DEAL_II_WITH_${feature} ON)
+                SET_CACHED_OPTION(${feature} ON)
               ENDIF()
             ELSE()
               # This should not happen. So give an error
@@ -257,21 +269,21 @@ MACRO(CONFIGURE_FEATURE feature)
                 )
             ENDIF()
           ELSE()
-              IF(DEAL_II_FEATURE_AUTODETECTION)
-                SET_CACHED_OPTION(DEAL_II_WITH_${feature} OFF)
+            IF(DEAL_II_WITH_${feature})
+              IF(FEATURE_${feature}_CUSTOM_ERROR_MESSAGE)
+                RUN_COMMAND("FEATURE_${feature}_ERROR_MESSAGE()")
               ELSE()
-                IF(FEATURE_${feature}_CUSTOM_ERROR_MESSAGE)
-                  RUN_COMMAND("FEATURE_${feature}_ERROR_MESSAGE()")
-                ELSE()
-                  FEATURE_ERROR_MESSAGE(${feature})
-                ENDIF()
+                FEATURE_ERROR_MESSAGE(${feature})
               ENDIF()
+            ELSE()
+              SET_CACHED_OPTION(${feature} OFF)
+            ENDIF()
           ENDIF()
 
         ENDIF(FEATURE_${feature}_EXTERNAL_FOUND)
-      ENDIF(DEAL_II_FORCE_BUNDLED_${feature})
-    ENDIF(macro_dependencies_ok)
-  ENDIF(DEAL_II_FEATURE_AUTODETECTION OR DEAL_II_WITH_${feature})
+      ENDIF()
+    ENDIF()
+  ENDIF()
 
   SET(FEATURE_${feature}_PROCESSED TRUE)
 
diff --git a/deal.II/cmake/modules/FindMUMPS.cmake b/deal.II/cmake/modules/FindMUMPS.cmake
index 07280d1da9..15f3ecfa61 100644
--- a/deal.II/cmake/modules/FindMUMPS.cmake
+++ b/deal.II/cmake/modules/FindMUMPS.cmake
@@ -73,6 +73,8 @@ FIND_LIBRARY(PORD_LIBRARY
     ${MUMPS_DIR}
   PATH_SUFFIXES lib${LIB_SUFFIX} lib64 lib
   )
+MARK_AS_ADVANCED(PORD_LIBRARY)
+
 IF(NOT PORD_LIBRARY MATCHES "-NOTFOUND")
   LIST(APPEND MUMPS_LIBRARIES
     ${PORD_LIBRARY}
diff --git a/deal.II/cmake/setup_deal_ii.cmake b/deal.II/cmake/setup_deal_ii.cmake
index 8c6dc04c86..dc59a60116 100644
--- a/deal.II/cmake/setup_deal_ii.cmake
+++ b/deal.II/cmake/setup_deal_ii.cmake
@@ -20,7 +20,6 @@
 #
 # General configuration options:
 #
-#     DEAL_II_FEATURE_AUTODETECTION   **)
 #     DEAL_II_ALLOW_BUNDLED           **)
 #     DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS **)
 #     DEAL_II_COMPONENT_COMPAT_FILES  **)
@@ -65,10 +64,9 @@
 #     DEAL_II_WITH_BUNDLED_DIRECTORY
 #     DEAL_II_WITH_DOC_DIRECTORY
 #
-# *)  Values marked with *) can be overwritten by the command line via
-#     -D<...>
-# **) Cached Option. Can be set via ccmake or on the command line via
+# *)  Uncached variables. Can be overwritten by the command line via
 #     -D<...>
+# **) Cached Options. Can be set via ccmake or on the command line via -D<...>
 #
 
 
@@ -90,11 +88,6 @@ ENDIF()
 #                                                                         #
 ###########################################################################
 
-OPTION(DEAL_II_FEATURE_AUTODETECTION
-  "Enables feature autodetection. This will automatically set DEAL_II_WITH_<...> options."
-  ON
-  )
-
 OPTION(DEAL_II_ALLOW_BUNDLED
   "Allow the use of libraries bundled with the source tarball. (DEAL_II_FORCE_BUNDLED* will overwrite this option.)"
   ON
diff --git a/deal.II/cmake/setup_finalize.cmake b/deal.II/cmake/setup_finalize.cmake
index ee25e388af..2c0b2eaf0e 100644
--- a/deal.II/cmake/setup_finalize.cmake
+++ b/deal.II/cmake/setup_finalize.cmake
@@ -109,12 +109,23 @@ ELSEIF(NOT DEAL_II_KNOWN_COMPILER)
   FILE(APPEND ${log} "\nWARNING: Unknown compiler! Please set compiler flags by hand.\n")
 ENDIF()
 
-
 FILE(APPEND ${log}
   "\nConfigured Features ("
-  "DEAL_II_FEATURE_AUTODETECTION = ${DEAL_II_FEATURE_AUTODETECTION}, "
+  )
+IF(FORCE_AUTODETECTION)
+  FILE(APPEND ${log}
+    "!!! FORCE_AUTODETECTION !!!, "
+    )
+ENDIF()
+IF(DISABLE_AUTODETECTION)
+  FILE(APPEND ${log}
+    "!!! DISABLE_AUTODETECTION !!!, "
+    )
+ENDIF()
+FILE(APPEND ${log}
   "DEAL_II_ALLOW_BUNDLED = ${DEAL_II_ALLOW_BUNDLED}):\n"
   )
+
 GET_CMAKE_PROPERTY(res VARIABLES)
 FOREACH(var ${res})
   IF(var MATCHES "DEAL_II_WITH")
-- 
2.39.5