1# ============================================================================ 2# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html 3# ============================================================================ 4# 5# SYNOPSIS 6# 7# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional]) 8# 9# DESCRIPTION 10# 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# 14# The first argument, if specified, indicates whether you insist on an 15# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. 16# -std=c++11). If neither is specified, you get whatever works, with 17# preference for an extended mode. 18# 19# The second argument, if specified 'mandatory' or if left unspecified, 20# indicates that baseline C++11 support is required and that the macro 21# should error out if no mode with that support is found. If specified 22# 'optional', then configuration proceeds regardless, after defining 23# HAVE_CXX11 if and only if a supporting mode is found. 24# 25# LICENSE 26# 27# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com> 28# Copyright (c) 2012 Zack Weinberg <zackw@panix.com> 29# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu> 30# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com> 31# 32# Copying and distribution of this file, with or without modification, are 33# permitted in any medium without royalty provided the copyright notice 34# and this notice are preserved. This file is offered as-is, without any 35# warranty. 36 37#serial 9 38 39m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[ 40 template <typename T> 41 struct check 42 { 43 static_assert(sizeof(int) <= sizeof(T), "not big enough"); 44 }; 45 46 struct Base { 47 virtual void f() {} 48 }; 49 struct Child : public Base { 50 virtual void f() override {} 51 }; 52 53 typedef check<check<bool>> right_angle_brackets; 54 55 int a; 56 decltype(a) b; 57 58 typedef check<int> check_type; 59 check_type c; 60 check_type&& cr = static_cast<check_type&&>(c); 61 62 auto d = a; 63 auto l = [](){}; 64 65 // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae 66 // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this 67 namespace test_template_alias_sfinae { 68 struct foo {}; 69 70 template<typename T> 71 using member = typename T::member_type; 72 73 template<typename T> 74 void func(...) {} 75 76 template<typename T> 77 void func(member<T>*) {} 78 79 void test(); 80 81 void test() { 82 func<foo>(0); 83 } 84 } 85]]) 86 87AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl 88 m4_if([$1], [], [], 89 [$1], [ext], [], 90 [$1], [noext], [], 91 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl 92 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], 93 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], 94 [$2], [optional], [ax_cxx_compile_cxx11_required=false], 95 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])]) 96 AC_LANG_PUSH([C++])dnl 97 ac_success=no 98 AC_CACHE_CHECK(whether $CXX supports C++11 features by default, 99 ax_cv_cxx_compile_cxx11, 100 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], 101 [ax_cv_cxx_compile_cxx11=yes], 102 [ax_cv_cxx_compile_cxx11=no])]) 103 if test x$ax_cv_cxx_compile_cxx11 = xyes; then 104 ac_success=yes 105 fi 106 107 m4_if([$1], [noext], [], [dnl 108 if test x$ac_success = xno; then 109 for switch in -std=gnu++11 -std=gnu++0x; do 110 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) 111 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, 112 $cachevar, 113 [ac_save_CXXFLAGS="$CXXFLAGS" 114 CXXFLAGS="$CXXFLAGS $switch" 115 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], 116 [eval $cachevar=yes], 117 [eval $cachevar=no]) 118 CXXFLAGS="$ac_save_CXXFLAGS"]) 119 if eval test x\$$cachevar = xyes; then 120 CXXFLAGS="$CXXFLAGS $switch" 121 ac_success=yes 122 break 123 fi 124 done 125 fi]) 126 127 m4_if([$1], [ext], [], [dnl 128 if test x$ac_success = xno; then 129 for switch in -std=c++11 -std=c++0x; do 130 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) 131 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, 132 $cachevar, 133 [ac_save_CXXFLAGS="$CXXFLAGS" 134 CXXFLAGS="$CXXFLAGS $switch" 135 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], 136 [eval $cachevar=yes], 137 [eval $cachevar=no]) 138 CXXFLAGS="$ac_save_CXXFLAGS"]) 139 if eval test x\$$cachevar = xyes; then 140 CXXFLAGS="$CXXFLAGS $switch" 141 ac_success=yes 142 break 143 fi 144 done 145 fi]) 146 AC_LANG_POP([C++]) 147 if test x$ax_cxx_compile_cxx11_required = xtrue; then 148 if test x$ac_success = xno; then 149 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) 150 fi 151 else 152 if test x$ac_success = xno; then 153 HAVE_CXX11=0 154 AC_MSG_NOTICE([No compiler with C++11 support was found]) 155 else 156 HAVE_CXX11=1 157 AC_DEFINE(HAVE_CXX11,1, 158 [define if the compiler supports basic C++11 syntax]) 159 fi 160 161 AC_SUBST(HAVE_CXX11) 162 fi 163]) 164