Skip to content

Commit fd6e281

Browse files
committed
Use C++14 compiler if possible
This allows using new features of C++14 conditionally. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent b3327f4 commit fd6e281

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

configure.ac

+24-28
Original file line numberDiff line numberDiff line change
@@ -331,46 +331,42 @@ AC_COMPILE_IFELSE(
331331
332332
AC_MSG_RESULT([$CLANG])
333333
334-
dnl ********************
335-
dnl turn on c++11
336-
dnl ********************
334+
dnl **********************
335+
dnl Turn on C++11 or newer
336+
dnl **********************
337337
338-
OLD_CXXFLAGS=$CXXFLAGS
339-
AC_MSG_CHECKING([whether compiler supports C++11])
340-
CXXFLAGS="$CXXFLAGS -std=c++11"
341-
AC_COMPILE_IFELSE(
342-
[
343-
AC_LANG_SOURCE([[
344-
#if (__cplusplus < 201103L)
345-
#error C++ 11 is unsupported
346-
#endif
347-
]])
348-
], [
349-
AC_MSG_RESULT(yes)
350-
],
351-
[
352-
AC_MSG_RESULT(no)
353-
AC_MSG_ERROR([Your compiler does not have the necessary c++11 support! Cannot proceed.])
354-
])
355-
CXXFLAGS="$OLD_CXXFLAGS"
356-
357-
358-
# set c++11 support based on platform/compiler
338+
CPLUSPLUS=
339+
340+
AX_CHECK_COMPILE_FLAG([-std=c++11], [cplusplus11=true], [cplusplus11=false])
341+
if $cplusplus11; then
342+
CPLUSPLUS=11
343+
fi
344+
345+
AX_CHECK_COMPILE_FLAG([-std=c++14], [cplusplus14=true], [cplusplus14=false])
346+
if $cplusplus14; then
347+
CPLUSPLUS=14
348+
fi
349+
350+
if test -z "$CPLUSPLUS"; then
351+
AC_MSG_ERROR([Your compiler does not have the necessary C++11 support! Cannot proceed.])
352+
fi
353+
354+
# Set C++11 or C++14 support based on platform/compiler
359355
case "${host_os}" in
360356
cygwin*)
361-
CXXFLAGS="$CXXFLAGS -std=gnu++11"
357+
CXXFLAGS="$CXXFLAGS -std=gnu++$CPLUSPLUS"
362358
;;
363359
*-darwin* | *-macos10*)
364360
if test "x$CLANG" = "xyes"; then
365-
CXXFLAGS="$CXXFLAGS -std=c++11 "
361+
CXXFLAGS="$CXXFLAGS -std=c++$CPLUSPLUS"
366362
LDFLAGS="$LDFLAGS -stdlib=libc++"
367363
else
368-
CXXFLAGS="$CXXFLAGS -std=c++11"
364+
CXXFLAGS="$CXXFLAGS -std=c++$CPLUSPLUS"
369365
fi
370366
;;
371367
*)
372368
# default
373-
CXXFLAGS="$CXXFLAGS -std=c++11"
369+
CXXFLAGS="$CXXFLAGS -std=c++$CPLUSPLUS"
374370
;;
375371
esac
376372

0 commit comments

Comments
 (0)