Use C++14 compiler if possible

This allows using new features of C++14 conditionally.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2019-02-13 11:05:34 +01:00
parent b3327f4e90
commit fd6e281c61

View File

@ -331,46 +331,42 @@ AC_COMPILE_IFELSE(
AC_MSG_RESULT([$CLANG])
dnl ********************
dnl turn on c++11
dnl ********************
dnl **********************
dnl Turn on C++11 or newer
dnl **********************
OLD_CXXFLAGS=$CXXFLAGS
AC_MSG_CHECKING([whether compiler supports C++11])
CXXFLAGS="$CXXFLAGS -std=c++11"
AC_COMPILE_IFELSE(
[
AC_LANG_SOURCE([[
#if (__cplusplus < 201103L)
#error C++ 11 is unsupported
#endif
]])
], [
AC_MSG_RESULT(yes)
],
[
AC_MSG_RESULT(no)
AC_MSG_ERROR([Your compiler does not have the necessary c++11 support! Cannot proceed.])
])
CXXFLAGS="$OLD_CXXFLAGS"
CPLUSPLUS=
AX_CHECK_COMPILE_FLAG([-std=c++11], [cplusplus11=true], [cplusplus11=false])
if $cplusplus11; then
CPLUSPLUS=11
fi
# set c++11 support based on platform/compiler
AX_CHECK_COMPILE_FLAG([-std=c++14], [cplusplus14=true], [cplusplus14=false])
if $cplusplus14; then
CPLUSPLUS=14
fi
if test -z "$CPLUSPLUS"; then
AC_MSG_ERROR([Your compiler does not have the necessary C++11 support! Cannot proceed.])
fi
# Set C++11 or C++14 support based on platform/compiler
case "${host_os}" in
cygwin*)
CXXFLAGS="$CXXFLAGS -std=gnu++11"
CXXFLAGS="$CXXFLAGS -std=gnu++$CPLUSPLUS"
;;
*-darwin* | *-macos10*)
if test "x$CLANG" = "xyes"; then
CXXFLAGS="$CXXFLAGS -std=c++11 "
CXXFLAGS="$CXXFLAGS -std=c++$CPLUSPLUS"
LDFLAGS="$LDFLAGS -stdlib=libc++"
else
CXXFLAGS="$CXXFLAGS -std=c++11"
CXXFLAGS="$CXXFLAGS -std=c++$CPLUSPLUS"
fi
;;
*)
# default
CXXFLAGS="$CXXFLAGS -std=c++11"
CXXFLAGS="$CXXFLAGS -std=c++$CPLUSPLUS"
;;
esac