mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Cmake build: Determine availability of 'std::regex' if using clang compiler
This commit is contained in:
parent
9558d863c8
commit
24a7dd45dc
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user