Debian Codegraph @

m4/ax_cxx_compile_stdcxx_11.m4

raw
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 #
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 4
38
39 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
40 #include <memory>
41
42 template <typename T>
43 struct check
44 {
45 static_assert(sizeof(int) <= sizeof(T), "not big enough");
46 };
47
48 struct Base {
49 virtual void f() {}
50 };
51 struct Child : public Base {
52 virtual void f() override {}
53 };
54
55 std::unique_ptr<Base> ptr_to_base;
56
57 typedef check<check<bool>> right_angle_brackets;
58
59 int a;
60 decltype(a) b;
61
62 typedef check<int> check_type;
63 check_type c;
64 check_type&& cr = static_cast<check_type&&>(c);
65
66 auto d = a;
67 auto l = [](){};
68 ]])
69
70 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
71 m4_if([$1], [], [],
72 [$1], [ext], [],
73 [$1], [noext], [],
74 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
75 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
76 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
77 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
78 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
79 AC_LANG_PUSH([C++])dnl
80 ac_success=no
81 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
82 ax_cv_cxx_compile_cxx11,
83 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
84 [ax_cv_cxx_compile_cxx11=yes],
85 [ax_cv_cxx_compile_cxx11=no])])
86 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
87 ac_success=yes
88 fi
89
90 m4_if([$1], [noext], [], [dnl
91 if test x$ac_success = xno; then
92 for switch in -std=gnu++11 -std=gnu++0x; do
93 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
94 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
95 $cachevar,
96 [ac_save_CXXFLAGS="$CXXFLAGS"
97 CXXFLAGS="$CXXFLAGS $switch"
98 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
99 [eval $cachevar=yes],
100 [eval $cachevar=no])
101 CXXFLAGS="$ac_save_CXXFLAGS"])
102 if eval test x\$$cachevar = xyes; then
103 CXXFLAGS="$CXXFLAGS $switch"
104 ac_success=yes
105 break
106 fi
107 done
108 fi])
109
110 m4_if([$1], [ext], [], [dnl
111 if test x$ac_success = xno; then
112 for switch in -std=c++11 -std=c++0x; do
113 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
114 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
115 $cachevar,
116 [ac_save_CXXFLAGS="$CXXFLAGS"
117 CXXFLAGS="$CXXFLAGS $switch"
118 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
119 [eval $cachevar=yes],
120 [eval $cachevar=no])
121 CXXFLAGS="$ac_save_CXXFLAGS"])
122 if eval test x\$$cachevar = xyes; then
123 CXXFLAGS="$CXXFLAGS $switch"
124 ac_success=yes
125 break
126 fi
127 done
128 fi])
129 AC_LANG_POP([C++])
130 if test x$ax_cxx_compile_cxx11_required = xtrue; then
131 if test x$ac_success = xno; then
132 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
133 fi
134 else
135 if test x$ac_success = xno; then
136 HAVE_CXX11=0
137 AC_MSG_NOTICE([No compiler with C++11 support was found])
138 else
139 HAVE_CXX11=1
140 AC_DEFINE(HAVE_CXX11,1,
141 [define if the compiler supports basic C++11 syntax])
142 fi
143
144 AC_SUBST(HAVE_CXX11)
145 fi
146 ])