Skip to content

Commit ab0a468

Browse files
author
KytyPlus Dev
committed
build: link zlib statically to remove z.dll runtime dependency
1 parent c483542 commit ab0a468

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

3rdparty/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
66
set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
77
set(ZLIB_BUILD_TESTING OFF CACHE BOOL "" FORCE)
88
set(ZLIB_INSTALL OFF CACHE BOOL "" FORCE)
9+
# Build zlib statically only. The vendored zlib CMakeLists defaults
10+
# ZLIB_BUILD_SHARED to ON, which emits z.dll on Windows and makes the
11+
# emulator a hard runtime dependency on whatever z.dll the loader resolves
12+
# from PATH. A stale/ABI-mismatched z.dll then kills the process at startup.
13+
# Linking the static archive removes the DLL dependency entirely.
14+
set(ZLIB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
915
add_subdirectory(zlib EXCLUDE_FROM_ALL)
1016

1117
add_subdirectory(cpuinfo)

src/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,13 @@ endif()
356356

357357
set(kyty_emulator_link_libraries common Vulkan::Headers spirv-tools-opt spirv-tools SDL2-static imgui xxhash FFmpeg::ffmpeg fmt::fmt nlohmann_json::nlohmann_json LibAtrac9 kyty_git_version Zydis::Zydis xbyak::xbyak)
358358

359-
# zlib is required by rpfArchiveReader on all platforms.
360-
find_package(ZLIB)
361-
if(ZLIB_FOUND)
362-
list(APPEND kyty_emulator_link_libraries ZLIB::ZLIB)
363-
list(APPEND kyty_emulator_compile_definitions KYTY_HAS_ZLIB=1)
364-
endif()
359+
# zlib is required by rpfArchiveReader on all platforms. The vendored static
360+
# archive (ZLIB::ZLIBSTATIC) is always built by 3rdparty/CMakeLists.txt, so
361+
# link it unconditionally. The shared target ZLIB::ZLIB is not built anymore
362+
# (no z.dll is emitted or loaded at runtime), and find_package(ZLIB) is not
363+
# used because it could resolve a system zlib instead of the vendored one.
364+
list(APPEND kyty_emulator_link_libraries ZLIB::ZLIBSTATIC)
365+
list(APPEND kyty_emulator_compile_definitions KYTY_HAS_ZLIB=1)
365366

366367
# Linux system libraries required by the static FFmpeg archive.
367368
if(LINUX)

src/package/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ target_link_libraries(pkg_parser PRIVATE common)
1919

2020
# zlib is required for PFSC (compressed PFS) decompression.
2121
# Vendored static build from 3rdparty/zlib (always available, no system dependency).
22-
target_link_libraries(pkg_parser PRIVATE ZLIB::ZLIB)
22+
target_link_libraries(pkg_parser PRIVATE ZLIB::ZLIBSTATIC)
2323
target_compile_definitions(pkg_parser PRIVATE KYTY_HAS_ZLIB=1)

0 commit comments

Comments
 (0)