>From 471afd936ccd513aa15509d5c2c8b0f4e71c9306 Mon Sep 17 00:00:00 2001 From: Roger Leigh
Date: Sun, 20 Jan 2013 18:50:49 +0000 Subject: [PATCH] AC_PROG_CXX: Add checks for C++11, C++98TR1 and C++98 These checks are the C++ equivalent of the existing C standards checks. --- doc/autoconf.texi | 97 +++++++++++ lib/autoconf/c.m4 | 471 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 560 insertions(+), 8 deletions(-) diff --git a/doc/autoconf.texi b/doc/autoconf.texi index bb83443..a5987a6 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -7642,6 +7642,36 @@ like this: AC_PROG_CXX([gcc cl KCC CC cxx cc++ xlC aCC c++ g++]) @end example +If necessary, add an option to output variable @code{CXX} to enable +support for ISO Standard C++ features with extensions. Prefer the newest +C++ standard that is supported. Currently the newest standard is ISO C++11, +with ISO C++98 (with TR1 extensions) and ISO C++98 being the older versions. +After calling this macro you can check whether the C++ compiler has been +set to accept Standard C++; if not, the shell variable address@hidden is set to @samp{no}. + +When attempting to add compiler options, prefer extended functionality +to strict conformance: the goal is to enable whatever standard features +that are available, not to check for full conformance to the standard or +to prohibit incompatible extensions. Test for C++11 support by checking +for the language features @code{auto}, @code{constexpr}, address@hidden, @code{default}ed and @code{delete}ed constructors, +delegate constructors, @code{final}, initializer lists, lambda +functions, @code{nullptr}, @code{override}, range-based for loops, +template brackets without spaces and unicode literals, and library +features @code{std::array}, @code{std::shared_ptr}, address@hidden::weak_ptr}, @code{std::regex} and @code{std::tuple}. Test for +C++98TR1 support by checking for the library features address@hidden::tr1::array}, @code{std::tr1::shared_ptr}, address@hidden::tr1::weak_ptr}, @code{std::tr1::regex} and address@hidden::tr1::tuple}. Test for C++98 support using basic features of +the @code{std} namespace including @code{std::string}, containers +(@code{std::list}, @code{std::map}, @code{std::set}, address@hidden::vector}), streams (fstreams, iostreams, stringstreams, +iomanip), @code{std::pair}, exceptions (@code{try}, @code{catch} and address@hidden::runtime_error}) and algorithms. Tests for more recent +standards include all the tests for older standards. + If using the GNU C++ compiler, set shell variable @code{GXX} to @samp{yes}. If output variable @code{CXXFLAGS} was not already set, set it to @option{-g -O2} for the GNU C++ compiler (@option{-O2} on @@ -7652,6 +7682,73 @@ and before @code{AC_PROG_CXX} to select an empty default instead. @end defmac address@hidden AC_PROG_CXX_CXX11 (@ovar{action-if-available}, @ovar{action-if-unavailable}) address@hidden address@hidden prog_cxx_cxx11 +If the C++ compiler is not in C++11 mode by default, try to add an +option to output variable @code{CXX} to make it so. This macro tries +various options that select C++11 on some system or another, preferring +extended functionality modes over strict conformance modes. Test for +C++11 support by checking for the language features @code{auto}, address@hidden, @code{decltype}, @code{default}ed and @code{delete}ed +constructors, delegate constructors, @code{final}, initializer lists, +lambda functions, @code{nullptr}, @code{override}, range-based for +loops, template brackets without spaces and unicode literals, and +library features @code{std::array}, @code{std::shared_ptr}, address@hidden::weak_ptr}, @code{std::regex} and @code{std::tuple}. + +After calling this macro you can check whether the C++ compiler has been +set to accept C++11; if not, the shell variable address@hidden is set to @samp{no}. + +This macro is rarely needed. It should be used only if your application +requires C++11 and will not work with earlier C++ versions. Typical +applications should use @code{AC_PROG_CXX} instead. address@hidden defmac + address@hidden AC_PROG_CXX_CXX98TR1 (@ovar{action-if-available}, @ovar{action-if-unavailable}) address@hidden address@hidden prog_cxx_cxx98tr1 +If the C++ compiler is not in C++98 mode (with TR1 extensions) by +default, try to add an option to output variable @code{CXX} to make it +so. This macro tries various options that select C++98TR1 on some +system or another, preferring extended functionality modes over strict +conformance modes. Test for C++98TR1 support by checking for the +library features @code{std::tr1::array}, @code{std::tr1::shared_ptr}, address@hidden::tr1::weak_ptr}, @code{std::tr1::regex} and address@hidden::tr1::tuple}. + +After calling this macro you can check whether the C++ compiler has been +set to accept C++98TR1; if not, the shell variable address@hidden is set to @samp{no}. + +This macro is rarely needed. It should be used only if your application +requires C++98TR1 and will not work with earlier C++ versions. Typical +applications should use @code{AC_PROG_CXX} instead. address@hidden defmac + address@hidden AC_PROG_CXX_CXX98 (@ovar{action-if-available}, @ovar{action-if-unavailable}) address@hidden address@hidden prog_cxx_cxx98 +If the C++ compiler is not in C++98 mode by default, try to add an +option to output variable @code{CXX} to make it so. This macro tries +various options that select C++98 on some system or another, preferring +extended functionality modes over strict conformance modes. Test for +C++98 support using basic features of the @code{std} namespace including address@hidden::string}, containers (@code{std::list}, @code{std::map}, address@hidden::set}, @code{std::vector}), streams (fstreams, iostreams, +stringstreams, iomanip), @code{std::pair}, exceptions (@code{try}, address@hidden and @code{std::runtime_error}) and algorithms. + +After calling this macro you can check whether the C++ compiler has been +set to accept C++98; if not, the shell variable address@hidden is set to @samp{no}. + +This macro is rarely needed. It should be used only if your application +requires C++98 and will not work with earlier C++ versions. Typical +applications should use @code{AC_PROG_CXX} instead. address@hidden defmac + @defmac AC_PROG_CXXCPP @acindex{PROG_CXXCPP} @evindex CXXCPP diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index affd765..052e3d2 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -657,7 +657,7 @@ AC_DEFUN([AC_LANG_PREPROC(C++)], # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX. AC_DEFUN([AC_PROG_CXXCPP], -[AC_REQUIRE([AC_PROG_CXX])dnl +[AC_REQUIRE([_AC_PROG_CXX])dnl AC_ARG_VAR([CXXCPP], [C++ preprocessor])dnl _AC_ARG_VAR_CPPFLAGS()dnl AC_LANG_PUSH(C++)dnl @@ -688,7 +688,7 @@ AC_LANG_POP(C++)dnl # --------------------- # Find the C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able. AC_DEFUN([AC_LANG_COMPILER(C++)], -[AC_REQUIRE([AC_PROG_CXX])]) +[AC_REQUIRE([_AC_PROG_CXX])]) # ac_cv_prog_gxx @@ -710,11 +710,11 @@ AU_DEFUN([ac_cv_prog_gxx], # RCC Rational C++ # xlC_r AIX C Set++ (with support for reentrant code) # xlC AIX C Set++ -AN_MAKEVAR([CXX], [AC_PROG_CXX]) -AN_PROGRAM([CC], [AC_PROG_CXX]) -AN_PROGRAM([c++], [AC_PROG_CXX]) -AN_PROGRAM([g++], [AC_PROG_CXX]) -AC_DEFUN([AC_PROG_CXX], +AN_MAKEVAR([CXX], [_AC_PROG_CXX]) +AN_PROGRAM([CC], [_AC_PROG_CXX]) +AN_PROGRAM([c++], [_AC_PROG_CXX]) +AN_PROGRAM([g++], [_AC_PROG_CXX]) +AC_DEFUN([_AC_PROG_CXX], [AC_LANG_PUSH(C++)dnl AC_ARG_VAR([CXX], [C++ compiler command])dnl AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl @@ -750,6 +750,35 @@ else fi _AC_PROG_CXX_G AC_LANG_POP(C++)dnl +])# _AC_PROG_CXX + +# AC_PROG_CXX([LIST-OF-COMPILERS]) +# -------------------------------- +# LIST-OF-COMPILERS is a space separated list of C++ compilers to search +# for (if not specified, a default list is used). This just gives the +# user an opportunity to specify an alternative search list for the C++ +# compiler. +# aCC HP-UX C++ compiler much better than `CC', so test before. +# FCC Fujitsu C++ compiler +# KCC KAI C++ compiler +# RCC Rational C++ +# xlC_r AIX C Set++ (with support for reentrant code) +# xlC AIX C Set++ +AC_DEFUN([AC_PROG_CXX], +[AC_LANG_PUSH(C++)dnl +AC_REQUIRE([_AC_PROG_CXX])dnl +dnl Set ac_prog_cxx_stdcxx to the supported C++ version. +dnl Also set the documented variable ac_cv_prog_cxx_stdcxx; +dnl its name was chosen when it was cached, but it is no longer cached. +_AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11 + ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11], + [_AC_PROG_CXX_CXX98TR1([ac_prog_cxx_stdcxx=cxx98tr1 + ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98tr1], + [_AC_PROG_CXX_CXX98([ac_prog_cxx_stdcxx=cxx98 + ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98], + [ac_prog_cxx_stdcxx=no + ac_cv_prog_cxx_stdcxx=no])])]) +AC_LANG_POP(C++)dnl ])# AC_PROG_CXX @@ -800,7 +829,7 @@ fi[]dnl # Test if the C++ compiler accepts the options `-c' and `-o' # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not. AC_DEFUN([AC_PROG_CXX_C_O], -[AC_REQUIRE([AC_PROG_CXX])dnl +[AC_REQUIRE([_AC_PROG_CXX])dnl AC_LANG_PUSH([C++])dnl AC_CACHE_CHECK([whether $CXX understands -c and -o together], [ac_cv_prog_cxx_c_o], @@ -2158,3 +2187,429 @@ AC_DEFUN([AC_OPENMP], fi AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS]) ]) + +# _AC_CXX_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST, +# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE) +# -------------------------------------------------------------- +# Check whether the C++ compiler accepts features of STANDARD (e.g +# `cxx98', `cxx11') by trying to compile a program of TEST-PROLOGUE +# and TEST-BODY. If this fails, try again with each compiler option +# in the space-separated OPTION-LIST; if one helps, append it to CXX. +# If eventually successful, run ACTION-IF-AVAILABLE, else +# ACTION-IF-UNAVAILABLE. +AC_DEFUN([_AC_CXX_STD_TRY], +[AC_MSG_CHECKING([for $CXX option to enable ]m4_translit(m4_translit($1, [x], [+]), [a-z], [A-Z])[ features]) +AC_LANG_PUSH(C++)dnl +AC_CACHE_VAL(ac_cv_prog_cxx_$1, +[ac_cv_prog_cxx_$1=no +ac_save_CXX=$CXX +AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])]) +for ac_arg in '' $4 +do + CXX="$ac_save_CXX $ac_arg" + _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_$1=$ac_arg]) + test "x$ac_cv_prog_cxx_$1" != "xno" && break +done +rm -f conftest.$ac_ext +CXX=$ac_save_CXX +])# AC_CACHE_VAL +ac_prog_cxx_stdcxx_options= +case "x$ac_cv_prog_cxx_$1" in + x) + AC_MSG_RESULT([none needed]) ;; + xno) + AC_MSG_RESULT([unsupported]) ;; + *) + ac_prog_cxx_stdcxx_options=" $ac_cv_prog_cxx_$1" + CXX=$CXX$ac_prog_cxx_stdcxx_options + AC_MSG_RESULT([$ac_cv_prog_cxx_$1]) ;; +esac +AC_LANG_POP(C++)dnl +AS_IF([test "x$ac_cv_prog_cxx_$1" != xno], [$5], [$6]) +])# _AC_CXX_STD_TRY + +# _AC_CXX_CXX98_TEST_HEADER +# ------------------------- +# A C++ header suitable for testing for CXX98. +AC_DEFUN([_AC_CXX_CXX98_TEST_HEADER], +[[ +#include