]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add support for C++14.
authorDavid Wells <drwells@vt.edu>
Mon, 22 Jun 2015 01:43:42 +0000 (21:43 -0400)
committerDavid Wells <drwells@vt.edu>
Mon, 22 Jun 2015 02:13:32 +0000 (22:13 -0400)
Rather than support "C++11 or not C++11", the CMake files now support
either C++14 or C++11 based on the flags DEAL_II_WITH_CXX14 and
DEAL_II_WITH_CXX11. As C++14 is (very nearly) a superset of C++11
functionality, DEAL_II_HAVE_CXX14 may only be true when
DEAL_II_HAVE_CXX11 is true.

cmake/checks/check_01_cxx_features.cmake
cmake/checks/check_03_compiler_bugs.cmake
cmake/modules/FindTRILINOS.cmake
include/deal.II/base/config.h.in

index 9241110bc22901548ffca63a461e2b5488c197c1..8b098b5709a7e24a168da4e7ba1dc0e873d660ec 100644 (file)
@@ -19,6 +19,7 @@
 # This file sets up
 #
 #   DEAL_II_WITH_CXX11
+#   DEAL_II_WITH_CXX14
 #
 #   DEAL_II_HAVE_ISNAN
 #   DEAL_II_HAVE_UNDERSCORE_ISNAN
 
 ########################################################################
 #                                                                      #
-#                             C++11 Support:                           #
+#                         C++ Version Support:                         #
 #                                                                      #
 ########################################################################
 
+#
+# backwards compatability with the old DEAL_II_CXX11_FLAG option
+#
+
+IF(DEFINED DEAL_II_CXX11_FLAG AND NOT DEFINED DEAL_II_CXX_VERSION_FLAG)
+  SET(DEAL_II_CXX_VERSION_FLAG ${DEAL_II_CXX11_FLAG})
+ENDIF()
+
+IF(DEAL_II_WITH_CXX11 AND DEAL_II_WITH_CXX14)
+  MESSAGE(STATUS
+          "Since DEAL_II_WITH_CXX11 and DEAL_II_WITH_CXX14 were both specified,\n"
+          "DEAL_II_WITH_CXX14 is chosen as the standard.")
+ENDIF()
+
+IF(DEAL_II_WITH_CXX14 AND DEFINED DEAL_II_WITH_CXX11 AND NOT DEAL_II_WITH_CXX11)
+  MESSAGE(FATAL_ERROR
+    "Compiling deal.II with C++14 support (i.e., DEAL_II_WITH_CXX14=ON) requires"
+    " that C++11 support not be explicitly disabled (i.e., DEAL_II_WITH_CXX11 may"
+    " not be set to a logically false value).")
+ENDIF()
 
 #
-# Only run these tests if C++11 support should actually be set up:
+# Only run these tests if C++11 support (or newer) should actually be set up:
 #
