comparison acinclude.m4 @ 1011:dbb7f0ab011e cxx11

CXX11 (-std=c++11) branch, to test build environments before making any code adaptations
author Chris Cannam
date Mon, 17 Nov 2014 15:31:07 +0000
parents a98af74f8e2f
children 8a1328ab9c48
comparison
equal deleted inserted replaced
1010:36f79bc5c3d7 1011:dbb7f0ab011e
110 *Darwin*) QMAKE="$QMAKE -spec macx-g++";; 110 *Darwin*) QMAKE="$QMAKE -spec macx-g++";;
111 esac 111 esac
112 112
113 ]) 113 ])
114 114
115 # From autoconf archive:
116
117 # ============================================================================
118 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
119 # ============================================================================
120 #
121 # SYNOPSIS
122 #
123 # AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
124 #
125 # DESCRIPTION
126 #
127 # Check for baseline language coverage in the compiler for the C++11
128 # standard; if necessary, add switches to CXXFLAGS to enable support.
129 #
130 # The first argument, if specified, indicates whether you insist on an
131 # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
132 # -std=c++11). If neither is specified, you get whatever works, with
133 # preference for an extended mode.
134 #
135 # The second argument, if specified 'mandatory' or if left unspecified,
136 # indicates that baseline C++11 support is required and that the macro
137 # should error out if no mode with that support is found. If specified
138 # 'optional', then configuration proceeds regardless, after defining
139 # HAVE_CXX11 if and only if a supporting mode is found.
140 #
141 # LICENSE
142 #
143 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
144 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
145 # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
146 # Copyright (c) 2014 Alexey Sokolov <sokolov@google.com>
147 #
148 # Copying and distribution of this file, with or without modification, are
149 # permitted in any medium without royalty provided the copyright notice
150 # and this notice are preserved. This file is offered as-is, without any
151 # warranty.
152
153 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
154 template <typename T>
155 struct check
156 {
157 static_assert(sizeof(int) <= sizeof(T), "not big enough");
158 };
159
160 struct Base {
161 virtual void f() {}
162 };
163 struct Child : public Base {
164 virtual void f() override {}
165 };
166
167 typedef check<check<bool>> right_angle_brackets;
168
169 int a;
170 decltype(a) b;
171
172 typedef check<int> check_type;
173 check_type c;
174 check_type&& cr = static_cast<check_type&&>(c);
175
176 auto d = a;
177 auto l = [](){};
178 ]])
179
180 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
181 m4_if([$1], [], [],
182 [$1], [ext], [],
183 [$1], [noext], [],
184 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
185 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
186 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
187 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
188 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
189 AC_LANG_PUSH([C++])dnl
190 ac_success=no
191 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
192 ax_cv_cxx_compile_cxx11,
193 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
194 [ax_cv_cxx_compile_cxx11=yes],
195 [ax_cv_cxx_compile_cxx11=no])])
196 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
197 ac_success=yes
198 fi
199
200 m4_if([$1], [noext], [], [dnl
201 if test x$ac_success = xno; then
202 for switch in -std=gnu++11 -std=gnu++0x; do
203 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
204 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
205 $cachevar,
206 [ac_save_CXXFLAGS="$CXXFLAGS"
207 CXXFLAGS="$CXXFLAGS $switch"
208 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
209 [eval $cachevar=yes],
210 [eval $cachevar=no])
211 CXXFLAGS="$ac_save_CXXFLAGS"])
212 if eval test x\$$cachevar = xyes; then
213 CXXFLAGS="$CXXFLAGS $switch"
214 ac_success=yes
215 break
216 fi
217 done
218 fi])
219
220 m4_if([$1], [ext], [], [dnl
221 if test x$ac_success = xno; then
222 for switch in -std=c++11 -std=c++0x; do
223 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
224 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
225 $cachevar,
226 [ac_save_CXXFLAGS="$CXXFLAGS"
227 CXXFLAGS="$CXXFLAGS $switch"
228 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
229 [eval $cachevar=yes],
230 [eval $cachevar=no])
231 CXXFLAGS="$ac_save_CXXFLAGS"])
232 if eval test x\$$cachevar = xyes; then
233 CXXFLAGS="$CXXFLAGS $switch"
234 ac_success=yes
235 break
236 fi
237 done
238 fi])
239 AC_LANG_POP([C++])
240 if test x$ax_cxx_compile_cxx11_required = xtrue; then
241 if test x$ac_success = xno; then
242 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
243 fi
244 else
245 if test x$ac_success = xno; then
246 HAVE_CXX11=0
247 AC_MSG_NOTICE([No compiler with C++11 support was found])
248 else
249 HAVE_CXX11=1
250 AC_DEFINE(HAVE_CXX11,1,
251 [define if the compiler supports basic C++11 syntax])
252 fi
253
254 AC_SUBST(HAVE_CXX11)
255 fi
256 ])
257