annotate src/capnproto-git-20161025/c++/m4/ax_cxx_compile_stdcxx_11.m4 @ 133:1ac99bfc383d

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