-IF(NOT DEFINED DEAL_II_WITH_CXX11 OR DEAL_II_WITH_CXX11)
-
-  IF("${DEAL_II_CXX11_FLAG}" STREQUAL "")
-    CHECK_CXX_COMPILER_FLAG("-std=c++0x" DEAL_II_HAVE_FLAG_stdcxx0x)
-    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_stdcxx0x)
-      SET(DEAL_II_CXX11_FLAG "-std=c++0x")
+
+IF(DEAL_II_WITH_CXX11 OR DEAL_II_WITH_CXX14)
+  IF(NOT DEAL_II_CXX_VERSION_FLAG)
+    IF(DEAL_II_WITH_CXX14)
+      CHECK_CXX_COMPILER_FLAG("-std=c++14" DEAL_II_HAVE_FLAG_stdcxx14)
+      IF(DEAL_II_HAVE_FLAG_stdcxx14)
+        SET(DEAL_II_CXX_VERSION_FLAG "-std=c++14")
+      ELSE()
+        MESSAGE(FATAL_ERROR
+          "CMake was not able to find a valid C++14 flag. Try manually"
+          " specifying\nDEAL_II_CXX_VERSION_FLAG\nand reruning CMake.")
+      ENDIF()
+    ELSEIF(DEAL_II_WITH_CXX11)
+      CHECK_CXX_COMPILER_FLAG("-std=c++0x" DEAL_II_HAVE_FLAG_stdcxx0x)
+      CHECK_CXX_COMPILER_FLAG("-std=c++11" DEAL_II_HAVE_FLAG_stdcxx11)
+      IF(DEAL_II_HAVE_FLAG_stdcxx11)
+        SET(DEAL_II_CXX_VERSION_FLAG "-std=c++11")
+      ELSEIF(DEAL_II_HAVE_FLAG_stdcxx0x)
+        SET(DEAL_II_CXX_VERSION_FLAG "-std=c++0x")
+      ELSE()
+        MESSAGE(FATAL_ERROR
+          "CMake was not able to find a valid C++11 flag. Try manually"
+          " specifying\nDEAL_II_CXX_VERSION_FLAG and reruning CMake.")
+      ENDIF()
+    ENDIF()
+  ELSE()
+    CHECK_CXX_COMPILER_FLAG(${DEAL_II_CXX_VERSION_FLAG} DEAL_II_CXX_VERSION_FLAG_VALID)
+    IF(NOT DEAL_II_CXX_VERSION_FLAG_VALID)
+      MESSAGE(FATAL_ERROR
+        "The supplied flag \"${DEAL_II_CXX_VERSION_FLAG}\" was not recognized "
+        "by the detected compiler.")
     ENDIF()
   ENDIF()
 
   # Set CMAKE_REQUIRED_FLAGS for the unit tests
-  MESSAGE(STATUS "Using C++11 flag \"${DEAL_II_CXX11_FLAG}\"")
-  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX11_FLAG}")
+  MESSAGE(STATUS "Using C++ version flag \"${DEAL_II_CXX_VERSION_FLAG}\"")
+  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}")
 
   CHECK_CXX_SOURCE_COMPILES(
     "
@@ -111,7 +154,7 @@ IF(NOT DEFINED DEAL_II_WITH_CXX11 OR DEAL_II_WITH_CXX11)
       "
       DEAL_II_HAVE_CXX11_THREAD)
     RESET_CMAKE_REQUIRED()
-    PUSH_CMAKE_REQUIRED("${DEAL_II_CXX11_FLAG}")
+    PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}")
   ELSE()
     # Just export it ;-)
     SET(DEAL_II_HAVE_CXX11_THREAD TRUE CACHE BOOL "")
@@ -228,7 +271,30 @@ IF(NOT DEFINED DEAL_II_WITH_CXX11 OR DEAL_II_WITH_CXX11)
       SET(DEAL_II_HAVE_CXX11 TRUE)
   ENDIF()
 
+  #
+  # This test does not guarantee full C++14 support, but virtually every
+  # compiler with some C++14 support implements this.
+  #
+  CHECK_CXX_SOURCE_COMPILES(
+    "
+    #include <memory>
+    int main()
+    {
+        auto ptr = std::make_unique<int>(42);
+        return 0;
+    }
+    "
+    DEAL_II_HAVE_CXX14_MAKE_UNIQUE)
+  IF( DEAL_II_HAVE_CXX11 AND
+      DEAL_II_HAVE_CXX14_MAKE_UNIQUE AND
+      DEAL_II_WITH_CXX14)
+    SET(DEAL_II_HAVE_CXX14 TRUE)
+  ENDIF()
+
   RESET_CMAKE_REQUIRED()
+ELSE()
+  SET(DEAL_II_WITH_CXX11 FALSE)
+  SET(DEAL_II_WITH_CXX14 FALSE)
 ENDIF()
 
 #
@@ -240,6 +306,15 @@ OPTION(DEAL_II_WITH_CXX11
   ${DEAL_II_HAVE_CXX11}
   )
 
+#
+# Set up a configuration option for C++14 support:
+#
+
+OPTION(DEAL_II_WITH_CXX14
+  "Compile deal.II using C++14 language standard."
+  ${DEAL_II_HAVE_CXX14}
+  )
+
 #
 # 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):
@@ -254,19 +329,39 @@ IF(DEAL_II_WITH_CXX11 AND NOT DEAL_II_HAVE_CXX11)
     "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 via\n"
