]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
CMake: Organize C++11 support as a toggable feature
authormaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 22 Dec 2013 18:36:41 +0000 (18:36 +0000)
committermaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 22 Dec 2013 18:36:41 +0000 (18:36 +0000)
git-svn-id: https://svn.dealii.org/trunk@32097 0785d39b-7218-0410-832d-ea1e28bc413d

13 files changed:
deal.II/cmake/checks/check_01_cxx_features.cmake
deal.II/cmake/setup_cached_variables.cmake
deal.II/doc/users/config.sample
deal.II/include/deal.II/base/config.h.in
deal.II/include/deal.II/base/std_cxx1x/array.h
deal.II/include/deal.II/base/std_cxx1x/bind.h
deal.II/include/deal.II/base/std_cxx1x/condition_variable.h
deal.II/include/deal.II/base/std_cxx1x/function.h
deal.II/include/deal.II/base/std_cxx1x/mutex.h
deal.II/include/deal.II/base/std_cxx1x/shared_ptr.h
deal.II/include/deal.II/base/std_cxx1x/thread.h
deal.II/include/deal.II/base/std_cxx1x/tuple.h
deal.II/include/deal.II/base/std_cxx1x/type_traits.h

index 0f5b0865f29886a0df0eca68ce416e50bb6cda84..c5024e098a568dae4339fe73eab502a901fc4396 100644 (file)
@@ -19,9 +19,8 @@
 #
 # This file sets up
 #
-#   DEAL_II_HAVE_CXX11_FLAG
-#   DEAL_II_CXX11_FLAG
-#   DEAL_II_USE_CXX11
+#   DEAL_II_WITH_CXX11
+#
 #   HAVE_ISNAN
 #   HAVE_UNDERSCORE_ISNAN
 #   DEAL_II_HAVE_ISFINITE
 #                                                                      #
 ########################################################################
 
+
 #
-# See if there is a compiler flag to enable C++11 features
+# Only run these tests if C++11 support should actually be set up:
 #
-IF(NOT DEFINED DEAL_II_HAVE_CXX11_FLAG)
-  FOREACH(_test_flag
-      "-std=c++11"
-      "-std=c++0x"
-      )
-    CHECK_CXX_COMPILER_FLAG("${_test_flag}" DEAL_II_HAVE_CXX11_FLAG)
-
-    IF(DEAL_II_HAVE_CXX11_FLAG)
-      # We have found a CXX11_FLAG that the compiler understands
-      SET(DEAL_II_CXX11_FLAG "${_test_flag}" CACHE INTERNAL "")
-      BREAK()
-    ELSE()
-      # Remove test result from cache and try the next flag in the list
-      UNSET(DEAL_II_HAVE_CXX11_FLAG CACHE)
+IF(NOT DEFINED DEAL_II_WITH_CXX11 OR DEAL_II_WITH_CXX11)
+
+  IF("${DEAL_II_CXX11_FLAG}" STREQUAL "")
+    CHECK_CXX_COMPILER_FLAG("-std=c++11" DEAL_II_HAVE_FLAG_stdcxx11)
+    IF(DEAL_II_HAVE_FLAG_stdcxx11)
+      SET(DEAL_II_CXX11_FLAG "-std=c++11")
+    ELSEIF(DEAL_II_HAVE_FLAG_stdcxx11)
+      CHECK_CXX_COMPILER_FLAG("-std=c++0x" DEAL_II_HAVE_FLAG_stdcxx0x)
+      SET(DEAL_II_CXX11_FLAG "-std=x++0x")
     ENDIF()
-  ENDFOREACH()
-ENDIF()
-
-
-IF(DEAL_II_HAVE_CXX11_FLAG)
+  ENDIF()
 
   # Set CMAKE_REQUIRED_FLAGS for the unit tests
