@@ -657,14 +657,18 @@ endif ()
657657# Precompiled headers
658658##
659659
660- # Non-LLVM sources get a PCH covering the most expensive standard library and
661- # core Halide headers.
662- target_precompile_headers (Halide PRIVATE Halide_pch.h )
663-
664- # Util.cpp implements run_with_large_stack(), which is sensitive to CMake's
665- # forced-include PCH path and produces crashing helper binaries when compiled
666- # with PCH enabled.
667- set_source_files_properties (Util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON )
660+ # On MSVC, cmake_pch.cxx compiles to a real .obj whose _PchSym_ markers leak
661+ # into the auto-generated exports.def (via CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS),
662+ # causing LNK2001/LNK4022. Disable PCH on MSVC entirely to avoid this.
663+ if (NOT MSVC )
664+ # Non-LLVM sources get a PCH covering the most expensive standard library
665+ # headers.
666+ target_precompile_headers (Halide PRIVATE Halide_pch.h )
667+
668+ # Util.cpp implements run_with_large_stack(), which requires _XOPEN_SOURCE
669+ # to be defined before any includes. The PCH force-include violates this.
670+ set_source_files_properties (Util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON )
671+ endif ()
668672
669673# LLVM sources live in their own object library so they can have a separate PCH.
670674add_library (Halide_LLVM_srcs OBJECT
@@ -705,7 +709,12 @@ foreach (backend IN LISTS Halide_LLVM_COMPONENTS)
705709 target_link_libraries (Halide_LLVM_srcs PRIVATE Halide_LLVM::${backend} )
706710endforeach ()
707711
708- target_precompile_headers (Halide_LLVM_srcs PRIVATE Halide_llvm_pch.h )
712+ # On MSVC, cmake_pch.cxx compiles to a real .obj whose _PchSym_ markers leak
713+ # into the auto-generated exports.def (via CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS),
714+ # causing LNK2001/LNK4022. Disable the LLVM PCH on MSVC to avoid this.
715+ if (NOT MSVC )
716+ target_precompile_headers (Halide_LLVM_srcs PRIVATE Halide_llvm_pch.h )
717+ endif ()
709718
710719target_sources (Halide PRIVATE $<TARGET_OBJECTS :Halide_LLVM_srcs >)
711720
0 commit comments