Add a CMake check for a working <regex> implementation

Define HAVE_WORKING_STD_REGEX if, and only if <regex> is usable.

Normally, <regex> 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 <regex> 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/
This commit is contained in:
Florent Rougon 2017-12-29 13:46:42 +01:00
parent 401bd1c643
commit ab1e2d49ab
2 changed files with 28 additions and 0 deletions

View File

@ -351,6 +351,33 @@ if (NOT ${HAVE_STD_ISNAN})
message(FATAL_ERROR "Your compiler lacks C++11 std::isnan, please update it") message(FATAL_ERROR "Your compiler lacks C++11 std::isnan, please update it")
endif() endif()
# Check if the <regex> implementation in the C++ standard library is usable.
# This is necessary because g++ 4.8 lies about its C++11 compliance: its
# <regex> 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 <regex>
#include <cstdlib>
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) if(CMAKE_COMPILER_IS_GNUCXX)
set(WARNING_FLAGS_CXX "-Wall -fPIC") set(WARNING_FLAGS_CXX "-Wall -fPIC")
set(WARNING_FLAGS_C "-Wall -fPIC") set(WARNING_FLAGS_C "-Wall -fPIC")

View File

@ -11,6 +11,7 @@
#cmakedefine HAVE_TIMEGM #cmakedefine HAVE_TIMEGM
#cmakedefine HAVE_STD_ISNAN #cmakedefine HAVE_STD_ISNAN
#cmakedefine HAVE_WORKING_STD_REGEX
#cmakedefine HAVE_WINDOWS_H #cmakedefine HAVE_WINDOWS_H
#cmakedefine HAVE_MKDTEMP #cmakedefine HAVE_MKDTEMP
#cmakedefine HAVE_AL_EXT_H #cmakedefine HAVE_AL_EXT_H