[cmake][msvc] Enable standards-conforming preprocessor
authorJan Svoboda <jan_svoboda@apple.com>
Wed, 2 Nov 2022 16:35:00 +0000 (09:35 -0700)
committerJan Svoboda <jan_svoboda@apple.com>
Wed, 2 Nov 2022 16:35:55 +0000 (09:35 -0700)
Since we now only support Visual Studio 2019 16.7 and newer, we're able to use the /Zc:preprocessor flag that turns on the standards-conforming preprocessor. Among other things, it correctly expands __VA_ARGS__. This enables removal of some boilerplate in D135128.

Reviewed By: Bigcheese, thieta

Differential Revision: https://reviews.llvm.org/D135128

llvm/cmake/modules/HandleLLVMOptions.cmake

index 7828e8a..8be51f7 100644 (file)
@@ -481,6 +481,10 @@ if( MSVC )
 
   append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 
+  # Enable standards-conforming preprocessor.
+  # https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor
+  append("/Zc:preprocessor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+
   # Some projects use the __cplusplus preprocessor macro to check support for
   # a particular version of the C++ standard. When this option is not specified
   # explicitly, macro's value is "199711L" that implies C++98 Standard.