cannam@133: # ============================================================================ cannam@133: # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html cannam@133: # Additionally modified to detect -stdlib by Kenton Varda. cannam@133: # ============================================================================ cannam@133: # cannam@133: # SYNOPSIS cannam@133: # cannam@133: # AX_CXX_COMPILE_STDCXX_11([ext|noext]) cannam@133: # cannam@133: # DESCRIPTION cannam@133: # cannam@133: # Check for baseline language coverage in the compiler for the C++11 cannam@133: # standard; if necessary, add switches to CXXFLAGS to enable support. cannam@133: # Errors out if no mode that supports C++11 baseline syntax can be found. cannam@133: # The argument, if specified, indicates whether you insist on an extended cannam@133: # mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -std=c++11). cannam@133: # If neither is specified, you get whatever works, with preference for an cannam@133: # extended mode. cannam@133: # cannam@133: # Additionally, check if the standard library supports C++11. If not, cannam@133: # try adding -stdlib=libc++ to see if that fixes it. This is needed e.g. cannam@133: # on Mac OSX 10.8, which ships with a very old libstdc++ but a relatively cannam@133: # new libc++. cannam@133: # cannam@133: # Both flags are actually added to CXX rather than CXXFLAGS to work around cannam@133: # a bug in libtool: -stdlib is stripped from CXXFLAGS when linking dynamic cannam@133: # libraries because it is not recognized. A patch was committed to mainline cannam@133: # libtool in February 2012 but as of June 2013 there has not yet been a cannam@133: # release containing this patch. cannam@133: # http://git.savannah.gnu.org/gitweb/?p=libtool.git;a=commit;h=c0c49f289f22ae670066657c60905986da3b555f cannam@133: # cannam@133: # LICENSE cannam@133: # cannam@133: # Copyright (c) 2008 Benjamin Kosnik cannam@133: # Copyright (c) 2012 Zack Weinberg cannam@133: # Copyright (c) 2013 Kenton Varda cannam@133: # cannam@133: # Copying and distribution of this file, with or without modification, are cannam@133: # permitted in any medium without royalty provided the copyright notice cannam@133: # and this notice are preserved. This file is offered as-is, without any cannam@133: # warranty. cannam@133: cannam@133: #serial 1 cannam@133: cannam@133: m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [ cannam@133: template cannam@133: struct check cannam@133: { cannam@133: static_assert(sizeof(int) <= sizeof(T), "not big enough"); cannam@133: }; cannam@133: cannam@133: typedef check> right_angle_brackets; cannam@133: cannam@133: int a; cannam@133: decltype(a) b; cannam@133: cannam@133: typedef check check_type; cannam@133: check_type c; cannam@133: check_type&& cr = static_cast(c); cannam@133: cannam@133: // GCC 4.7 introduced __float128 and makes reference to it in type_traits. cannam@133: // Clang doesn't implement it, so produces an error. Using -std=c++11 cannam@133: // instead of -std=gnu++11 works around the problem. But on some cannam@133: // platforms we need -std=gnu++11. So we want to make sure the test of cannam@133: // -std=gnu++11 fails only where this problem is present, and we hope that cannam@133: // -std=c++11 is always an acceptable fallback in these cases. Complicating cannam@133: // matters, though, is that we don't want to fail here if the platform is cannam@133: // completely missing a C++11 standard library, because we want to probe that cannam@133: // in a later test. It happens, though, that Clang allows us to check cannam@133: // whether a header exists at all before we include it. cannam@133: // cannam@133: // So, if we detect that __has_include is available (which it is on Clang), cannam@133: // and we use it to detect that (a C++11 header) exists, then cannam@133: // we go ahead and #include it to see if it breaks. In all other cases, we cannam@133: // don't #include it at all. cannam@133: #ifdef __has_include cannam@133: #if __has_include() cannam@133: #include cannam@133: #endif cannam@133: #endif cannam@133: ]) cannam@133: cannam@133: m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody_lib], [ cannam@133: #include cannam@133: #include cannam@133: #include cannam@133: #include cannam@133: ]) cannam@133: cannam@133: AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl cannam@133: m4_if([$1], [], [], cannam@133: [$1], [ext], [], cannam@133: [$1], [noext], [], cannam@133: [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl cannam@133: AC_LANG_ASSERT([C++])dnl cannam@133: ac_success=no cannam@133: AC_CACHE_CHECK(whether $CXX supports C++11 features by default, cannam@133: ax_cv_cxx_compile_cxx11, cannam@133: [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], cannam@133: [ax_cv_cxx_compile_cxx11=yes], cannam@133: [ax_cv_cxx_compile_cxx11=no])]) cannam@133: if test x$ax_cv_cxx_compile_cxx11 = xyes; then cannam@133: ac_success=yes cannam@133: fi cannam@133: cannam@133: m4_if([$1], [noext], [], [dnl cannam@133: if test x$ac_success = xno; then cannam@133: for switch in -std=gnu++11 -std=gnu++0x; do cannam@133: cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) cannam@133: AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, cannam@133: $cachevar, cannam@133: [ac_save_CXX="$CXX" cannam@133: CXX="$CXX $switch" cannam@133: AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], cannam@133: [eval $cachevar=yes], cannam@133: [eval $cachevar=no]) cannam@133: CXX="$ac_save_CXX"]) cannam@133: if eval test x\$$cachevar = xyes; then cannam@133: CXX="$CXX $switch" cannam@133: ac_success=yes cannam@133: break cannam@133: fi cannam@133: done cannam@133: fi]) cannam@133: cannam@133: m4_if([$1], [ext], [], [dnl cannam@133: if test x$ac_success = xno; then cannam@133: for switch in -std=c++11 -std=c++0x; do cannam@133: cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) cannam@133: AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, cannam@133: $cachevar, cannam@133: [ac_save_CXX="$CXX" cannam@133: CXX="$CXX $switch" cannam@133: AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], cannam@133: [eval $cachevar=yes], cannam@133: [eval $cachevar=no]) cannam@133: CXX="$ac_save_CXX"]) cannam@133: if eval test x\$$cachevar = xyes; then cannam@133: CXX="$CXX $switch" cannam@133: ac_success=yes cannam@133: break cannam@133: fi cannam@133: done cannam@133: fi]) cannam@133: cannam@133: if test x$ac_success = xno; then cannam@133: AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) cannam@133: else cannam@133: ac_success=no cannam@133: AC_CACHE_CHECK(whether $CXX supports C++11 library features by default, cannam@133: ax_cv_cxx_compile_cxx11_lib, cannam@133: [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody_lib])], cannam@133: [ax_cv_cxx_compile_cxx11_lib=yes], cannam@133: [ax_cv_cxx_compile_cxx11_lib=no]) cannam@133: ]) cannam@133: if test x$ax_cv_cxx_compile_cxx11_lib = xyes; then cannam@133: ac_success=yes cannam@133: else cannam@133: # Try with -stdlib=libc++ cannam@133: AC_CACHE_CHECK(whether $CXX supports C++11 library features with -stdlib=libc++, cannam@133: ax_cv_cxx_compile_cxx11_lib_libcxx, cannam@133: [ac_save_CXX="$CXX" cannam@133: CXX="$CXX -stdlib=libc++" cannam@133: AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody_lib])], cannam@133: [eval ax_cv_cxx_compile_cxx11_lib_libcxx=yes], cannam@133: [eval ax_cv_cxx_compile_cxx11_lib_libcxx=no]) cannam@133: CXX="$ac_save_CXX"]) cannam@133: if eval test x$ax_cv_cxx_compile_cxx11_lib_libcxx = xyes; then cannam@133: CXX="$CXX -stdlib=libc++" cannam@133: ac_success=yes cannam@133: break cannam@133: fi cannam@133: fi cannam@133: cannam@133: if test x$ac_success = xno; then cannam@133: AC_MSG_ERROR([*** A C++ library with support for C++11 features is required.]) cannam@133: fi cannam@133: fi cannam@133: ])