From 77c8533ef4fe1e988065d8ea583a95dfe3ca6168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= <muething@dune-project.org> Date: Mon, 14 Apr 2014 18:30:14 +0200 Subject: [PATCH] [Buildsystem] Require C++11-compliant compiler and clean up associated tests As we have bumped our compiler requirements to GCC 4.4+, we can now require the compiler to support C++11. This patch updates both the autotools and the CMake tests to produce an error if the compiler doesn't support either -std=c++11 or -std=c++0x. It also renames the tests from ..0X to ..11 and renames the configure options from --disable-gxx0xcheck to --disable-cxx11check and removes a couple of redundant calls to the autotools macro. --- cmake/modules/CheckCXX11Features.cmake | 11 +++-- lib/dunecommonam2cmake.lib | 6 +-- m4/cxx0x_compiler.m4 | 55 --------------------- m4/cxx0x_nullptr.m4 | 2 +- m4/cxx11_compiler.m4 | 66 ++++++++++++++++++++++++++ m4/cxx11_constexpr.m4 | 2 +- m4/dune_common.m4 | 2 +- 7 files changed, 79 insertions(+), 65 deletions(-) delete mode 100644 m4/cxx0x_compiler.m4 create mode 100644 m4/cxx11_compiler.m4 diff --git a/cmake/modules/CheckCXX11Features.cmake b/cmake/modules/CheckCXX11Features.cmake index a2150a190..91fe8957d 100644 --- a/cmake/modules/CheckCXX11Features.cmake +++ b/cmake/modules/CheckCXX11Features.cmake @@ -17,10 +17,10 @@ cmake_push_check_state() # test for C++11 flags include(TestCXXAcceptsFlag) -if(NOT DISABLE_GXX0XCHECK) +if(NOT DISABLE_CXX11CHECK) # try to use compiler flag -std=c++11 check_cxx_accepts_flag("-std=c++11" CXX_FLAG_CXX11) -endif(NOT DISABLE_GXX0XCHECK) +endif(NOT DISABLE_CXX11CHECK) if(CXX_FLAG_CXX11) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") @@ -31,10 +31,13 @@ if(CXX_FLAG_CXX11) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -std=c++11 ") set(CXX_STD11_FLAGS "-std=c++11") else() - if(NOT DISABLE_GXX0XCHECK) + if(NOT DISABLE_CXX11CHECK) # try to use compiler flag -std=c++0x for older compilers check_cxx_accepts_flag("-std=c++0x" CXX_FLAG_CXX0X) - endif(NOT DISABLE_GXX0XCHECK) + if(NOT CXX_FLAG_CXX0X) + MESSAGE(FATAL_ERROR "Your compiler does not seem to support C++11. If it does, please add any required flags to your CXXFLAGS and run dunecontrol with --disable-cxx11check") + endif(NOT CXX_FLAG_CXX0X) + endif(NOT DISABLE_CXX11CHECK) if(CXX_FLAG_CXX0X) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x" ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ") diff --git a/lib/dunecommonam2cmake.lib b/lib/dunecommonam2cmake.lib index 06ecfcb7d..5e4f646e0 100644 --- a/lib/dunecommonam2cmake.lib +++ b/lib/dunecommonam2cmake.lib @@ -28,10 +28,10 @@ dune_common_options_am2cmake() else CMAKE_PARAMS="$CMAKE_PARAMS -DUSE_MPI=ON" fi - # Check for --disable-gxx0xcheck - echo $PARAMS | grep \\-\\-disable-gxx0xcheck > /dev/null + # Check for --disable-cxx11check + echo $PARAMS | grep \\-\\-disable-cxx11check > /dev/null if test "$?" -eq 0 ; then - CMAKE_PARAMS="$CMAKE_PARAMS -DDISABLE_GXX0XCHECK:BOOL=TRUE" + CMAKE_PARAMS="$CMAKE_PARAMS -DDISABLE_CXX11CHECK:BOOL=TRUE" fi # Check for --disable-gxx0xcheck diff --git a/m4/cxx0x_compiler.m4 b/m4/cxx0x_compiler.m4 deleted file mode 100644 index bc0736bc8..000000000 --- a/m4/cxx0x_compiler.m4 +++ /dev/null @@ -1,55 +0,0 @@ -# whether compiler accepts -std=c++11 or -std=c++0x -# can be disabled by --disable-gxx0xcheck - -AC_DEFUN([GXX0X],[ - ac_save_CXX="$CXX" - - # try flag -std=c++11 - AC_CACHE_CHECK([whether $CXX accepts -std=c++11], dune_cv_gplusplus_accepts_cplusplus11, [ - AC_REQUIRE([AC_PROG_CXX]) - AC_ARG_ENABLE(gxx0xcheck, - AC_HELP_STRING([--disable-gxx0xcheck], - [Skip test whether compiler supports flag -std=c++11 and -std=c++0x to enable C++11 features (with this option C++11 features will not be activated)]), - [gxx0xcheck=$enableval], - [gxx0xcheck=yes]) - if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then - AC_LANG_PUSH([C++]) - CXX="$CXX -std=c++11" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include <iostream> - #include <array> - ]], [])], - dune_cv_gplusplus_accepts_cplusplus11=yes, - dune_cv_gplusplus_accepts_cplusplus11=no) - AC_LANG_POP([C++]) - fi - ]) - if test "x$dune_cv_gplusplus_accepts_cplusplus11" == "xyes" ; then - CXX="$ac_save_CXX -std=c++11" - CXXCPP="$CXXCPP -std=c++11" - else - CXX="$ac_save_CXX" - - # try flag -std=c++0x instead - AC_CACHE_CHECK([whether $CXX accepts -std=c++0x], dune_cv_gplusplus_accepts_cplusplus0x, [ - AC_REQUIRE([AC_PROG_CXX]) - if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then - AC_LANG_PUSH([C++]) - CXX="$CXX -std=c++0x" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include <iostream> - #include <array> - ]], [])], - dune_cv_gplusplus_accepts_cplusplus0x=yes, - dune_cv_gplusplus_accepts_cplusplus0x=no) - AC_LANG_POP([C++]) - fi - ]) - if test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then - CXX="$ac_save_CXX -std=c++0x" - CXXCPP="$CXXCPP -std=c++0x" - else - CXX="$ac_save_CXX" - fi - fi -]) diff --git a/m4/cxx0x_nullptr.m4 b/m4/cxx0x_nullptr.m4 index 0e09739c3..547453ad3 100644 --- a/m4/cxx0x_nullptr.m4 +++ b/m4/cxx0x_nullptr.m4 @@ -1,7 +1,7 @@ AC_DEFUN([NULLPTR_CHECK],[ AC_CACHE_CHECK([whether nullptr is supported], dune_cv_nullptr_support, [ AC_REQUIRE([AC_PROG_CXX]) - AC_REQUIRE([GXX0X]) + AC_REQUIRE([CXX11]) AC_LANG_PUSH([C++]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM( [],[[ diff --git a/m4/cxx11_compiler.m4 b/m4/cxx11_compiler.m4 new file mode 100644 index 000000000..91b6151f8 --- /dev/null +++ b/m4/cxx11_compiler.m4 @@ -0,0 +1,66 @@ +# whether compiler accepts -std=c++11 or -std=c++0x +# can be disabled by --disable-cxx11check + +AC_DEFUN([CXX11],[ + AC_REQUIRE([AC_PROG_CXX]) + AC_ARG_ENABLE(cxx11check, + AC_HELP_STRING([--disable-cxx11check], + [Skip test whether compiler supports flag -std=c++11 and -std=c++0x to enable C++11 features + (Dune always requires C++11 support - if your compiler requires custom flags for C++11 mode, tell configure about them + in your CXXFLAGS and disable this check)]), + [cxx11check=$enableval], + [cxx11check=yes]) + + # try flag -std=c++11 + AC_CACHE_CHECK([whether $CXX accepts -std=c++11], dune_cv_gplusplus_accepts_cplusplus11, [ + dune_cv_gplusplus_accepts_cplusplus11=no + if test "x$GXX" = xyes && test "x$cxx11check" = xyes; then + ac_save_CXX="$CXX" + AC_LANG_PUSH([C++]) + CXX="$CXX -std=c++11" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #include <iostream> + #include <array> + ]], [])], + dune_cv_gplusplus_accepts_cplusplus11=yes, + dune_cv_gplusplus_accepts_cplusplus11=no) + AC_LANG_POP([C++]) + CXX="$ac_save_CXX" + fi + ]) + # try flag -std=c++0x + if test "x$dune_cv_gplusplus_accepts_cplusplus11" == "xno" ; then + AC_CACHE_CHECK([whether $CXX accepts -std=c++0x], dune_cv_gplusplus_accepts_cplusplus0x, [ + dune_cv_gplusplus_accepts_cplusplus0x=no + if test "x$GXX" = xyes && test "x$cxx11check" = xyes; then + ac_save_CXX="$CXX" + AC_LANG_PUSH([C++]) + CXX="$CXX -std=c++0x" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #include <iostream> + #include <array> + ]], [])], + dune_cv_gplusplus_accepts_cplusplus0x=yes, + dune_cv_gplusplus_accepts_cplusplus0x=no) + AC_LANG_POP([C++]) + CXX="$ac_save_CXX" + fi + ]) + fi + + if test "x$dune_cv_gplusplus_accepts_cplusplus11" == "xyes" ; then + CXX="$CXX -std=c++11" + CXXCPP="$CXXCPP -std=c++11" + elif test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then + CXX="$CXX -std=c++0x" + CXXCPP="$CXXCPP -std=c++0x" + else + if test "x$cxx11check" = xyes; then + # we ran the test, and it failed - bail out + AC_MSG_FAILURE([Your compiler does not seem to support C++11!]) + else + # test was skipped, warn the user + AC_MSG_WARN([Skipping test for C++11 support, make sure your compiler supports at least the feature set of GCC 4.4!]) + fi + fi +]) diff --git a/m4/cxx11_constexpr.m4 b/m4/cxx11_constexpr.m4 index 12b7b7acc..4762dc001 100644 --- a/m4/cxx11_constexpr.m4 +++ b/m4/cxx11_constexpr.m4 @@ -4,7 +4,7 @@ AC_DEFUN([CXX11_CONSTEXPR_CHECK],[ AC_CACHE_CHECK([for C++11 constexpr], dune_cv_cxx11_constexpr_support, [ AC_REQUIRE([AC_PROG_CXX]) - AC_REQUIRE([GXX0X]) + AC_REQUIRE([CXX11]) AC_LANG_PUSH([C++]) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([ diff --git a/m4/dune_common.m4 b/m4/dune_common.m4 index f1fa4d423..7949a805a 100644 --- a/m4/dune_common.m4 +++ b/m4/dune_common.m4 @@ -18,7 +18,7 @@ AC_DEFUN([DUNE_COMMON_CHECKS], AC_REQUIRE([AC_PROG_MKDIR_P]) AC_REQUIRE([DUNE_CHECK_COMPILER]) - AC_REQUIRE([GXX0X]) + AC_REQUIRE([CXX11]) AC_REQUIRE([NULLPTR_CHECK]) AC_REQUIRE([CXX11_CONSTEXPR_CHECK]) AC_REQUIRE([DUNE_BOOST_BASE]) -- GitLab