diff options
| author | Nils Maier <maierman@web.de> | 2013-08-21 22:59:34 +0200 |
|---|---|---|
| committer | Nils Maier <maierman@web.de> | 2013-08-21 23:19:01 +0200 |
| commit | 22e414dbb0263a87029d14b0bd3da4a83f743567 (patch) | |
| tree | 82ac970ae071962e41d019930c08b33192023a1a /m4 | |
| parent | b888088dc3de4828897b6c9062cb75e1cd665d19 (diff) | |
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.
Diffstat (limited to 'm4')
| -rw-r--r-- | m4/ax_cxx_compile_stdcxx_11.m4 | 71 |
1 files 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 <bkoz@redhat.com> # Copyright (c) 2012 Zack Weinberg <zackw@panix.com> # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu> +# Copyright (c) 2013 Nils Maier <maierman@web.de> # # 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 <memory> + template <typename T> struct check { @@ -52,6 +60,9 @@ m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [ check_type&& cr = static_cast<check_type&&>(c); auto d = a; + + // Check std::shared_ptr is available, which might require -stdlib=libc++. + std::shared_ptr<check_type> 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++]) |
