Chris@526: Chris@526: # From autoconf archive: Chris@526: Chris@526: # ============================================================================ Chris@526: # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html Chris@526: # ============================================================================ Chris@526: # Chris@526: # SYNOPSIS Chris@526: # Chris@526: # AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional]) Chris@526: # Chris@526: # DESCRIPTION Chris@526: # Chris@526: # Check for baseline language coverage in the compiler for the C++11 Chris@526: # standard; if necessary, add switches to CXXFLAGS to enable support. Chris@526: # Chris@526: # The first argument, if specified, indicates whether you insist on an Chris@526: # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. Chris@526: # -std=c++11). If neither is specified, you get whatever works, with Chris@526: # preference for an extended mode. Chris@526: # Chris@526: # The second argument, if specified 'mandatory' or if left unspecified, Chris@526: # indicates that baseline C++11 support is required and that the macro Chris@526: # should error out if no mode with that support is found. If specified Chris@526: # 'optional', then configuration proceeds regardless, after defining Chris@526: # HAVE_CXX11 if and only if a supporting mode is found. Chris@526: # Chris@526: # LICENSE Chris@526: # Chris@526: # Copyright (c) 2008 Benjamin Kosnik Chris@526: # Copyright (c) 2012 Zack Weinberg Chris@526: # Copyright (c) 2013 Roy Stogner Chris@526: # Copyright (c) 2014 Alexey Sokolov Chris@526: # Chris@526: # Copying and distribution of this file, with or without modification, are Chris@526: # permitted in any medium without royalty provided the copyright notice Chris@526: # and this notice are preserved. This file is offered as-is, without any Chris@526: # warranty. Chris@526: Chris@526: m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[ Chris@526: template Chris@526: struct check Chris@526: { Chris@526: static_assert(sizeof(int) <= sizeof(T), "not big enough"); Chris@526: }; Chris@526: Chris@526: struct Base { Chris@526: virtual void f() {} Chris@526: }; Chris@526: struct Child : public Base { Chris@526: virtual void f() override {} Chris@526: }; Chris@526: Chris@526: typedef check> right_angle_brackets; Chris@526: Chris@526: int a; Chris@526: decltype(a) b; Chris@526: Chris@526: typedef check check_type; Chris@526: check_type c; Chris@526: check_type&& cr = static_cast(c); Chris@526: Chris@526: auto d = a; Chris@526: auto l = [](){}; Chris@526: ]]) Chris@526: Chris@526: AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl Chris@526: m4_if([$1], [], [], Chris@526: [$1], [ext], [], Chris@526: [$1], [noext], [], Chris@526: [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl Chris@526: m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], Chris@526: [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], Chris@526: [$2], [optional], [ax_cxx_compile_cxx11_required=false], Chris@526: [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])]) Chris@526: AC_LANG_PUSH([C++])dnl Chris@526: ac_success=no Chris@526: AC_CACHE_CHECK(whether $CXX supports C++11 features by default, Chris@526: ax_cv_cxx_compile_cxx11, Chris@526: [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], Chris@526: [ax_cv_cxx_compile_cxx11=yes], Chris@526: [ax_cv_cxx_compile_cxx11=no])]) Chris@526: if test x$ax_cv_cxx_compile_cxx11 = xyes; then Chris@526: ac_success=yes Chris@526: fi Chris@526: Chris@526: m4_if([$1], [noext], [], [dnl Chris@526: if test x$ac_success = xno; then Chris@526: for switch in -std=gnu++11 -std=gnu++0x; do Chris@526: cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) Chris@526: AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, Chris@526: $cachevar, Chris@526: [ac_save_CXXFLAGS="$CXXFLAGS" Chris@526: CXXFLAGS="$CXXFLAGS $switch" Chris@526: AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], Chris@526: [eval $cachevar=yes], Chris@526: [eval $cachevar=no]) Chris@526: CXXFLAGS="$ac_save_CXXFLAGS"]) Chris@526: if eval test x\$$cachevar = xyes; then Chris@526: CXXFLAGS="$CXXFLAGS $switch" Chris@526: ac_success=yes Chris@526: break Chris@526: fi Chris@526: done Chris@526: fi]) Chris@526: Chris@526: m4_if([$1], [ext], [], [dnl Chris@526: if test x$ac_success = xno; then Chris@526: for switch in -std=c++11 -std=c++0x; do Chris@526: cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) Chris@526: AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, Chris@526: $cachevar, Chris@526: [ac_save_CXXFLAGS="$CXXFLAGS" Chris@526: CXXFLAGS="$CXXFLAGS $switch" Chris@526: AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], Chris@526: [eval $cachevar=yes], Chris@526: [eval $cachevar=no]) Chris@526: CXXFLAGS="$ac_save_CXXFLAGS"]) Chris@526: if eval test x\$$cachevar = xyes; then Chris@526: CXXFLAGS="$CXXFLAGS $switch" Chris@526: ac_success=yes Chris@526: break Chris@526: fi Chris@526: done Chris@526: fi]) Chris@526: AC_LANG_POP([C++]) Chris@526: if test x$ax_cxx_compile_cxx11_required = xtrue; then Chris@526: if test x$ac_success = xno; then Chris@526: AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) Chris@526: fi Chris@526: else Chris@526: if test x$ac_success = xno; then Chris@526: HAVE_CXX11=0 Chris@526: AC_MSG_NOTICE([No compiler with C++11 support was found]) Chris@526: else Chris@526: HAVE_CXX11=1 Chris@526: AC_DEFINE(HAVE_CXX11,1, Chris@526: [define if the compiler supports basic C++11 syntax]) Chris@526: fi Chris@526: Chris@526: AC_SUBST(HAVE_CXX11) Chris@526: fi Chris@526: ])