+dnl Usage: LYX_CXX_CXX11_FLAGS: add to AM_CXXFLAGS the best flag that
+selects C++11 mode; gives an error when C++11 mode is not found.
+AC_DEFUN([LYX_CXX_CXX11_FLAGS],
+[AC_CACHE_CHECK([for at least C++11 mode], [lyx_cv_cxx11_flags],
+ [lyx_cv_cxx11_flags=none
+ for flag in -std=c++14 -std=c++11 "" -std=c++0x -std=gnu++14 -std=gnu++11 -std=gnu++0x ; do
+ save_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
+ save_CXXFLAGS=$CXXFLAGS
+ CXXFLAGS="$flag $AM_CXXFLAGS $CXXFLAGS"
+ dnl sample openmp source code to test
+ AC_TRY_COMPILE([
+ template <typename T>
+ struct check
+ {
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
+ };
+
+ 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;], [],
+ [lyx_cv_cxx11_flags=$flag; break])
+ 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
+ AM_CXXFLAGS="$lyx_cv_cxx11_flags $AM_CXXFLAGS"
+])
+
+
+dnl Usage: LYX_CXX_USE_REGEX
+dnl decide whether we want to use std::regex and set the
+dnl LYX_USE_STD_REGEX macro and conditional accordingly.
+AC_DEFUN([LYX_CXX_USE_REGEX],
+[AC_ARG_ENABLE(std-regex,
+ AC_HELP_STRING([--enable-std-regex],[use std::regex instead of boost::regex (default is autodetected)]),
+ [lyx_std_regex=$enableval],
+ [AC_MSG_CHECKING([for correct regex implementation])
+ save_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
+ save_CXXFLAGS=$CXXFLAGS
+ CXXFLAGS="$AM_CXXFLAGS $CXXFLAGS"
+ # The following code snippet has been taken taken from example in
+ # http://stackoverflow.com/questions/8561850/compile-stdregex-iterator-with-gcc
+ AC_TRY_LINK(
+ [
+ #include <regex>
+ #include <iostream>
+
+ #include <string.h>
+
+ typedef std::regex_iterator<const char *> Myiter;
+ ], [
+ const char *pat = "axayaz";
+ Myiter::regex_type rx("a");
+ Myiter next(pat, pat + strlen(pat), rx);
+ Myiter end;
+ ], [lyx_std_regex=yes], [lyx_std_regex=no])
+ CXXFLAGS=$save_CXXFLAGS
+ CPPFLAGS=$save_CPPFLAGS
+ AC_MSG_RESULT([$lyx_std_regex])
+ ])
+
+ if test $lyx_std_regex = yes ; then
+ lyx_flags="$lyx_flags std-regex"
+ AC_DEFINE([LYX_USE_STD_REGEX], 1, [define to 1 if std::regex should be preferred to boost::regex])
+ fi
+ AM_CONDITIONAL([LYX_USE_STD_REGEX], test $lyx_std_regex = yes)
+])