annotate acinclude.m4 @ 536:74c5b0bfa108

Merge
author Chris Cannam
date Tue, 03 Mar 2020 11:48:28 +0000
parents 459cddd7e64a
children
rev   line source
Chris@526 1
Chris@526 2 # From autoconf archive:
Chris@526 3
Chris@526 4 # ============================================================================
Chris@526 5 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
Chris@526 6 # ============================================================================
Chris@526 7 #
Chris@526 8 # SYNOPSIS
Chris@526 9 #
Chris@526 10 # AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
Chris@526 11 #
Chris@526 12 # DESCRIPTION
Chris@526 13 #
Chris@526 14 # Check for baseline language coverage in the compiler for the C++11
Chris@526 15 # standard; if necessary, add switches to CXXFLAGS to enable support.
Chris@526 16 #
Chris@526 17 # The first argument, if specified, indicates whether you insist on an
Chris@526 18 # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
Chris@526 19 # -std=c++11). If neither is specified, you get whatever works, with
Chris@526 20 # preference for an extended mode.
Chris@526 21 #
Chris@526 22 # The second argument, if specified 'mandatory' or if left unspecified,
Chris@526 23 # indicates that baseline C++11 support is required and that the macro
Chris@526 24 # should error out if no mode with that support is found. If specified
Chris@526 25 # 'optional', then configuration proceeds regardless, after defining
Chris@526 26 # HAVE_CXX11 if and only if a supporting mode is found.
Chris@526 27 #
Chris@526 28 # LICENSE
Chris@526 29 #
Chris@526 30 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
Chris@526 31 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
Chris@526 32 # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
Chris@526 33 # Copyright (c) 2014 Alexey Sokolov <sokolov@google.com>
Chris@526 34 #
Chris@526 35 # Copying and distribution of this file, with or without modification, are
Chris@526 36 # permitted in any medium without royalty provided the copyright notice
Chris@526 37 # and this notice are preserved. This file is offered as-is, without any
Chris@526 38 # warranty.
Chris@526 39
Chris@526 40 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
Chris@526 41 template <typename T>
Chris@526 42 struct check
Chris@526 43 {
Chris@526 44 static_assert(sizeof(int) <= sizeof(T), "not big enough");
Chris@526 45 };
Chris@526 46
Chris@526 47 struct Base {
Chris@526 48 virtual void f() {}
Chris@526 49 };
Chris@526 50 struct Child : public Base {
Chris@526 51 virtual void f() override {}
Chris@526 52 };
Chris@526 53
Chris@526 54 typedef check<check<bool>> right_angle_brackets;
Chris@526 55
Chris@526 56 int a;
Chris@526 57 decltype(a) b;
Chris@526 58
Chris@526 59 typedef check<int> check_type;
Chris@526 60 check_type c;
Chris@526 61 check_type&& cr = static_cast<check_type&&>(c);
Chris@526 62
Chris@526 63 auto d = a;
Chris@526 64 auto l = [](){};
Chris@526 65 ]])
Chris@526 66
Chris@526 67 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
Chris@526 68 m4_if([$1], [], [],
Chris@526 69 [$1], [ext], [],
Chris@526 70 [$1], [noext], [],
Chris@526 71 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
Chris@526 72 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
Chris@526 73 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
Chris@526 74 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
Chris@526 75 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
Chris@526 76 AC_LANG_PUSH([C++])dnl
Chris@526 77 ac_success=no
Chris@526 78 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
Chris@526 79 ax_cv_cxx_compile_cxx11,
Chris@526 80 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
Chris@526 81 [ax_cv_cxx_compile_cxx11=yes],
Chris@526 82 [ax_cv_cxx_compile_cxx11=no])])
Chris@526 83 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
Chris@526 84 ac_success=yes
Chris@526 85 fi
Chris@526 86
Chris@526 87 m4_if([$1], [noext], [], [dnl
Chris@526 88 if test x$ac_success = xno; then
Chris@526 89 for switch in -std=gnu++11 -std=gnu++0x; do
Chris@526 90 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
Chris@526 91 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
Chris@526 92 $cachevar,
Chris@526 93 [ac_save_CXXFLAGS="$CXXFLAGS"
Chris@526 94 CXXFLAGS="$CXXFLAGS $switch"
Chris@526 95 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
Chris@526 96 [eval $cachevar=yes],
Chris@526 97 [eval $cachevar=no])
Chris@526 98 CXXFLAGS="$ac_save_CXXFLAGS"])
Chris@526 99 if eval test x\$$cachevar = xyes; then
Chris@526 100 CXXFLAGS="$CXXFLAGS $switch"
Chris@526 101 ac_success=yes
Chris@526 102 break
Chris@526 103 fi
Chris@526 104 done
Chris@526 105 fi])
Chris@526 106
Chris@526 107 m4_if([$1], [ext], [], [dnl
Chris@526 108 if test x$ac_success = xno; then
Chris@526 109 for switch in -std=c++11 -std=c++0x; do
Chris@526 110 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
Chris@526 111 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
Chris@526 112 $cachevar,
Chris@526 113 [ac_save_CXXFLAGS="$CXXFLAGS"
Chris@526 114 CXXFLAGS="$CXXFLAGS $switch"
Chris@526 115 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
Chris@526 116 [eval $cachevar=yes],
Chris@526 117 [eval $cachevar=no])
Chris@526 118 CXXFLAGS="$ac_save_CXXFLAGS"])
Chris@526 119 if eval test x\$$cachevar = xyes; then
Chris@526 120 CXXFLAGS="$CXXFLAGS $switch"
Chris@526 121 ac_success=yes
Chris@526 122 break
Chris@526 123 fi
Chris@526 124 done
Chris@526 125 fi])
Chris@526 126 AC_LANG_POP([C++])
Chris@526 127 if test x$ax_cxx_compile_cxx11_required = xtrue; then
Chris@526 128 if test x$ac_success = xno; then
Chris@526 129 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
Chris@526 130 fi
Chris@526 131 else
Chris@526 132 if test x$ac_success = xno; then
Chris@526 133 HAVE_CXX11=0
Chris@526 134 AC_MSG_NOTICE([No compiler with C++11 support was found])
Chris@526 135 else
Chris@526 136 HAVE_CXX11=1
Chris@526 137 AC_DEFINE(HAVE_CXX11,1,
Chris@526 138 [define if the compiler supports basic C++11 syntax])
Chris@526 139 fi
Chris@526 140
Chris@526 141 AC_SUBST(HAVE_CXX11)
Chris@526 142 fi
Chris@526 143 ])