annotate src/capnproto-git-20161025/c++/m4/ax_cxx_compile_stdcxx_11.m4 @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 9530b331f8c1
children
rev   line source
cannam@48 1 # ============================================================================
cannam@48 2 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
cannam@48 3 # Additionally modified to detect -stdlib by Kenton Varda.
cannam@48 4 # ============================================================================
cannam@48 5 #
cannam@48 6 # SYNOPSIS
cannam@48 7 #
cannam@48 8 # AX_CXX_COMPILE_STDCXX_11([ext|noext])
cannam@48 9 #
cannam@48 10 # DESCRIPTION
cannam@48 11 #
cannam@48 12 # Check for baseline language coverage in the compiler for the C++11
cannam@48 13 # standard; if necessary, add switches to CXXFLAGS to enable support.
cannam@48 14 # Errors out if no mode that supports C++11 baseline syntax can be found.
cannam@48 15 # The argument, if specified, indicates whether you insist on an extended
cannam@48 16 # mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -std=c++11).
cannam@48 17 # If neither is specified, you get whatever works, with preference for an
cannam@48 18 # extended mode.
cannam@48 19 #
cannam@48 20 # Additionally, check if the standard library supports C++11. If not,
cannam@48 21 # try adding -stdlib=libc++ to see if that fixes it. This is needed e.g.
cannam@48 22 # on Mac OSX 10.8, which ships with a very old libstdc++ but a relatively
cannam@48 23 # new libc++.
cannam@48 24 #
cannam@48 25 # Both flags are actually added to CXX rather than CXXFLAGS to work around
cannam@48 26 # a bug in libtool: -stdlib is stripped from CXXFLAGS when linking dynamic
cannam@48 27 # libraries because it is not recognized. A patch was committed to mainline
cannam@48 28 # libtool in February 2012 but as of June 2013 there has not yet been a
cannam@48 29 # release containing this patch.
cannam@48 30 # http://git.savannah.gnu.org/gitweb/?p=libtool.git;a=commit;h=c0c49f289f22ae670066657c60905986da3b555f
cannam@48 31 #
cannam@48 32 # LICENSE
cannam@48 33 #
cannam@48 34 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
cannam@48 35 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
cannam@48 36 # Copyright (c) 2013 Kenton Varda <temporal@gmail.com>
cannam@48 37 #
cannam@48 38 # Copying and distribution of this file, with or without modification, are
cannam@48 39 # permitted in any medium without royalty provided the copyright notice
cannam@48 40 # and this notice are preserved. This file is offered as-is, without any
cannam@48 41 # warranty.
cannam@48 42
cannam@48 43 #serial 1
cannam@48 44
cannam@48 45 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
cannam@48 46 template <typename T>
cannam@48 47 struct check
cannam@48 48 {
cannam@48 49 static_assert(sizeof(int) <= sizeof(T), "not big enough");
cannam@48 50 };
cannam@48 51
cannam@48 52 typedef check<check<bool>> right_angle_brackets;
cannam@48 53
cannam@48 54 int a;
cannam@48 55 decltype(a) b;
cannam@48 56
cannam@48 57 typedef check<int> check_type;
cannam@48 58 check_type c;
cannam@48 59 check_type&& cr = static_cast<check_type&&>(c);
cannam@48 60
cannam@48 61 // GCC 4.7 introduced __float128 and makes reference to it in type_traits.
cannam@48 62 // Clang doesn't implement it, so produces an error. Using -std=c++11
cannam@48 63 // instead of -std=gnu++11 works around the problem. But on some
cannam@48 64 // platforms we need -std=gnu++11. So we want to make sure the test of
cannam@48 65 // -std=gnu++11 fails only where this problem is present, and we hope that
cannam@48 66 // -std=c++11 is always an acceptable fallback in these cases. Complicating
cannam@48 67 // matters, though, is that we don't want to fail here if the platform is
cannam@48 68 // completely missing a C++11 standard library, because we want to probe that
cannam@48 69 // in a later test. It happens, though, that Clang allows us to check
cannam@48 70 // whether a header exists at all before we include it.
cannam@48 71 //
cannam@48 72 // So, if we detect that __has_include is available (which it is on Clang),
cannam@48 73 // and we use it to detect that <type_traits> (a C++11 header) exists, then
cannam@48 74 // we go ahead and #include it to see if it breaks. In all other cases, we
cannam@48 75 // don't #include it at all.
cannam@48 76 #ifdef __has_include
cannam@48 77 #if __has_include(<type_traits>)
cannam@48 78 #include <type_traits>
cannam@48 79 #endif
cannam@48 80 #endif
cannam@48 81 ])
cannam@48 82
cannam@48 83 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody_lib], [
cannam@48 84 #include <initializer_list>
cannam@48 85 #include <unordered_map>
cannam@48 86 #include <atomic>
cannam@48 87 #include <thread>
cannam@48 88 ])
cannam@48 89
cannam@48 90 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
cannam@48 91 m4_if([$1], [], [],
cannam@48 92 [$1], [ext], [],
cannam@48 93 [$1], [noext], [],
cannam@48 94 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
cannam@48 95 AC_LANG_ASSERT([C++])dnl
cannam@48 96 ac_success=no
cannam@48 97 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
cannam@48 98 ax_cv_cxx_compile_cxx11,
cannam@48 99 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
cannam@48 100 [ax_cv_cxx_compile_cxx11=yes],
cannam@48 101 [ax_cv_cxx_compile_cxx11=no])])
cannam@48 102 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
cannam@48 103 ac_success=yes
cannam@48 104 fi
cannam@48 105
cannam@48 106 m4_if([$1], [noext], [], [dnl
cannam@48 107 if test x$ac_success = xno; then
cannam@48 108 for switch in -std=gnu++11 -std=gnu++0x; do
cannam@48 109 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
cannam@48 110 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
cannam@48 111 $cachevar,
cannam@48 112 [ac_save_CXX="$CXX"
cannam@48 113 CXX="$CXX $switch"
cannam@48 114 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
cannam@48 115 [eval $cachevar=yes],
cannam@48 116 [eval $cachevar=no])
cannam@48 117 CXX="$ac_save_CXX"])
cannam@48 118 if eval test x\$$cachevar = xyes; then
cannam@48 119 CXX="$CXX $switch"
cannam@48 120 ac_success=yes
cannam@48 121 break
cannam@48 122 fi
cannam@48 123 done
cannam@48 124 fi])
cannam@48 125
cannam@48 126 m4_if([$1], [ext], [], [dnl
cannam@48 127 if test x$ac_success = xno; then
cannam@48 128 for switch in -std=c++11 -std=c++0x; do
cannam@48 129 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
cannam@48 130 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
cannam@48 131 $cachevar,
cannam@48 132 [ac_save_CXX="$CXX"
cannam@48 133 CXX="$CXX $switch"
cannam@48 134 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
cannam@48 135 [eval $cachevar=yes],
cannam@48 136 [eval $cachevar=no])
cannam@48 137 CXX="$ac_save_CXX"])
cannam@48 138 if eval test x\$$cachevar = xyes; then
cannam@48 139 CXX="$CXX $switch"
cannam@48 140 ac_success=yes
cannam@48 141 break
cannam@48 142 fi
cannam@48 143 done
cannam@48 144 fi])
cannam@48 145
cannam@48 146 if test x$ac_success = xno; then
cannam@48 147 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
cannam@48 148 else
cannam@48 149 ac_success=no
cannam@48 150 AC_CACHE_CHECK(whether $CXX supports C++11 library features by default,
cannam@48 151 ax_cv_cxx_compile_cxx11_lib,
cannam@48 152 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody_lib])],
cannam@48 153 [ax_cv_cxx_compile_cxx11_lib=yes],
cannam@48 154 [ax_cv_cxx_compile_cxx11_lib=no])
cannam@48 155 ])
cannam@48 156 if test x$ax_cv_cxx_compile_cxx11_lib = xyes; then
cannam@48 157 ac_success=yes
cannam@48 158 else
cannam@48 159 # Try with -stdlib=libc++
cannam@48 160 AC_CACHE_CHECK(whether $CXX supports C++11 library features with -stdlib=libc++,
cannam@48 161 ax_cv_cxx_compile_cxx11_lib_libcxx,
cannam@48 162 [ac_save_CXX="$CXX"
cannam@48 163 CXX="$CXX -stdlib=libc++"
cannam@48 164 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody_lib])],
cannam@48 165 [eval ax_cv_cxx_compile_cxx11_lib_libcxx=yes],
cannam@48 166 [eval ax_cv_cxx_compile_cxx11_lib_libcxx=no])
cannam@48 167 CXX="$ac_save_CXX"])
cannam@48 168 if eval test x$ax_cv_cxx_compile_cxx11_lib_libcxx = xyes; then
cannam@48 169 CXX="$CXX -stdlib=libc++"
cannam@48 170 ac_success=yes
cannam@48 171 break
cannam@48 172 fi
cannam@48 173 fi
cannam@48 174
cannam@48 175 if test x$ac_success = xno; then
cannam@48 176 AC_MSG_ERROR([*** A C++ library with support for C++11 features is required.])
cannam@48 177 fi
cannam@48 178 fi
cannam@48 179 ])