Mercurial > hg > vamp-plugin-sdk
comparison acinclude.m4 @ 526:459cddd7e64a c++11-mutex
Switch from C++98 to C++11
author | Chris Cannam |
---|---|
date | Wed, 11 Sep 2019 14:30:14 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
525:8c18bdaad04f | 526:459cddd7e64a |
---|---|
1 | |
2 # From autoconf archive: | |
3 | |
4 # ============================================================================ | |
5 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html | |
6 # ============================================================================ | |
7 # | |
8 # SYNOPSIS | |
9 # | |
10 # AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional]) | |
11 # | |
12 # DESCRIPTION | |
13 # | |
14 # Check for baseline language coverage in the compiler for the C++11 | |
15 # standard; if necessary, add switches to CXXFLAGS to enable support. | |
16 # | |
17 # The first argument, if specified, indicates whether you insist on an | |
18 # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. | |
19 # -std=c++11). If neither is specified, you get whatever works, with | |
20 # preference for an extended mode. | |
21 # | |
22 # The second argument, if specified 'mandatory' or if left unspecified, | |
23 # indicates that baseline C++11 support is required and that the macro | |
24 # should error out if no mode with that support is found. If specified | |
25 # 'optional', then configuration proceeds regardless, after defining | |
26 # HAVE_CXX11 if and only if a supporting mode is found. | |
27 # | |
28 # LICENSE | |
29 # | |
30 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com> | |
31 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com> | |
32 # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu> | |
33 # Copyright (c) 2014 Alexey Sokolov <sokolov@google.com> | |
34 # | |
35 # Copying and distribution of this file, with or without modification, are | |
36 # permitted in any medium without royalty provided the copyright notice | |
37 # and this notice are preserved. This file is offered as-is, without any | |
38 # warranty. | |
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 | |
67 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl | |
68 m4_if([$1], [], [], | |
69 [$1], [ext], [], | |
70 [$1], [noext], [], | |
71 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl | |
72 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], | |
73 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], | |
74 [$2], [optional], [ax_cxx_compile_cxx11_required=false], | |
75 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])]) | |
76 AC_LANG_PUSH([C++])dnl | |
77 ac_success=no | |
78 AC_CACHE_CHECK(whether $CXX supports C++11 features by default, | |
79 ax_cv_cxx_compile_cxx11, | |
80 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], | |
81 [ax_cv_cxx_compile_cxx11=yes], | |
82 [ax_cv_cxx_compile_cxx11=no])]) | |
83 if test x$ax_cv_cxx_compile_cxx11 = xyes; then | |
84 ac_success=yes | |
85 fi | |
86 | |
87 m4_if([$1], [noext], [], [dnl | |
88 if test x$ac_success = xno; then | |
89 for switch in -std=gnu++11 -std=gnu++0x; do | |
90 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) | |
91 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, | |
92 $cachevar, | |
93 [ac_save_CXXFLAGS="$CXXFLAGS" | |
94 CXXFLAGS="$CXXFLAGS $switch" | |
95 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], | |
96 [eval $cachevar=yes], | |
97 [eval $cachevar=no]) | |
98 CXXFLAGS="$ac_save_CXXFLAGS"]) | |
99 if eval test x\$$cachevar = xyes; then | |
100 CXXFLAGS="$CXXFLAGS $switch" | |
101 ac_success=yes | |
102 break | |
103 fi | |
104 done | |
105 fi]) | |
106 | |
107 m4_if([$1], [ext], [], [dnl | |
108 if test x$ac_success = xno; then | |
109 for switch in -std=c++11 -std=c++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 AC_LANG_POP([C++]) | |
127 if test x$ax_cxx_compile_cxx11_required = xtrue; then | |
128 if test x$ac_success = xno; then | |
129 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) | |
130 fi | |
131 else | |
132 if test x$ac_success = xno; then | |
133 HAVE_CXX11=0 | |
134 AC_MSG_NOTICE([No compiler with C++11 support was found]) | |
135 else | |
136 HAVE_CXX11=1 | |
137 AC_DEFINE(HAVE_CXX11,1, | |
138 [define if the compiler supports basic C++11 syntax]) | |
139 fi | |
140 | |
141 AC_SUBST(HAVE_CXX11) | |
142 fi | |
143 ]) |