[LyX/master] Cmake build: Adapt handling of c++ standards to new Visual C++ 2019

Kornel Benko kornel at lyx.org
Tue May 5 11:31:26 UTC 2020


commit 9c863039b620ebc54b218e8be5c4112906178323
Author: Kornel Benko <kornel at lyx.org>
Date:   Tue May 5 13:49:50 2020 +0200

    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
---
 CMakeLists.txt                                    |    7 ++++++-
 development/cmake/modules/FindCXX11Compiler.cmake |   14 ++++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2a123e7..618f62a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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()
diff --git a/development/cmake/modules/FindCXX11Compiler.cmake b/development/cmake/modules/FindCXX11Compiler.cmake
index 739d267..e1bf1fb 100644
--- a/development/cmake/modules/FindCXX11Compiler.cmake
+++ b/development/cmake/modules/FindCXX11Compiler.cmake
@@ -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)


More information about the lyx-cvs mailing list