]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Fix MSVC /Zc:preprocessor warning (#1461)
authorSilver Zachara <silver.zachara@gmail.com>
Tue, 28 May 2024 17:03:29 +0000 (19:03 +0200)
committerGitHub <noreply@github.com>
Tue, 28 May 2024 17:03:29 +0000 (19:03 +0200)
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
unittest/CMakeLists.txt

index b6a0643c99ac551869540487b685a64922235744..b0ff499b86dd42d7d743f3ced6f9af8bd9978e8e 100644 (file)
@@ -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
+      $<$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.25>:/Zc:preprocessor>
   )
 endif()
 
index 842f3d4d8341dadcb4a65ff6b68ce372b6324377..3fee27fb9a530212450481c3b6c2cbb92da0f0c7 100644 (file)
@@ -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()