Skip to content
Snippets Groups Projects
Commit 77c8533e authored by Steffen Müthing's avatar Steffen Müthing
Browse files

[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.
parent d1fbdfaf
No related branches found
No related tags found
No related merge requests found
......@@ -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 ")
......
......@@ -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
......
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(
[],[[
......
# whether compiler accepts -std=c++11 or -std=c++0x
# can be disabled by --disable-gxx0xcheck
# 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])
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
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([[
......@@ -22,18 +25,15 @@ AC_DEFUN([GXX0X],[
dune_cv_gplusplus_accepts_cplusplus11=yes,
dune_cv_gplusplus_accepts_cplusplus11=no)
AC_LANG_POP([C++])
CXX="$ac_save_CXX"
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
# 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, [
AC_REQUIRE([AC_PROG_CXX])
if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then
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([[
......@@ -43,13 +43,24 @@ AC_DEFUN([GXX0X],[
dune_cv_gplusplus_accepts_cplusplus0x=yes,
dune_cv_gplusplus_accepts_cplusplus0x=no)
AC_LANG_POP([C++])
CXX="$ac_save_CXX"
fi
])
if test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then
CXX="$ac_save_CXX -std=c++0x"
CXXCPP="$CXXCPP -std=c++0x"
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
CXX="$ac_save_CXX"
# 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
])
......@@ -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([
......
......@@ -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])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment