From 22e414dbb0263a87029d14b0bd3da4a83f743567 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Wed, 21 Aug 2013 22:59:34 +0200 Subject: [PATCH] Make AX_CXX_COMPILE_STDCXX_11 test for -stdlib=libc++ via std::shared_ptr The clang shipped with OSX XCode and clangs not build enabling libcpp, will default to the libstdc++ headers and lib installed on the system. In the OSX case, that libstdc++ is the one bundles with gcc-4.2, which is far too old to provide all required C++11 types, such as std::shared_ptr. Hence, the C++11 check should try to compile a program with a C++11 type and try -stdlib=libc++ if the default lib fails to compile said program. --- m4/ax_cxx_compile_stdcxx_11.m4 | 71 ++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4 index cb0d2673..ecb03427 100644 --- a/m4/ax_cxx_compile_stdcxx_11.m4 +++ b/m4/ax_cxx_compile_stdcxx_11.m4 @@ -22,11 +22,16 @@ # 'optional', then configuration proceeds regardless, after defining # HAVE_CXX11 if and only if a supporting mode is found. # +# This version of AX_CXX_COMPILE_STDCXX_11 will also check if specifying +# `-stdlib=libc++`` is required, as it is on current OSX systems using +# a clang which defaults to an old libstdc++. +# # LICENSE # # Copyright (c) 2008 Benjamin Kosnik # Copyright (c) 2012 Zack Weinberg # Copyright (c) 2013 Roy Stogner +# Copyright (c) 2013 Nils Maier # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice @@ -34,8 +39,11 @@ # warranty. #serial 3 +#modified to check fo -stdlib=libc++ (required on OSX) m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [ + #include + template struct check { @@ -52,6 +60,9 @@ m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [ check_type&& cr = static_cast(c); auto d = a; + + // Check std::shared_ptr is available, which might require -stdlib=libc++. + std::shared_ptr ptr; ]) AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl @@ -77,40 +88,44 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl m4_if([$1], [noext], [], [dnl if test x$ac_success = xno; then for switch in -std=gnu++11 -std=gnu++0x; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) - AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, - $cachevar, - [ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS $switch" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], - [eval $cachevar=yes], - [eval $cachevar=no]) - CXXFLAGS="$ac_save_CXXFLAGS"]) - if eval test x\$$cachevar = xyes; then - CXXFLAGS="$CXXFLAGS $switch" - ac_success=yes - break - fi + for lib in "" -stdlib=libc++; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch$lib]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch $lib, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch $lib" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch $lib" + ac_success=yes + break 2 + fi + done done fi]) m4_if([$1], [ext], [], [dnl if test x$ac_success = xno; then for switch in -std=c++11 -std=c++0x; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) - AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, - $cachevar, - [ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS $switch" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], - [eval $cachevar=yes], - [eval $cachevar=no]) - CXXFLAGS="$ac_save_CXXFLAGS"]) - if eval test x\$$cachevar = xyes; then - CXXFLAGS="$CXXFLAGS $switch" - ac_success=yes - break - fi + for lib in "" -stdlib=libc++; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch$lib]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch $lib, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch $lib" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch $lib" + ac_success=yes + break 2 + fi + done done fi]) AC_LANG_POP([C++])