From ab1e2d49abdf5b1aca9035a51d9d73d687f0eba7 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Fri, 29 Dec 2017 13:46:42 +0100 Subject: [PATCH] Add a CMake check for a working implementation Define HAVE_WORKING_STD_REGEX if, and only if is usable. Normally, should be available and working in any compliant C++11 implementation, however at least g++ 4.8[1] lies about its C++11 compliance: its is utterly unusable, see [2] and [3] for details. [1] Which appears to be (precisely 4.8.5) the version shipped in CentOS 7, and used on FlightGear's current Jenkins installation. [2] https://stackoverflow.com/a/12665408/4756009 [3] https://sourceforge.net/p/flightgear/mailman/message/36170781/ --- CMakeLists.txt | 27 +++++++++++++++++++++++++++ simgear/simgear_config_cmake.h.in | 1 + 2 files changed, 28 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e15718b6..bbf4e46c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,6 +351,33 @@ if (NOT ${HAVE_STD_ISNAN}) message(FATAL_ERROR "Your compiler lacks C++11 std::isnan, please update it") endif() +# Check if the implementation in the C++ standard library is usable. +# This is necessary because g++ 4.8 lies about its C++11 compliance: its +# is utterly unusable, cf. [1]. +# The big preprocessor test essentially comes from [2], and gcc upstream devs +# appear to back it (see comments following [2], as well as [3]). +# +# [1] https://stackoverflow.com/a/12665408/4756009 +# [2] https://stackoverflow.com/a/41186162/4756009 +# [3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78905 +check_cxx_source_compiles( + "#include + #include + +int main() { + #if __cplusplus >= 201103L && \ + (!defined(__GLIBCXX__) || \ + (__cplusplus >= 201402L) || \ + defined(_GLIBCXX_REGEX_DFS_QUANTIFIERS_LIMIT) || \ + defined(_GLIBCXX_REGEX_STATE_LIMIT) || \ + (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE > 4)) + return EXIT_SUCCESS; + #else + nullptr = void; // intentionally trigger a compilation error + #endif +}" + HAVE_WORKING_STD_REGEX) + if(CMAKE_COMPILER_IS_GNUCXX) set(WARNING_FLAGS_CXX "-Wall -fPIC") set(WARNING_FLAGS_C "-Wall -fPIC") diff --git a/simgear/simgear_config_cmake.h.in b/simgear/simgear_config_cmake.h.in index ba28e761..0282aca1 100644 --- a/simgear/simgear_config_cmake.h.in +++ b/simgear/simgear_config_cmake.h.in @@ -11,6 +11,7 @@ #cmakedefine HAVE_TIMEGM #cmakedefine HAVE_STD_ISNAN +#cmakedefine HAVE_WORKING_STD_REGEX #cmakedefine HAVE_WINDOWS_H #cmakedefine HAVE_MKDTEMP #cmakedefine HAVE_AL_EXT_H