-    "    -DDEAL_II_CXX11_FLAG=\"...\"\n\n"
+    "    -DDEAL_II_CXX_VERSION_FLAG=\"...\"\n\n"
+    )
+ENDIF()
+
+#
+# similar for C++14
+#
+
+IF(DEAL_II_WITH_CXX14 AND NOT DEAL_II_HAVE_CXX14)
+  MESSAGE(FATAL_ERROR "\n"
+    "C++14 support was requested (DEAL_II_WITH_CXX14=${DEAL_II_WITH_CXX14}) "
+    "but is not supported by the current compiler and flag combination.\n"
+    "Please disable C++14 support, i.e. configure with\n"
+    "    -DDEAL_II_WITH_CXX14=FALSE,\n"
+    "or use a different compiler, instead. (If the compiler flag for C++14 "
+    "support differs from \"-std=c++14\", a suitable "
+    "compiler flag has to be specified manually via\n"
+    "    -DDEAL_II_CXX_VERSION_FLAG=\"...\"\n\n"
     )
 ENDIF()
 
 #
-# Set up C++11 support:
+# Set up support for newer versions of C++:
 #
 
-IF(DEAL_II_WITH_CXX11)
-  ADD_FLAGS(DEAL_II_CXX_FLAGS "${DEAL_II_CXX11_FLAG}")
+IF (DEAL_II_WITH_CXX14)
+  ADD_FLAGS(DEAL_II_CXX_FLAGS "${DEAL_II_CXX_VERSION_FLAG}")
+  MESSAGE(STATUS "DEAL_II_WITH_CXX14 successfully set up")
+ELSEIF(DEAL_II_WITH_CXX11)
+  ADD_FLAGS(DEAL_II_CXX_FLAGS "${DEAL_II_CXX_VERSION_FLAG}")
   MESSAGE(STATUS "DEAL_II_WITH_CXX11 successfully set up")
 
-  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX11_FLAG}")
+  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}")
   CHECK_CXX_SOURCE_COMPILES(
     "
     #include <type_traits>
@@ -275,7 +370,7 @@ IF(DEAL_II_WITH_CXX11)
     DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE)
   RESET_CMAKE_REQUIRED()
 ELSE()
-  MESSAGE(STATUS "DEAL_II_WITH_CXX11 disabled")
+  MESSAGE(STATUS "DEAL_II_WITH_CXX14 and DEAL_II_WITH_CXX11 are both disabled")
 ENDIF()
 
 
index e45a7b53fcc0c56d1704fcc6734decbadad66d48..6ac82586bd3931bc12a8105d8e41805de1c67a57 100644 (file)
@@ -296,7 +296,7 @@ ENDIF()
 # - Wolfgang Bangerth, 2014
 #
 IF(DEAL_II_WITH_CXX11)
-  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX11_FLAG}")
+  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}")
   CHECK_CXX_COMPILER_BUG(
     "
     #include <functional>
index 53c1167455051859d9f09d8f3d0565e9c98730c2..acc46a0f142a874af0d3113337ed8fceaba8ce31 100644 (file)
@@ -125,7 +125,7 @@ DEAL_II_FIND_FILE(SACADO_CMATH_HPP Sacado_cmath.hpp
 
 IF(EXISTS ${SACADO_CMATH_HPP})
   LIST(APPEND CMAKE_REQUIRED_INCLUDES ${Trilinos_INCLUDE_DIRS})
-  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX11_FLAG}")
+  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}")
 
   CHECK_CXX_SOURCE_COMPILES(
     "
index 0650ff7831607d4ba36bd67d6f4f827a703cd999..a70d2deb991956657081f5676febd74cd88a59b3 100644 (file)
@@ -38,6 +38,7 @@
 #cmakedefine DEAL_II_WITH_ARPACK
 #cmakedefine DEAL_II_WITH_BZIP2
 #cmakedefine DEAL_II_WITH_CXX11
+#cmakedefine DEAL_II_WITH_CXX14
 #cmakedefine DEAL_II_WITH_HDF5
 #cmakedefine DEAL_II_WITH_LAPACK
 #cmakedefine DEAL_II_WITH_METIS

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.