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