Files
OrcaSlicer/deps/EXPAT/EXPAT.cmake
T
Noisyfox 8db30fdb30 Fix Expat MSVC builds with UTF-8 source encoding (#17596)
Expat 2.10.0 has UTF-8 quotes in a comment in random_rand_s.c. cl.exe reads source files in the system code page, so on code page 936 it reads the line break as part of a double-byte character. The next line becomes part of the comment and the build fails with C1020.

Pass /utf-8 to Expat's C compiler when building with MSVC, keeping the existing C flags.
2026-11-19 20:53:54 -06:00

50 lines
1.9 KiB
CMake

# Pinned release: expat's entity-amplification guard is a security boundary, so
# the parser must not come from a distro or SDK copy that may predate it.
# XML_DTD and XML_GE are passed explicitly: 2.4.0 gated the guard behind XML_DTD
# and 2.6.0 behind XML_GE, so neither may be left to the default.
set(_expat_c_flags_line "")
if (MSVC)
# UTF-8 quotes in random_rand_s.c comments can swallow a preprocessor line
# when MSVC reads the source using the system's legacy code page.
set(_expat_c_flags_line "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} /utf-8")
endif ()
orcaslicer_add_cmake_project(EXPAT
URL https://github.com/libexpat/libexpat/releases/download/R_2_10_0/expat-2.10.0.tar.gz
URL_HASH SHA256=5466a341f9c692ef7a958a6881311be597f8e1ce345984cf78414f54793dea4c
CMAKE_ARGS
"${_expat_c_flags_line}"
-DBUILD_SHARED_LIBS=OFF
-DEXPAT_SHARED_LIBS=OFF
-DEXPAT_DTD=ON
-DEXPAT_GE=ON
-DEXPAT_BUILD_TOOLS=OFF
-DEXPAT_BUILD_EXAMPLES=OFF
-DEXPAT_BUILD_TESTS=OFF
-DEXPAT_BUILD_DOCS=OFF
-DEXPAT_BUILD_FUZZERS=OFF
-DEXPAT_BUILD_PKGCONFIG=OFF
-DEXPAT_ENABLE_INSTALL=ON
)
if (MSVC)
add_debug_dep(dep_EXPAT)
# A deps prefix built before this pin still has lib/expat.lib from the
# bundled 2.5.0, and FindEXPAT matches that name before libexpatMD.lib, so
# overwrite it with the pinned build. This also covers a cached EXPAT_LIBRARY.
set(_expat_legacy_libs
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DESTDIR}/lib/libexpatMD.lib ${DESTDIR}/lib/expat.lib
)
if (DEP_DEBUG)
list(APPEND _expat_legacy_libs
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DESTDIR}/lib/libexpatdMD.lib ${DESTDIR}/lib/expatd.lib
)
endif ()
ExternalProject_Add_Step(dep_EXPAT copy_legacy_lib
DEPENDEES install
${_expat_legacy_libs}
)
endif ()