Jeff Thompson | dc2c430 | 2013-11-22 12:04:16 -0800 | [diff] [blame] | 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 | # |
| 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 | |
| 38 | m4_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 | typedef check<check<bool>> right_angle_brackets; |
| 46 | |
| 47 | int a; |
| 48 | decltype(a) b; |
| 49 | |
| 50 | typedef check<int> check_type; |
| 51 | check_type c; |
| 52 | check_type&& cr = static_cast<check_type&&>(c); |
| 53 | |
| 54 | auto d = a; |
| 55 | ]) |
| 56 | |
| 57 | AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl |
Alexander Afanasyev | 0541cf4 | 2014-01-02 19:10:37 -0800 | [diff] [blame] | 58 | AC_ARG_WITH([c++11], |
| 59 | AS_HELP_STRING( |
| 60 | [--with-c++11=@<:@ARG@:>@], |
Alexander Afanasyev | 9e92bfd | 2014-01-24 12:23:33 -0800 | [diff] [blame^] | 61 | [use C++11 when available @<:@default=no@:>@] |
Alexander Afanasyev | 0541cf4 | 2014-01-02 19:10:37 -0800 | [diff] [blame] | 62 | ), |
| 63 | [ |
Alexander Afanasyev | 9e92bfd | 2014-01-24 12:23:33 -0800 | [diff] [blame^] | 64 | if test "$withval" = "yes"; then |
| 65 | WANT_CXX11="yes" |
Jeff Thompson | dc2c430 | 2013-11-22 12:04:16 -0800 | [diff] [blame] | 66 | fi |
Alexander Afanasyev | 0541cf4 | 2014-01-02 19:10:37 -0800 | [diff] [blame] | 67 | ], |
Alexander Afanasyev | 9e92bfd | 2014-01-24 12:23:33 -0800 | [diff] [blame^] | 68 | [WANT_CXX11="no"] |
Alexander Afanasyev | 0541cf4 | 2014-01-02 19:10:37 -0800 | [diff] [blame] | 69 | ) |
| 70 | |
| 71 | if test "x$WANT_CXX11" = "xyes"; then |
| 72 | m4_if([$1], [], [], |
| 73 | [$1], [ext], [], |
| 74 | [$1], [noext], [], |
| 75 | [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl |
| 76 | m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], |
| 77 | [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], |
| 78 | [$2], [optional], [ax_cxx_compile_cxx11_required=false], |
| 79 | [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])dnl |
| 80 | AC_LANG_PUSH([C++])dnl |
| 81 | ac_success=no |
| 82 | AC_CACHE_CHECK(whether $CXX supports C++11 features by default, |
| 83 | ax_cv_cxx_compile_cxx11, |
| 84 | [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], |
| 85 | [ax_cv_cxx_compile_cxx11=yes], |
| 86 | [ax_cv_cxx_compile_cxx11=no])]) |
| 87 | if test x$ax_cv_cxx_compile_cxx11 = xyes; then |
| 88 | ac_success=yes |
| 89 | fi |
| 90 | |
| 91 | m4_if([$1], [noext], [], [dnl |
Jeff Thompson | dc2c430 | 2013-11-22 12:04:16 -0800 | [diff] [blame] | 92 | if test x$ac_success = xno; then |
Alexander Afanasyev | 0541cf4 | 2014-01-02 19:10:37 -0800 | [diff] [blame] | 93 | for switch in -std=gnu++11 -std=gnu++0x; do |
| 94 | cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) |
| 95 | AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, |
| 96 | $cachevar, |
| 97 | [ac_save_CXXFLAGS="$CXXFLAGS" |
| 98 | CXXFLAGS="$CXXFLAGS $switch" |
| 99 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], |
| 100 | [eval $cachevar=yes], |
| 101 | [eval $cachevar=no]) |
| 102 | CXXFLAGS="$ac_save_CXXFLAGS"]) |
| 103 | if eval test x\$$cachevar = xyes; then |
| 104 | CXXFLAGS="$CXXFLAGS $switch" |
| 105 | ac_success=yes |
| 106 | break |
| 107 | fi |
| 108 | done |
| 109 | fi]) |
| 110 | |
| 111 | m4_if([$1], [ext], [], [dnl |
| 112 | if test x$ac_success = xno; then |
| 113 | for switch in -std=c++11 -std=c++0x; do |
| 114 | cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) |
| 115 | AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, |
| 116 | $cachevar, |
| 117 | [ac_save_CXXFLAGS="$CXXFLAGS" |
| 118 | CXXFLAGS="$CXXFLAGS $switch" |
| 119 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], |
| 120 | [eval $cachevar=yes], |
| 121 | [eval $cachevar=no]) |
| 122 | CXXFLAGS="$ac_save_CXXFLAGS"]) |
| 123 | if eval test x\$$cachevar = xyes; then |
| 124 | CXXFLAGS="$CXXFLAGS $switch" |
| 125 | ac_success=yes |
| 126 | break |
| 127 | fi |
| 128 | done |
| 129 | fi]) |
| 130 | AC_LANG_POP([C++]) |
| 131 | if test x$ax_cxx_compile_cxx11_required = xtrue; then |
| 132 | if test x$ac_success = xno; then |
| 133 | AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) |
| 134 | fi |
Jeff Thompson | dc2c430 | 2013-11-22 12:04:16 -0800 | [diff] [blame] | 135 | else |
Alexander Afanasyev | 0541cf4 | 2014-01-02 19:10:37 -0800 | [diff] [blame] | 136 | if test x$ac_success = xno; then |
| 137 | HAVE_CXX11=0 |
| 138 | AC_MSG_NOTICE([No compiler with C++11 support was found]) |
| 139 | else |
| 140 | HAVE_CXX11=1 |
| 141 | AC_DEFINE(HAVE_CXX11,1, |
| 142 | [define if the compiler supports basic C++11 syntax]) |
| 143 | fi |
| 144 | |
| 145 | AC_SUBST(HAVE_CXX11) |
Jeff Thompson | dc2c430 | 2013-11-22 12:04:16 -0800 | [diff] [blame] | 146 | fi |
Jeff Thompson | dc2c430 | 2013-11-22 12:04:16 -0800 | [diff] [blame] | 147 | fi |
| 148 | ]) |