blob: f3e5fce81bc8947d8b652eeca45d543ad72830d7 [file] [log] [blame]
Austin Schuh24adb6b2015-09-06 17:37:40 -07001# ============================================================================
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#
31# Copying and distribution of this file, with or without modification, are
32# permitted in any medium without royalty provided the copyright notice
33# and this notice are preserved. This file is offered as-is, without any
34# warranty.
35
36#serial 3
37
38m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
39 template <typename T>
40 struct check
41 {
42 static_assert(sizeof(int) <= sizeof(T), "not big enough");
43 };
44
45 struct base { virtual void func() = 0; };
46 struct override : base { virtual void func() override {}; };
47
48 typedef check<check<bool>> right_angle_brackets;
49
50 int a;
51 decltype(a) b;
52
53 typedef check<int> check_type;
54 check_type c;
55 check_type&& cr = static_cast<check_type&&>(c);
56
57 auto d = a;
58])
59
60AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
61 m4_if([$1], [], [],
62 [$1], [ext], [],
63 [$1], [noext], [],
64 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])
65 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
66 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
67 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
68 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
69 AC_LANG_PUSH([C++])
70 ac_success=no
71 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
72 ax_cv_cxx_compile_cxx11,
73 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
74 [ax_cv_cxx_compile_cxx11=yes],
75 [ax_cv_cxx_compile_cxx11=no])])
76 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
77 ac_success=yes
78 fi
79
80 m4_if([$1], [noext], [], [dnl
81 if test x$ac_success = xno; then
82 for switch in -std=gnu++11 -std=gnu++0x; do
83 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
84 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
85 $cachevar,
86 [ac_save_CXXFLAGS="$CXXFLAGS"
87 CXXFLAGS="$CXXFLAGS $switch"
88 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
89 [eval $cachevar=yes],
90 [eval $cachevar=no])
91 CXXFLAGS="$ac_save_CXXFLAGS"])
92 if eval test x\$$cachevar = xyes; then
93 CXXFLAGS="$CXXFLAGS $switch"
94 ac_success=yes
95 break
96 fi
97 done
98 fi])
99
100 m4_if([$1], [ext], [], [dnl
101 if test x$ac_success = xno; then
102 for switch in -std=c++11 -std=c++0x; do
103 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
104 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
105 $cachevar,
106 [ac_save_CXXFLAGS="$CXXFLAGS"
107 CXXFLAGS="$CXXFLAGS $switch"
108 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
109 [eval $cachevar=yes],
110 [eval $cachevar=no])
111 CXXFLAGS="$ac_save_CXXFLAGS"])
112 if eval test x\$$cachevar = xyes; then
113 CXXFLAGS="$CXXFLAGS $switch"
114 ac_success=yes
115 break
116 fi
117 done
118 fi])
119 AC_LANG_POP([C++])
120 if test x$ax_cxx_compile_cxx11_required = xtrue; then
121 if test x$ac_success = xno; then
122 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
123 fi
124 else
125 if test x$ac_success = xno; then
126 HAVE_CXX11=0
127 AC_MSG_NOTICE([No compiler with C++11 support was found])
128 else
129 HAVE_CXX11=1
130 AC_DEFINE(HAVE_CXX11,1,
131 [define if the compiler supports basic C++11 syntax])
132 fi
133
134 AC_SUBST(HAVE_CXX11)
135 fi
136])