commit 24a7dd45dcc6c7b4d22bf1dc3762ff27efeedcaa
Author: Kornel Benko <[email protected]>
Date:   Sat Jun 11 12:23:33 2016 +0200

    Cmake build: Determine availability of 'std::regex' if using clang compiler

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..5d127cf 100644
--- a/development/cmake/modules/FindCXX11Compiler.cmake
+++ b/development/cmake/modules/FindCXX11Compiler.cmake
@@ -80,6 +80,26 @@ int main() {
 };
 ")
 
+# The following code snipped taken from example in 
http://stackoverflow.com/questions/8561850/compile-stdregex-iterator-with-gcc
+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 +113,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 +129,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