Am Samstag, 11. Juni 2016 um 10:36:47, schrieb Georg Baum 
<georg.b...@post.rwth-aachen.de>
> Kornel Benko wrote:
>
> > OK, but my second question is not answered. To what value  should
> > LYX_USE_STD_REGEX be set?
>
> It should be autodetected. The algorithm of autotools is:
>
> detect presence of <regex>. If available and compiler is clang, use
> std::regex.
>
> This is however not 100% correct: If clang is used on linux with the gcc
> stdlib, then a version check would be needed for the gcc stdlib as well,
> since it would use the broken gcc implementation of the lib comes from a gcc
> older than 4.9. This check is currently not implemented. Therefore it was
> good than Jean-Marc introduced the possibility to disable stdregex manually
> at 6f585055d918.
>
>
> Georg

I have a check for regex, what about the attached?
1.) Determine if 'regex-source' compiles in FindCXX11Compiler.cmake
2.) Use the value in case of 'clang' in CMakeLists.txt

Maybe we should use this value unconditionally?

        Kornel

Attachment: signature.asc
Description: This is a digitally signed message part.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fee89e1..1bc690a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -260,17 +260,29 @@ if(NOT CXX11COMPILER_FOUND)
 endif()
 set(LYX_GCC11_MODE)
 if(UNIX OR MINGW)
-	execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
-	message(STATUS "Using GCC version ${GCC_VERSION}")
-	if(GCC_VERSION VERSION_LESS 4.9)
-		if(GCC_VERSION VERSION_LESS 4.3)
-			message(FATAL_ERROR "gcc >= 4.3 is required.")
-		endif()
-		# <regex> in gcc is unusable in versions less than 4.9.0
-		# see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
-		set(LYX_USE_STD_REGEX 0)
+	if (CMAKE_CXX_COMPILER_ID MATCHES "^[cC]lang$")
+	  # ignore the GCC_VERSION for clang
+	  # We pretend the compiler version >= 4.9
+	  message(STATUS "Using clang")
+	  # CXX11_STD_REGEX found in FindCXX11Compiler.cmake
+	  if(CXX11_STD_REGEX)
+	    set(LYX_USE_STD_REGEX 1)
+	  else()
+	    set(LYX_USE_STD_REGEX 0)
+	  endif()
 	else()
-		set(LYX_USE_STD_REGEX 1)
+	  execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+	  message(STATUS "Using GCC version ${GCC_VERSION}")
+	  if(GCC_VERSION VERSION_LESS 4.9)
+		  if(GCC_VERSION VERSION_LESS 4.3)
+			  message(FATAL_ERROR "gcc >= 4.3 is required.")
+		  endif()
+		  # <regex> in gcc is unusable in versions less than 4.9.0
+		  # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
+		  set(LYX_USE_STD_REGEX 0)
+	  else()
+		  set(LYX_USE_STD_REGEX 1)
+	  endif()
 	endif()
 	set(LYX_GCC11_MODE "${CXX11_FLAG}")
 else()
diff --git a/development/cmake/modules/FindCXX11Compiler.cmake b/development/cmake/modules/FindCXX11Compiler.cmake
index 7d09f8f..2c711c8 100644
--- a/development/cmake/modules/FindCXX11Compiler.cmake
+++ b/development/cmake/modules/FindCXX11Compiler.cmake
@@ -80,6 +80,25 @@ int main() {
 };
 ")
 
+set(REGEX_TEST_SOURCE
+"
+#include <regex>
+#include <iostream>
+
+#include <string.h>
+
+typedef std::regex_iterator<const char *> Myiter;
+int main()
+{
+    const char *pat = \"axayaz\";
+    Myiter::regex_type rx(\"a\");
+    Myiter next(pat, pat + strlen(pat), rx);
+    Myiter end;
+
+    return (0);
+}
+")
+
 # check c compiler
 set(SAFE_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
 set(CMAKE_REQUIRED_QUIET ON)
@@ -93,7 +112,15 @@ FOREACH(FLAG ${CXX11_FLAG_CANDIDATES})
     SET(CXX11_FLAG "${FLAG}")
     message(STATUS "CXX11_FLAG_DETECTED = \"${FLAG}\"")
     set(LYX_USE_CXX11 1)
-    BREAK()
+      check_cxx_source_compiles("${REGEX_TEST_SOURCE}" CXX_STD_REGEX_DETECTED)
+      if (CXX_STD_REGEX_DETECTED)
+	message(STATUS "Compiler supports std_regex")
+	set(CXX11_STD_REGEX ON)
+      else()
+	message(STATUS "Compiler does not support std_regex")
+	set(CXX11_STD_REGEX OFF)
+      endif()
+    break()
   ENDIF()
 ENDFOREACH()
 set(CMAKE_REQUIRED_QUIET ${SAFE_CMAKE_REQUIRED_QUIET})
@@ -101,4 +128,4 @@ set(CMAKE_REQUIRED_QUIET ${SAFE_CMAKE_REQUIRED_QUIET})
 # handle the standard arguments for find_package
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CXX11Compiler DEFAULT_MSG CXX11_FLAG)
 
-MARK_AS_ADVANCED(CXX11_FLAG)
+MARK_AS_ADVANCED(CXX11_FLAG CXX11_STD_REGEX)

Reply via email to