+  MESSAGE(STATUS "Using C++11 flag \"${DEAL_II_CXX11_FLAG}\"")
   PUSH_TEST_FLAG("${DEAL_II_CXX11_FLAG}")
 
   CHECK_CXX_SOURCE_COMPILES(
@@ -110,12 +102,7 @@ IF(DEAL_II_HAVE_CXX11_FLAG)
   # below but it will throw an exception when run. So test
   # that as well.
   #
-  # TODO: This test will only succeed on platforms where "-pthread" is
-  #       recognized. But this isn't easily fixable:
-  #       configure_threads.cmake which will determine and setup threads
-  #       has to be called later...
-  #
-  IF(NOT CMAKE_CROSSCOMPILING) # Todo: Is it better to use DEAL_II_ALLOW_PLATFORM_INTROSPECTION here?
+  IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
     PUSH_TEST_FLAG("-pthread")
     CHECK_CXX_SOURCE_RUNS(
       "
@@ -127,7 +114,7 @@ IF(DEAL_II_HAVE_CXX11_FLAG)
     POP_TEST_FLAG()
   ELSE()
     # Just export it ;-)
-    SET_IF_EMPTY(DEAL_II_HAVE_CXX11_THREAD TRUE)
+    SET(DEAL_II_HAVE_CXX11_THREAD TRUE CACHE BOOL "")
   ENDIF()
 
   CHECK_CXX_SOURCE_COMPILES(
@@ -165,57 +152,56 @@ IF(DEAL_II_HAVE_CXX11_FLAG)
       DEAL_II_HAVE_CXX11_MUTEX AND
       DEAL_II_HAVE_CXX11_TUPLE AND
       DEAL_II_HAVE_CXX11_TYPE_TRAITS )
-
-    MESSAGE(STATUS "Sufficient C++11 support. Enabling ${DEAL_II_CXX11_FLAG}.")
-
-    SET(DEAL_II_USE_CXX11 TRUE)
-
-    ADD_FLAGS(DEAL_II_CXX_FLAGS "${DEAL_II_CXX11_FLAG}")
-
-  ELSE()
-    MESSAGE(STATUS "Insufficient C++11 support. Disabling ${DEAL_II_CXX11_FLAG}.")
+    SET(DEAL_II_HAVE_CXX11 TRUE)
   ENDIF()
 
- IF(DEAL_II_USE_CXX11)
-   CHECK_CXX_SOURCE_COMPILES(
-     "
-     #include <type_traits>
-     int main(){ std::is_trivially_copyable<int> bob; }
-     "
-     DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE)
+  RESET_CMAKE_REQUIRED()
+ENDIF()
 
-# Currently unused:
 #
-#    CHECK_CXX_SOURCE_COMPILES(
-#      "
-#      #include <vector>
-#      std::vector<int> v;
-#      int main(){ auto i = v.begin(); *i; return 0;}
-#      "
-#      DEAL_II_HAVE_CXX11_AUTO_TYPE)
+# Set up a configuration option for C++11 support:
 #
-#    CHECK_CXX_SOURCE_COMPILES(
-#      "
-#      #include <vector>],
-#      std::vector<int> v;
-#      int main(){ for (std::vector<int>::iterator i : v) *i; return 0;}
-#      "
-#      DEAL_II_HAVE_CXX11_RANGE_BASED_FOR)
+
+OPTION(DEAL_II_WITH_CXX11
+  "Compile deal.II using C++11 language standard."
+  ${DEAL_II_HAVE_CXX11}
+  )
+
 #
-#    IF( DEAL_II_HAVE_CXX11_AUTO_TYPE AND
-#        DEAL_II_HAVE_CXX11_RANGE_BASED_FOR )
+# Bail out if user requested C++11 support (DEAL_II_WITH_CXX11) but support
+# is not available due to above tests (DEAL_II_HAVE_CXX11):
 #
-#      MESSAGE(STATUS "Additional C++11 support available.")
+
+IF(DEAL_II_WITH_CXX11 AND NOT DEAL_II_HAVE_CXX11)
+  MESSAGE(FATAL_ERROR "\n"
+    "C++11 support was requested (DEAL_II_WITH_CXX11=TRUE) but is not
+    supported by the current compiler.\n"
+    "Please disable C++11 support, i.e. configure with\n"
+    "    -DDEAL_II_WITH_CXX11=FALSE,\n"
+    "or use a different compiler, instead. (If the compiler flag for C++11 "
+    "support differs from \"-std=c++0x\" or \"-std=c++11\", a suitable "
+    "compiler flag has to be specified manually.\n\n"
+    )
+ENDIF()
+
 #
-#      SET(DEAL_II_CAN_USE_ADDITIONAL_CXX1X_FEATURES)
-#    ENDIF()
+# Set up C++11 support:
 #
-  ENDIF()
 
-  POP_TEST_FLAG()
+IF(DEAL_II_WITH_CXX11)
+  ADD_FLAGS(DEAL_II_CXX_FLAGS "${DEAL_II_CXX11_FLAG}")
+  MESSAGE(STATUS "DEAL_II_WITH_CXX11 successfully set up")
 
+  PUSH_TEST_FLAG("${DEAL_II_CXX11_FLAG}")
+  CHECK_CXX_SOURCE_COMPILES(
+    "
+    #include <type_traits>
+    int main(){ std::is_trivially_copyable<int> bob; }
+    "
+    DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE)
+  POP_TEST_FLAG()
 ELSE()
-    MESSAGE(STATUS "Insufficient C++11 support. Disabling ${DEAL_II_CXX11_FLAG}.")
+  MESSAGE(STATUS "DEAL_II_WITH_CXX11 disabled")
 ENDIF()
 
 
index 055fe5c59f40c669b84498a4c6f195140f23db7b..f6e074057c9a957511d4e51108ea52c6495a0c3a 100644 (file)
@@ -348,6 +348,14 @@ if this is what you tried to do.)
     )
 ENDIF()
 
