Skip to content

Commit

Permalink
Use C++14 compiler if possible
Browse files Browse the repository at this point in the history
This allows using new features of C++14 conditionally.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Feb 13, 2019
1 parent b3327f4 commit fd6e281
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions configure.ac
Expand Up @@ -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"
# set c++11 support based on platform/compiler
CPLUSPLUS=
AX_CHECK_COMPILE_FLAG([-std=c++11], [cplusplus11=true], [cplusplus11=false])
if $cplusplus11; then
CPLUSPLUS=11
fi
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
Expand Down

0 comments on commit fd6e281

Please sign in to comment.