]> git.ipfire.org Git - thirdparty/squid.git/blame - acinclude/ax_cxx_compile_stdcxx_11.m4
SourceFormat Enforcement
[thirdparty/squid.git] / acinclude / ax_cxx_compile_stdcxx_11.m4
CommitLineData
4ac4a490 1## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
5d2e6f19
AJ
2##
3## Squid software is distributed under GPLv2+ license and includes
4## contributions from numerous individuals and organizations.
5## Please see the COPYING and CONTRIBUTORS files for details.
6##
7
ea1cf567
AJ
8# ============================================================================
9# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
10# ============================================================================
11#
12# SYNOPSIS
13#
14# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
15#
16# DESCRIPTION
17#
18# Check for baseline language coverage in the compiler for the C++11
19# standard; if necessary, add switches to CXXFLAGS to enable support.
20#
21# The first argument, if specified, indicates whether you insist on an
22# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
23# -std=c++11). If neither is specified, you get whatever works, with
24# preference for an extended mode.
25#
26# The second argument, if specified 'mandatory' or if left unspecified,
27# indicates that baseline C++11 support is required and that the macro
28# should error out if no mode with that support is found. If specified
29# 'optional', then configuration proceeds regardless, after defining
30# HAVE_CXX11 if and only if a supporting mode is found.
31#
32# LICENSE
33#
34# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
35# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
36# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
37# Copyright (c) 2014 Alexey Sokolov <sokolov@google.com>
38#
39# Copying and distribution of this file, with or without modification, are
40# permitted in any medium without royalty provided the copyright notice
41# and this notice are preserved. This file is offered as-is, without any
42# warranty.
43
44#serial 4
45
46m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
e4dffe5a 47 template <typename T>
ea1cf567
AJ
48 struct check
49 {
e4dffe5a 50 static_assert(sizeof(int) <= sizeof(T), "not big enough"); // GCC 4.3+
ea1cf567
AJ
51 };
52
e4dffe5a 53#if WHEN_SQUID_HAS_MANDATORY_GCC_4_789_SUPPORT
ea1cf567
AJ
54 struct Base {
55 virtual void f() {}
56 };
57 struct Child : public Base {
e4dffe5a 58 virtual void f() override {} // GCC 4.7+
ea1cf567 59 };
e4dffe5a 60#endif
ea1cf567 61
e4dffe5a 62 typedef check<check<bool>> right_angle_brackets; // GCC 4.3+
ea1cf567
AJ
63
64 int a;
e4dffe5a 65 decltype(a) b; // GCC 4.3+
ea1cf567
AJ
66
67 typedef check<int> check_type;
68 check_type c;
e4dffe5a 69 check_type&& cr = static_cast<check_type&&>(c); // GCC 4.3+
ea1cf567 70
e4dffe5a
AJ
71 auto d = a; // GCC 4.4+
72#if WHEN_SQUID_HAS_MANDATORY_GCC_4_789_SUPPORT
73 auto l = [](){}; // GCC 4.5+ (void lambda seems not to be documented)
74#endif
ea1cf567
AJ
75]])
76
77AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
78 m4_if([$1], [], [],
79 [$1], [ext], [],
80 [$1], [noext], [],
81 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
82 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
83 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
84 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
85 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
86 AC_LANG_PUSH([C++])dnl
87 ac_success=no
88 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
89 ax_cv_cxx_compile_cxx11,
90 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
91 [ax_cv_cxx_compile_cxx11=yes],
92 [ax_cv_cxx_compile_cxx11=no])])
93 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
94 ac_success=yes
95 fi
96
97 m4_if([$1], [noext], [], [dnl
98 if test x$ac_success = xno; then
99 for switch in -std=gnu++11 -std=gnu++0x; do
100 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
101 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
102 $cachevar,
103 [ac_save_CXXFLAGS="$CXXFLAGS"
104 CXXFLAGS="$CXXFLAGS $switch"
105 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
106 [eval $cachevar=yes],
107 [eval $cachevar=no])
108 CXXFLAGS="$ac_save_CXXFLAGS"])
109 if eval test x\$$cachevar = xyes; then
110 CXXFLAGS="$CXXFLAGS $switch"
111 ac_success=yes
112 break
113 fi
114 done
115 fi])
116
117 m4_if([$1], [ext], [], [dnl
118 if test x$ac_success = xno; then
119 for switch in -std=c++11 -std=c++0x; do
120 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
121 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
122 $cachevar,
123 [ac_save_CXXFLAGS="$CXXFLAGS"
124 CXXFLAGS="$CXXFLAGS $switch"
125 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
126 [eval $cachevar=yes],
127 [eval $cachevar=no])
128 CXXFLAGS="$ac_save_CXXFLAGS"])
129 if eval test x\$$cachevar = xyes; then
130 CXXFLAGS="$CXXFLAGS $switch"
131 ac_success=yes
132 break
133 fi
134 done
135 fi])
136 AC_LANG_POP([C++])
137 if test x$ax_cxx_compile_cxx11_required = xtrue; then
138 if test x$ac_success = xno; then
139 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
140 fi
141 else
142 if test x$ac_success = xno; then
143 HAVE_CXX11=0
144 AC_MSG_NOTICE([No compiler with C++11 support was found])
145 else
146 HAVE_CXX11=1
147 AC_DEFINE(HAVE_CXX11,1,
148 [define if the compiler supports basic C++11 syntax])
149 fi
150
151 AC_SUBST(HAVE_CXX11)
152 fi
153])