@@ -650,14 +650,18 @@ endif ()
650650# Precompiled headers
651651##
652652
653- # Non-LLVM sources get a PCH covering the most expensive standard library and
654- # core Halide headers.
655- target_precompile_headers (Halide PRIVATE Halide_pch.h )
656-
657- # Util.cpp implements run_with_large_stack(), which is sensitive to CMake's
658- # forced-include PCH path and produces crashing helper binaries when compiled
659- # with PCH enabled.
660- set_source_files_properties (Util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON )
653+ # On MSVC, cmake_pch.cxx compiles to a real .obj whose _PchSym_ markers leak
654+ # into the auto-generated exports.def (via CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS),
655+ # causing LNK2001/LNK4022. Disable PCH on MSVC entirely to avoid this.
656+ if (NOT MSVC )
657+ # Non-LLVM sources get a PCH covering the most expensive standard library
658+ # headers.
659+ target_precompile_headers (Halide PRIVATE Halide_pch.h )
660+
661+ # Util.cpp implements run_with_large_stack(), which requires _XOPEN_SOURCE
662+ # to be defined before any includes. The PCH force-include violates this.
663+ set_source_files_properties (Util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON )
664+ endif ()
661665
662666# LLVM sources live in their own object library so they can have a separate PCH.
663667add_library (Halide_LLVM_srcs OBJECT
@@ -698,7 +702,12 @@ foreach (backend IN LISTS Halide_LLVM_COMPONENTS)
698702 target_link_libraries (Halide_LLVM_srcs PRIVATE Halide_LLVM::${backend} )
699703endforeach ()
700704
701- target_precompile_headers (Halide_LLVM_srcs PRIVATE Halide_llvm_pch.h )
705+ # On MSVC, cmake_pch.cxx compiles to a real .obj whose _PchSym_ markers leak
706+ # into the auto-generated exports.def (via CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS),
707+ # causing LNK2001/LNK4022. Disable the LLVM PCH on MSVC to avoid this.
708+ if (NOT MSVC )
709+ target_precompile_headers (Halide_LLVM_srcs PRIVATE Halide_llvm_pch.h )
710+ endif ()
702711
703712target_sources (Halide PRIVATE $<TARGET_OBJECTS :Halide_LLVM_srcs >)
704713
0 commit comments