Cmake build: Adapt handling of c++ standards to new Visual C++ 2019

More or less suggested by Thibaut Cuvelier's switch to Visual C++ 2019
This commit is contained in:
Kornel Benko 2020-05-05 13:49:50 +02:00
parent c506f304bc
commit 9c863039b6
2 changed files with 18 additions and 3 deletions

View File

@ -657,7 +657,12 @@ else()
set(library_type STATIC)
endif()
if(NOT MSVC)
if(MSVC)
if (CXX11_FLAG MATCHES "\\+\\+([0-9]+)")
set(CMAKE_CXX_STANDARD ${CMAKE_MATCH_1})
message(STATUS "CMAKE_CXX_STANDARD set to ${CMAKE_CXX_STANDARD}")
endif()
else()
if(NOT LYX_QUIET)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

View File

@ -44,7 +44,15 @@ else()
# MSVC does not have a general C++11 flag, one can only switch off
# MS extensions with /Za in general or by extension with /Zc.
# Use an empty flag to ensure that CXX11_STD_REGEX is correctly set.
set(CXX11_FLAG_CANDIDATES "noflagneeded")
if (MSVC_VERSION LESS 1926)
set(CXX11_FLAG_CANDIDATES "noflagneeded")
else()
set(CXX11_FLAG_CANDIDATES
"/std:c++20"
"/std:c++17"
"/std:c++14"
"noflagneeded")
endif()
else()
set(CXX11_FLAG_CANDIDATES
"--std=c++14"
@ -113,7 +121,9 @@ set(SAFE_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ON)
SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
FOREACH(FLAG ${CXX11_FLAG_CANDIDATES})
IF(NOT "${FLAG}" STREQUAL "noflagneeded")
IF("${FLAG}" STREQUAL "noflagneeded")
UNSET(CMAKE_REQUIRED_FLAGS)
ELSE()
SET(CMAKE_REQUIRED_FLAGS "${FLAG}")
ENDIF()
UNSET(CXX11_FLAG_DETECTED CACHE)