1 # ============================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
3 # ============================================================================
7 # AX_CXX_COMPILE_STDCXX_11([ext|noext])
11 # Check for baseline language coverage in the compiler for the C++11
12 # standard; if necessary, add switches to CXXFLAGS to enable support.
13 # Errors out if no mode that supports C++11 baseline syntax can be found.
14 # The argument, if specified, indicates whether you insist on an extended
15 # mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -std=c++11).
16 # If neither is specified, you get whatever works, with preference for an
21 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
22 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
24 # Copying and distribution of this file, with or without modification, are
25 # permitted in any medium without royalty provided the copyright notice
26 # and this notice are preserved. This file is offered as-is, without any
31 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
35 static_assert(sizeof(int) <= sizeof(T), "not big enough");
38 typedef check<check<bool>> right_angle_brackets;
43 typedef check<int> check_type;
45 check_type&& cr = static_cast<check_type&&>(c);
48 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
52 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
53 AC_LANG_ASSERT([C++])dnl
55 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
56 ax_cv_cxx_compile_cxx11,
57 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
58 [ax_cv_cxx_compile_cxx11=yes],
59 [ax_cv_cxx_compile_cxx11=no])])
60 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
64 m4_if([$1], [noext], [], [dnl
65 if test x$ac_success = xno; then
66 for switch in -std=gnu++11 -std=gnu++0x; do
67 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
68 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
70 [ac_save_CXXFLAGS="$CXXFLAGS"
71 CXXFLAGS="$CXXFLAGS $switch"
72 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
75 CXXFLAGS="$ac_save_CXXFLAGS"])
76 if eval test x\$$cachevar = xyes; then
77 CXXFLAGS="$CXXFLAGS $switch"
84 m4_if([$1], [ext], [], [dnl
85 if test x$ac_success = xno; then
86 for switch in -std=c++11 -std=c++0x; do
87 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
88 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
90 [ac_save_CXXFLAGS="$CXXFLAGS"
91 CXXFLAGS="$CXXFLAGS $switch"
92 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
95 CXXFLAGS="$ac_save_CXXFLAGS"])
96 if eval test x\$$cachevar = xyes; then
97 CXXFLAGS="$CXXFLAGS $switch"
104 if test x$ac_success = xno; then
105 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])