Implement proper C++11 mode detection

Newer compilers have C++14 mode as default and package maintainers tend
to not specifying a C++ version when building a package, this causes
compatibility issues when (for example) qbt is compiled in C++11 and
dependency lib is in C++14. See issue #9485.

What this commit does:
1. Checks if compiler supports at least C++11
2. Checks if compiler is set in at least C++11 mode
This commit is contained in:
Chocobo1 2018-11-08 00:14:10 +08:00 committed by sledgehammer999
commit 1a21f45c75
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
4 changed files with 251 additions and 159 deletions

View file

@ -8,8 +8,6 @@ AC_LANG(C++)
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE
# Define --wth-* and --enable-* arguments
AC_ARG_WITH(qtsingleapplication,
@ -204,6 +202,32 @@ PKG_CHECK_MODULES(zlib,
[CPPFLAGS="$zlib_CFLAGS $CPPFLAGS"
LIBS="$zlib_LIBS $LIBS"])
# Check compiler C++11 support
AC_LANG_PUSH(C++)
m4_define([DETECT_CPP11_PROGRAM],
[AC_LANG_PROGRAM([[
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201103L
#error "This is not a C++11 compiler"
#endif]],
[[]])])
_tmp="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -std=c++11"
AC_COMPILE_IFELSE([DETECT_CPP11_PROGRAM()],
[],
[AC_MSG_ERROR([A compiler supporting C++11 is required.])])
CXXFLAGS="$_tmp $libtorrent_CFLAGS"
AC_COMPILE_IFELSE([DETECT_CPP11_PROGRAM()],
[],
[AC_MSG_ERROR([Compiler is not working in C++11 or later mode.
Make sure you use the same C++ mode for qBittorrent and its dependencies.
Example: `CXXFLAGS="\$CXXFLAGS -std=c++11" ./configure`])])
CXXFLAGS="$_tmp"
AC_LANG_POP([C++])
# These are required because autoconf doesn't expand these **particular**
# vars automatically. And qmake cannot autoexpand them.
AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])