From 273bbd63b8a08837b2ec2444b5e1d04aeefe2f6f Mon Sep 17 00:00:00 2001 From: Silver Zachara Date: Tue, 28 May 2024 19:03:29 +0200 Subject: [PATCH] build: Fix MSVC /Zc:preprocessor warning (#1461) Don't add the /Zc:preprocessor- compiler flag when it's not needed, to avoid the following warning: D9025 : overriding '/Zc:preprocessor' with '/Zc:preprocessor- The latest Windows SDK v10.0.22621 compiles fine with conforming preprocessor enabled, the bug was in older SDK-s like <=10.0.20348.0. Add the /Zc:preprocessor for msvc >=v19.25, it didn't exist before this version (it existed as /experimental:preprocessor before). --- cmake/StandardSettings.cmake | 8 ++++---- unittest/CMakeLists.txt | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmake/StandardSettings.cmake b/cmake/StandardSettings.cmake index b6a0643c9..b0ff499b8 100644 --- a/cmake/StandardSettings.cmake +++ b/cmake/StandardSettings.cmake @@ -59,10 +59,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "^GNU|(Apple)?Clang$" AND NOT MSVC) include(StdAtomic) include(StdFilesystem) -elseif(MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "^Clang$") - target_compile_options( - standard_settings - INTERFACE /Zc:preprocessor /Zc:__cplusplus +elseif(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(standard_settings INTERFACE + /Zc:__cplusplus + $<$,19.25>:/Zc:preprocessor> ) endif() diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 842f3d4d8..3fee27fb9 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -51,8 +51,10 @@ list(APPEND source_files ${headers}) add_executable(unittest ${source_files}) -if(MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "^Clang$") - # Turn off /Zc:preprocessor for this test because it triggers a bug in some older Windows 10 SDK headers. +# Turn off /Zc:preprocessor for this test because it triggers a bug in some older Windows 10 SDK headers. +if(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.25" AND + CMAKE_SYSTEM_VERSION VERSION_LESS "10.0.22621") set_source_files_properties(test_util_DirEntry.cpp PROPERTIES COMPILE_FLAGS /Zc:preprocessor-) endif() -- 2.47.2