Add /Zc:preprocessor for torch libraries in MSVC builds (#147825)

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/147825
Approved by: https://github.com/janeyx99
This commit is contained in:
cyy 2025-05-24 06:57:46 +00:00 committed by PyTorch MergeBot
parent 6503b4a96e
commit 8fe7ec6721

View File

@ -362,6 +362,10 @@ function(torch_compile_options libname)
# 2. For MSVC VERSION: https://cmake.org/cmake/help/latest/variable/MSVC_TOOLSET_VERSION.html
target_compile_options(${libname} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
endif()
# This option enables a token-based preprocessor that conforms to C99 and C++11 and later standards.
# This option is available since VS 2017.
# For MS official doc: https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:preprocessor" PARENT_SCOPE)
if(${MSVC_TOOLSET_VERSION} GREATER_EQUAL 143)
# Add /d2implyavx512upperregs- to disable compiler over-aggressive optimization, which caused involeved AVX512 register on AVX2 machine.