+#
+# Compatibility renaming:
+#
+
+IF(DEFINED DEAL_II_HAVE_CXX11_FLAG AND NOT DEAL_II_HAVE_CXX11_FLAG)
+  SET(DEAL_II_WITH_CXX11 FALSE CACHE BOOL "" FORCE)
+ENDIF()
+
 #
 # Miscellaneous renaming:
 #
index c81f471a80bdfbed6d06c0cb9f7b15d5a023baed..a64c3dcbb49ea72a6f7b5d9575e5ab1a9228a094 100644 (file)
 # C++11 support is autodetected. You can explicitly disable C+11 support by
 # specifying
 #
-#   SET(DEAL_II_HAVE_CXX11_FLAG FALSE CACHE BOOL "")
+#   SET(DEAL_II_WITH_CXX11 FALSE CACHE BOOL "")
 #
 # A custom C++11 flag can be set by setting
 #
-#   SET(DEAL_II_HAVE_CXX11_FLAG TRUE CACHE BOOL "")
-#   SET(DEAL_II_CXX11_FLAG "-std=c++0x" CACHE STRING "")
+#   SET(DEAL_II_CXX11_FLAG "-std=c++11" CACHE STRING "")
 #
 
 
index 34c4b9baf9d433688e736c0c9378840f98599dd8..7317d4fa6895d2447b09d78d0c996366e5b3f7eb 100644 (file)
  * to allow using the standard library classes instead of the corresponding
  * BOOST classes.
  */
-#cmakedefine DEAL_II_USE_CXX11
-#ifdef DEAL_II_USE_CXX11
+#cmakedefine DEAL_II_WITH_CXX11
+#ifdef DEAL_II_WITH_CXX11
+/* Compatibility definition (with naming from deal.II 8.0): */
+# define DEAL_II_USE_CXX11
 /* Compatibility definition (with naming from deal.II < 8.0): */
 # define DEAL_II_CAN_USE_CXX11
 # define DEAL_II_CAN_USE_CXX1X
index 68b8060321e6810aedef0282adaf0584542450d2..22635ef08619865ab96ded4c75af0db7bccd5c4c 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <array>
 DEAL_II_NAMESPACE_OPEN
index 9cb2192988e3bb76f447b3079d98ac4444dc66ff..5868fda7d0c3f9a93a5b1f5bd833a33f4087138f 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <functional>
 
index 4fd712c36cf850654ac0322c1d02c2e863006e66..1927778f1f86a285156d044865d8b191112729a2 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <condition_variable>
 DEAL_II_NAMESPACE_OPEN
index 86aea59ed13d2d49a397a9d591ab70ed28c2956f..08172582793b363e56745cd3d250b82e8db41ada 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <functional>
 DEAL_II_NAMESPACE_OPEN
index 7c195fffc90fd613c1d0f08dcdb39ae5d5938374..e8b40a54e242abe2e77f582e225ca494bfb71798 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <mutex>
 DEAL_II_NAMESPACE_OPEN
index 172218dedad4ba748e428581079b6ae0cc88c718..78f6701caba48c95c7e0d91a3818bfe7cbbec5df 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <memory>
 DEAL_II_NAMESPACE_OPEN
index ac3ed95d4dcf6bb1919fbc4c51055ebdb3f37ff7..2dccd96d78753ac3b7bc5550a0ffe3de9e8c937c 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <thread>
 DEAL_II_NAMESPACE_OPEN
index b3d846da6ed3f90f28c7a4efcbca25736dfbd51e..4a23a3d4412f143450df823d845ce95991b0933a 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <tuple>
 DEAL_II_NAMESPACE_OPEN
index d0e34b3280000c1184e912d509edc6d2d4926166..d2084bb48b46e449a6da33b4dbb14eb88d327edf 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_USE_CXX11
+#ifdef DEAL_II_WITH_CXX11
 
 #  include <type_traits>
 DEAL_II_NAMESPACE_OPEN

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.