| 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 <[email protected]> |
| 28 |
# Copyright (c) 2012 Zack Weinberg <[email protected]> |
| 29 |
# Copyright (c) 2013 Roy Stogner <[email protected]> |
| 30 |
# Copyright (c) 2014 Alexey Sokolov <[email protected]> |
| 31 |
# Copyright (c) 2014, 2015 Google Inc. |
| 32 |
# |
| 33 |
# Copying and distribution of this file, with or without modification, are |
| 34 |
# permitted in any medium without royalty provided the copyright notice |
| 35 |
# and this notice are preserved. This file is offered as-is, without any |
| 36 |
# warranty. |
| 37 |
|
| 38 |
#serial 7 |
| 39 |
|
| 40 |
m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[ |
| 41 |
template <typename T> |
| 42 |
struct check |
| 43 |
{ |
| 44 |
static_assert(sizeof(int) <= sizeof(T), "not big enough"); |
| 45 |
}; |
| 46 |
|
| 47 |
struct Base { |
| 48 |
virtual void f() {} |
| 49 |
}; |
| 50 |
struct Child : public Base { |
| 51 |
virtual void f() override {} |
| 52 |
}; |
| 53 |
|
| 54 |
typedef check<check<bool>> right_angle_brackets; |
| 55 |
|
| 56 |
int a; |
| 57 |
decltype(a) b; |
| 58 |
|
| 59 |
typedef check<int> check_type; |
| 60 |
check_type c; |
| 61 |
check_type&& cr = static_cast<check_type&&>(c); |
| 62 |
|
| 63 |
auto d = a; |
| 64 |
auto l = [](){}; |
| 65 |
|
| 66 |
// http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae |
| 67 |
// Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this |
| 68 |
namespace test_template_alias_sfinae { |
| 69 |
struct foo {}; |
| 70 |
|
| 71 |
template<typename T> |
| 72 |
using member = typename T::member_type; |
| 73 |
|
| 74 |
template<typename T> |
| 75 |
void func(...) {} |
| 76 |
|
| 77 |
template<typename T> |
| 78 |
void func(member<T>*) {} |
| 79 |
|
| 80 |
void test() { |
| 81 |
func<foo>(0); |
| 82 |
} |
| 83 |
} |
| 84 |
]]) |
| 85 |
|
| 86 |
AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl |
| 87 |
m4_if([$1], [], [], |
| 88 |
[$1], [ext], [], |
| 89 |
[$1], [noext], [], |
| 90 |
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl |
| 91 |
m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], |
| 92 |
[$2], [mandatory], [ax_cxx_compile_cxx11_required=true], |
| 93 |
[$2], [optional], [ax_cxx_compile_cxx11_required=false], |
| 94 |
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])]) |
| 95 |
AC_LANG_PUSH([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_CXXFLAGS="$CXXFLAGS" |
| 113 |
CXXFLAGS="$CXXFLAGS $switch" |
| 114 |
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], |
| 115 |
[eval $cachevar=yes], |
| 116 |
[eval $cachevar=no]) |
| 117 |
CXXFLAGS="$ac_save_CXXFLAGS"]) |
| 118 |
if eval test x\$$cachevar = xyes; then |
| 119 |
CXXFLAGS="$CXXFLAGS $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_CXXFLAGS="$CXXFLAGS" |
| 133 |
CXXFLAGS="$CXXFLAGS $switch" |
| 134 |
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], |
| 135 |
[eval $cachevar=yes], |
| 136 |
[eval $cachevar=no]) |
| 137 |
CXXFLAGS="$ac_save_CXXFLAGS"]) |
| 138 |
if eval test x\$$cachevar = xyes; then |
| 139 |
CXXFLAGS="$CXXFLAGS $switch" |
| 140 |
ac_success=yes |
| 141 |
break |
| 142 |
fi |
| 143 |
done |
| 144 |
fi]) |
| 145 |
AC_LANG_POP([C++]) |
| 146 |
if test x$ax_cxx_compile_cxx11_required = xtrue; then |
| 147 |
if test x$ac_success = xno; then |
| 148 |
AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) |
| 149 |
fi |
| 150 |
else |
| 151 |
if test x$ac_success = xno; then |
| 152 |
HAVE_CXX11=0 |
| 153 |
AC_MSG_NOTICE([No compiler with C++11 support was found]) |
| 154 |
else |
| 155 |
HAVE_CXX11=1 |
| 156 |
AC_DEFINE(HAVE_CXX11,1, |
| 157 |
[define if the compiler supports basic C++11 syntax]) |
| 158 |
fi |
| 159 |
|
| 160 |
AC_SUBST(HAVE_CXX11) |
| 161 |
fi |
| 162 |
]) |