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