From 364d0a8651e2043945233cdc9ed0c19133d9f6b4 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Sun, 22 Dec 2013 18:36:41 +0000 Subject: [PATCH] CMake: Organize C++11 support as a toggable feature git-svn-id: https://svn.dealii.org/trunk@32097 0785d39b-7218-0410-832d-ea1e28bc413d --- .../cmake/checks/check_01_cxx_features.cmake | 124 ++++++++---------- deal.II/cmake/setup_cached_variables.cmake | 8 ++ deal.II/doc/users/config.sample | 5 +- deal.II/include/deal.II/base/config.h.in | 6 +- .../include/deal.II/base/std_cxx1x/array.h | 2 +- deal.II/include/deal.II/base/std_cxx1x/bind.h | 2 +- .../base/std_cxx1x/condition_variable.h | 2 +- .../include/deal.II/base/std_cxx1x/function.h | 2 +- .../include/deal.II/base/std_cxx1x/mutex.h | 2 +- .../deal.II/base/std_cxx1x/shared_ptr.h | 2 +- .../include/deal.II/base/std_cxx1x/thread.h | 2 +- .../include/deal.II/base/std_cxx1x/tuple.h | 2 +- .../deal.II/base/std_cxx1x/type_traits.h | 2 +- 13 files changed, 78 insertions(+), 83 deletions(-) diff --git a/deal.II/cmake/checks/check_01_cxx_features.cmake b/deal.II/cmake/checks/check_01_cxx_features.cmake index 0f5b0865f2..c5024e098a 100644 --- a/deal.II/cmake/checks/check_01_cxx_features.cmake +++ b/deal.II/cmake/checks/check_01_cxx_features.cmake @@ -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 @@ -34,31 +33,24 @@ # # ######################################################################## + # -# 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 - int main(){ std::is_trivially_copyable bob; } - " - DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE) + RESET_CMAKE_REQUIRED() +ENDIF() -# Currently unused: # -# CHECK_CXX_SOURCE_COMPILES( -# " -# #include -# std::vector 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 ], -# std::vector v; -# int main(){ for (std::vector::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 + int main(){ std::is_trivially_copyable 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() diff --git a/deal.II/cmake/setup_cached_variables.cmake b/deal.II/cmake/setup_cached_variables.cmake index 055fe5c59f..f6e074057c 100644 --- a/deal.II/cmake/setup_cached_variables.cmake +++ b/deal.II/cmake/setup_cached_variables.cmake @@ -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: # diff --git a/deal.II/doc/users/config.sample b/deal.II/doc/users/config.sample index c81f471a80..a64c3dcbb4 100644 --- a/deal.II/doc/users/config.sample +++ b/deal.II/doc/users/config.sample @@ -632,12 +632,11 @@ # 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 "") # diff --git a/deal.II/include/deal.II/base/config.h.in b/deal.II/include/deal.II/base/config.h.in index 34c4b9baf9..7317d4fa68 100644 --- a/deal.II/include/deal.II/base/config.h.in +++ b/deal.II/include/deal.II/base/config.h.in @@ -112,8 +112,10 @@ * 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 diff --git a/deal.II/include/deal.II/base/std_cxx1x/array.h b/deal.II/include/deal.II/base/std_cxx1x/array.h index 68b8060321..22635ef086 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/array.h +++ b/deal.II/include/deal.II/base/std_cxx1x/array.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/include/deal.II/base/std_cxx1x/bind.h b/deal.II/include/deal.II/base/std_cxx1x/bind.h index 9cb2192988..5868fda7d0 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/bind.h +++ b/deal.II/include/deal.II/base/std_cxx1x/bind.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include diff --git a/deal.II/include/deal.II/base/std_cxx1x/condition_variable.h b/deal.II/include/deal.II/base/std_cxx1x/condition_variable.h index 4fd712c36c..1927778f1f 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/condition_variable.h +++ b/deal.II/include/deal.II/base/std_cxx1x/condition_variable.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/include/deal.II/base/std_cxx1x/function.h b/deal.II/include/deal.II/base/std_cxx1x/function.h index 86aea59ed1..0817258279 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/function.h +++ b/deal.II/include/deal.II/base/std_cxx1x/function.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/include/deal.II/base/std_cxx1x/mutex.h b/deal.II/include/deal.II/base/std_cxx1x/mutex.h index 7c195fffc9..e8b40a54e2 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/mutex.h +++ b/deal.II/include/deal.II/base/std_cxx1x/mutex.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/include/deal.II/base/std_cxx1x/shared_ptr.h b/deal.II/include/deal.II/base/std_cxx1x/shared_ptr.h index 172218deda..78f6701cab 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/shared_ptr.h +++ b/deal.II/include/deal.II/base/std_cxx1x/shared_ptr.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/include/deal.II/base/std_cxx1x/thread.h b/deal.II/include/deal.II/base/std_cxx1x/thread.h index ac3ed95d4d..2dccd96d78 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/thread.h +++ b/deal.II/include/deal.II/base/std_cxx1x/thread.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/include/deal.II/base/std_cxx1x/tuple.h b/deal.II/include/deal.II/base/std_cxx1x/tuple.h index b3d846da6e..4a23a3d441 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/tuple.h +++ b/deal.II/include/deal.II/base/std_cxx1x/tuple.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/include/deal.II/base/std_cxx1x/type_traits.h b/deal.II/include/deal.II/base/std_cxx1x/type_traits.h index d0e34b3280..d2084bb48b 100644 --- a/deal.II/include/deal.II/base/std_cxx1x/type_traits.h +++ b/deal.II/include/deal.II/base/std_cxx1x/type_traits.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_USE_CXX11 +#ifdef DEAL_II_WITH_CXX11 # include DEAL_II_NAMESPACE_OPEN -- 2.39.5