Looking into cmake internal handling of MSVC, maybe this patch should 1.) Unify use of find_package(CXX11Compiler) 2.) Allow using C++11 features for MSVC 3.) using std_regex for MSVC
I cannot test, since I don't have MSVC. In _my_ implementation of cmake modules (cmake 3.4) the MSVC_VERSION is defined for MSVC. Kornel
signature.asc
Description: This is a digitally signed message part.
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5840ad0..d0061c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,21 +260,26 @@ if(UNIX OR MINGW) set(LYX_USE_STD_REGEX 1) endif() endif() - if (LYX_ENABLE_CXX11) - find_package(CXX11Compiler) - if(NOT CXX11COMPILER_FOUND) - message(FATAL_ERROR "A C++11 compatible compiler is required.") - endif() - set(LYX_GCC11_MODE "${CXX11_FLAG}") - endif() else() set(LYX_USE_STD_REGEX 0) -# if(MSVC10) -# set(LYX_USE_STD_REGEX 1) #TODO should we use it in ECMAScript mode? -# endif() + if (LYX_ENABLE_CXX11) + if(MSVC) + if(MSVC_VERSION GREATER 1599) + # MSVC10 and newer + set(LYX_USE_STD_REGEX 1) + endif() + endif() + endif() +endif() + +if (LYX_ENABLE_CXX11) + find_package(CXX11Compiler) + if(NOT CXX11COMPILER_FOUND) + message(FATAL_ERROR "A C++11 compatible compiler is required.") + endif() + set(LYX_GCC11_MODE "${CXX11_FLAG}") endif() - set(VERSION_INFO "CMake Build") # Try to get some informations from configure.ac diff --git a/development/cmake/modules/FindCXX11Compiler.cmake b/development/cmake/modules/FindCXX11Compiler.cmake index 7d09f8f..822c074 100644 --- a/development/cmake/modules/FindCXX11Compiler.cmake +++ b/development/cmake/modules/FindCXX11Compiler.cmake @@ -34,7 +34,12 @@ INCLUDE(CheckCXXSourceCompiles) INCLUDE(FindPackageHandleStandardArgs) -if (CMAKE_CXX_COMPILER_ID MATCHES "^[cC]lang$") +if (MSVC) + if(MSVC_VERSION GREATER 1799) + # Microsoft Visual Studio 2013 and newer, e.g. MSVC12 and MSVC14 + set(CXX11_FLAG_CANDIDATES "empty") + endif() +elsif (CMAKE_CXX_COMPILER_ID MATCHES "^[cC]lang$") set(CXX11_FLAG_CANDIDATES "--std=c++11 -Wno-deprecated-register") else() if (CYGWIN) @@ -83,7 +88,12 @@ int main() { # check c compiler set(SAFE_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET}) set(CMAKE_REQUIRED_QUIET ON) -FOREACH(FLAG ${CXX11_FLAG_CANDIDATES}) +FOREACH(FLAG1 ${CXX11_FLAG_CANDIDATES}) + if(FLAG1 STREQUAL "empty") + set(FLAG "") + else() + set(FLAG ${FLAG1}) + endif() SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") SET(CMAKE_REQUIRED_FLAGS "${FLAG}") UNSET(CXX11_FLAG_DETECTED CACHE)