Add macros for testing C++0x/11 support in compiler

These files are shamelessly ripped from dune-common/m4 (e28ca3)
This commit is contained in:
Roland Kaufmann 2012-10-24 10:23:51 +02:00
parent 29ccdb7513
commit 2a43bd305a
3 changed files with 91 additions and 0 deletions

60
m4/cxx0x_compiler.m4 Normal file
View File

@ -0,0 +1,60 @@
# 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],
[try flag -std=c++11 to enable C++11 features [[default=yes]]]),
[gxx0xcheck=$enableval],
[gxx0xcheck=yes])
if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then
AC_LANG_PUSH([C++])
CXX="$CXX -std=c++11"
AC_TRY_COMPILE([
#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])
AC_ARG_ENABLE(gxx0xcheck,
AC_HELP_STRING([--disable-gxx0xcheck],
[try flag -std=c++0x to enable C++11 features [[default=yes]]]),
[gxx0xcheck=$enableval],
[gxx0xcheck=yes])
if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then
AC_LANG_PUSH([C++])
CXX="$CXX -std=c++0x"
AC_TRY_COMPILE([
#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
])

17
m4/cxx0x_nullptr.m4 Normal file
View File

@ -0,0 +1,17 @@
AC_DEFUN([NULLPTR_CHECK],[
AC_CACHE_CHECK([whether nullptr is supported], dune_cv_nullptr_support, [
AC_REQUIRE([AC_PROG_CXX])
AC_REQUIRE([GXX0X])
AC_LANG_PUSH([C++])
AC_TRY_COMPILE([],[
char* ch = nullptr;
if(ch!=nullptr) { ; }
],
dune_cv_nullptr_support=yes,
dune_cv_nullptr_support=no)
AC_LANG_POP
])
if test "x$dune_cv_nullptr_support" = xyes; then
AC_DEFINE(HAVE_NULLPTR, 1, [Define to 1 if nullptr is supported])
fi
])

14
m4/cxx0x_static_assert.m4 Normal file
View File

@ -0,0 +1,14 @@
AC_DEFUN([STATIC_ASSERT_CHECK],[
AC_CACHE_CHECK([whether static_assert is supported], dune_cv_static_assert_support, [
AC_REQUIRE([AC_PROG_CXX])
AC_REQUIRE([GXX0X])
AC_LANG_PUSH([C++])
AC_TRY_COMPILE([],[static_assert(true,"MSG")],
dune_cv_static_assert_support=yes,
dune_cv_static_assert_support=no)
AC_LANG_POP
])
if test "x$dune_cv_static_assert_support" = xyes; then
AC_DEFINE(HAVE_STATIC_ASSERT, 1, [Define to 1 if static_assert is supported])
fi
])