New test to determine correct -std option for CXX compiler

The test file is stolen from cmake. The options tested are, from the
most desirable to the least desirable:
  -std=c++14 -std=c++11 "" -std=c++0x -std=gnu++14 -std=gnu++11 -std=gnu++0x

It is expected that the result will not be correct for cygwin, but
this is fixable.
This commit is contained in:
Jean-Marc Lasgouttes 2016-07-06 14:03:22 +02:00
parent b874bdfd40
commit 23dbcb59d2

View File

@ -160,26 +160,53 @@ fi
]) ])
dnl Usage: LYX_CXX_CXX11: set lyx_use_cxx11 to yes if the compiler implements dnl Usage: LYX_CXX_CXX11_FLAGS: add to AM_CXXFLAGS the best flag that
dnl the C++11 standard. selects C++11 mode; gives an error when C++11 mode is not found.
AC_DEFUN([LYX_CXX_CXX11], AC_DEFUN([LYX_CXX_CXX11_FLAGS],
[AC_CACHE_CHECK([whether the compiler implements C++11], [AC_CACHE_CHECK([for at least C++11 mode], [lyx_cv_cxx11_flags],
[lyx_cv_cxx_cxx11], [lyx_cv_cxx11_flags=none
[save_CPPFLAGS=$CPPFLAGS for flag in -std=c++14 -std=c++11 "" -std=c++0x -std=gnu++14 -std=gnu++11 -std=gnu++0x ; do
CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS" save_CPPFLAGS=$CPPFLAGS
save_CXXFLAGS=$CXXFLAGS CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
CXXFLAGS="$AM_CXXFLAGS $CXXFLAGS" save_CXXFLAGS=$CXXFLAGS
AC_LANG_PUSH(C++) CXXFLAGS="$flag $AM_CXXFLAGS $CXXFLAGS"
AC_TRY_COMPILE([], [ AC_LANG_PUSH(C++)
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) dnl sample openmp source code to test
this is a c++11 compiler AC_TRY_COMPILE([
#endif template <typename T>
], struct check
[lyx_cv_cxx_cxx11=no], [lyx_cv_cxx_cxx11=yes ; lyx_flags="$lyx_flags c++11"]) {
AC_LANG_POP(C++) static_assert(sizeof(int) <= sizeof(T), "not big enough");
CXXFLAGS=$save_CXXFLAGS };
CPPFLAGS=$save_CPPFLAGS])
lyx_use_cxx11=$lyx_cv_cxx_cxx11 typedef check<check<bool>> right_angle_brackets;
class TestDeleted
{
public:
TestDeleted() = delete;
};
int a;
decltype(a) b;
typedef check<int> check_type;
check_type c;
check_type&& cr = static_cast<check_type&&>(c);
auto d = a;],
[return 0;],
[lyx_cv_cxx11_flags=$flag; break])
AC_LANG_POP(C++)
CXXFLAGS=$save_CXXFLAGS
CPPFLAGS=$save_CPPFLAGS
done])
if test $lyx_cv_cxx11_flags = none ; then
AC_ERROR([Cannot find suitable C++11 mode for compiler $CXX])
fi
lyx_cxx11_flags=$lyx_cv_cxx11_flags
AM_CXXFLAGS="$lyx_cxx11_flags $AM_CXXFLAGS"
]) ])
@ -369,35 +396,24 @@ if test x$GXX = xyes; then
;; ;;
esac esac
fi fi
fi
LYX_CXX_CXX11_FLAGS
# Some additional flags may be needed
if test x$GXX = xyes; then
case $gxx_version in case $gxx_version in
4.6*)
dnl Note that this will define __GXX_EXPERIMENTAL_CXX0X__.
dnl The source code relies on that.
cxx11_flags="-std=gnu++0x";;
4.7*|4.8*|4.9*|5.*)
cxx11_flags="-std=gnu++11";;
clang-3.0*|clang-3.1*|clang-3.2*|clang-3.3*) clang-3.0*|clang-3.1*|clang-3.2*|clang-3.3*)
dnl presumably all clang versions support c++11. dnl boost contains pragmas that are annoying on older clang versions
dnl boost contains pragmas that are annoying on older clang versions AM_CPPFLAGS="-Wno-unknown-pragmas $AM_CPPFLAGS";;
cxx11_flags="-std=c++11 -Wno-unknown-pragmas";;
clang*) clang*)
dnl the more recent versions support the deprecated-register warning, dnl the more recent versions support the deprecated-register warning,
dnl which is very annoying with Qt4.x right now. dnl which is very annoying with Qt4.x right now.
cxx11_flags="-std=c++11"
AM_CXXFLAGS="$AM_CXXFLAGS -Wno-deprecated-register";; AM_CXXFLAGS="$AM_CXXFLAGS -Wno-deprecated-register";;
*) # gcc 6 and newer use C++14 as default
;;
esac esac
# cxx11_flags is useful when running preprocessor alone
# (see detection of regex).
AM_CXXFLAGS="$cxx11_flags $AM_CXXFLAGS"
fi fi
LYX_CXX_CXX11 LYX_CXX_USE_REGEX([$lyx_cxx11_flags])
if test $lyx_use_cxx11 = no; then
AC_ERROR([A C++11 compatible compiler is required])
fi
LYX_CXX_USE_REGEX([$cxx11_flags])
]) ])
dnl Usage: LYX_USE_INCLUDED_BOOST : select if the included boost should dnl Usage: LYX_USE_INCLUDED_BOOST : select if the included boost should