diff --git a/configure b/configure index 04eeb1a741c..a10a2c85c6a 100755 --- a/configure +++ b/configure @@ -4770,11 +4770,95 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_ct_CXX"; then +# Check if it actually found a C++ compiler. +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : have_cxx=yes else have_cxx=no fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +if test "$have_cxx" = yes; then + +# Detect option needed for C++11 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CXX option to accept ISO C++11" >&5 +$as_echo_n "checking for $CXX option to accept ISO C++11... " >&6; } +if ${pgac_cv_prog_cxx_cxx11+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_cv_prog_cxx_cxx11=no +pgac_save_CXX=$CXX +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +for pgac_arg in '' '-std=gnu++11' '-std=c++11'; do + CXX="$pgac_save_CXX $pgac_arg" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#if !defined __cplusplus || __cplusplus < 201103L +# error "Compiler does not advertise C++11 conformance" +#endif +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + pgac_cv_prog_cxx_cxx11=$pgac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test x"$pgac_cv_prog_cxx_cxx11" != x"no" && break +done +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CXX=$pgac_save_CXX +fi + + +if test x"$pgac_cv_prog_cxx_cxx11" = x"no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C++ compiler \"$CXX\" does not support C++11" >&5 +$as_echo "$as_me: WARNING: C++ compiler \"$CXX\" does not support C++11" >&2;} + have_cxx=no +elif test x"$pgac_cv_prog_cxx_cxx11" = x""; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_cxx_cxx11" >&5 +$as_echo "$pgac_cv_prog_cxx_cxx11" >&6; } + CXX="$CXX $pgac_cv_prog_cxx_cxx11" +fi + +fi # have_cxx # Check if it's Intel's compiler, which (usually) pretends to be gcc, @@ -14764,7 +14848,6 @@ cat >>confdefs.h <<_ACEOF _ACEOF - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ printf format archetype" >&5 $as_echo_n "checking for C++ printf format archetype... " >&6; } if ${pgac_cv_cxx_printf_archetype+:} false; then : diff --git a/configure.ac b/configure.ac index 13c75170f7a..814e64a967e 100644 --- a/configure.ac +++ b/configure.ac @@ -387,13 +387,46 @@ fi AC_PROG_CXX([$pgac_cxx_list]) -if test -n "$ac_ct_CXX"; then - have_cxx=yes -else - have_cxx=no -fi +# Check if it actually found a C++ compiler. +AC_LANG_PUSH([C++]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], + [have_cxx=yes], + [have_cxx=no]) +AC_LANG_POP([C++]) AC_SUBST(have_cxx) +if test "$have_cxx" = yes; then + +# Detect option needed for C++11 +AC_MSG_CHECKING([for $CXX option to accept ISO C++11]) +AC_CACHE_VAL([pgac_cv_prog_cxx_cxx11], +[pgac_cv_prog_cxx_cxx11=no +pgac_save_CXX=$CXX +AC_LANG_PUSH([C++]) +for pgac_arg in '' '-std=gnu++11' '-std=c++11'; do + CXX="$pgac_save_CXX $pgac_arg" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#if !defined __cplusplus || __cplusplus < 201103L +# error "Compiler does not advertise C++11 conformance" +#endif]])], [[pgac_cv_prog_cxx_cxx11=$pgac_arg]]) + test x"$pgac_cv_prog_cxx_cxx11" != x"no" && break +done +AC_LANG_POP([C++]) +CXX=$pgac_save_CXX]) + +if test x"$pgac_cv_prog_cxx_cxx11" = x"no"; then + AC_MSG_RESULT([unsupported]) + AC_MSG_WARN([C++ compiler "$CXX" does not support C++11]) + have_cxx=no +elif test x"$pgac_cv_prog_cxx_cxx11" = x""; then + AC_MSG_RESULT([none needed]) +else + AC_MSG_RESULT([$pgac_cv_prog_cxx_cxx11]) + CXX="$CXX $pgac_cv_prog_cxx_cxx11" +fi + +fi # have_cxx + + # Check if it's Intel's compiler, which (usually) pretends to be gcc, # but has idiosyncrasies of its own. We assume icc will define # __INTEL_COMPILER regardless of CFLAGS. diff --git a/meson.build b/meson.build index 92850244ad9..df907b62da3 100644 --- a/meson.build +++ b/meson.build @@ -586,6 +586,33 @@ if not cc.compiles(c11_test, name: 'C11') endif +# Do we need an option to enable C++11? +cxx11_test = ''' +#if !defined __cplusplus || __cplusplus < 201103L +# error "Compiler does not advertise C++11 conformance" +#endif +''' + +if have_cxx and not cxx.compiles(cxx11_test, name: 'C++11') + cxx11_ok = false + if cxx.get_id() == 'msvc' + cxx11_test_args = ['/std:c++14'] # oldest version supported + else + cxx11_test_args = ['-std=gnu++11', '-std=c++11'] + endif + foreach arg : cxx11_test_args + if cxx.compiles(cxx11_test, name: 'C++11 with @0@'.format(arg), args: [arg]) + cxx11_ok = true + cxxflags += arg + break + endif + endforeach + if not cxx11_ok + error('C++ compiler does not support C++11') + endif +endif + + postgres_inc = [include_directories(postgres_inc_d)] test_lib_d = postgres_lib_d test_c_args = cppflags + cflags