build(toolchain): static-link MinGW runtime so the DLL has no libgcc/libstdc++ runtime dependency
This commit is contained in:
1 parent
091dd18d9e
commit
e4a3405a4b
1 file changed
+30
-3
@@ -33,6 +33,33 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
# Store path pinned in ../toolchain.lock; keep in sync if the pin moves.
|
||||
set(_gk_mcfgthread_lib "/nix/store/g72bh3mrbh6gkh59axd2199js9kccxfs-mcfgthread-i686-w64-mingw32-2.5.1/lib")
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${_gk_mcfgthread_lib}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${_gk_mcfgthread_lib}")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L${_gk_mcfgthread_lib}")
|
||||
# The original gamekdm.dll was built by MSVC with a statically linked CRT and
|
||||
# imports ZERO C/C++-runtime DLLs (confirmed: its import table has no
|
||||
# msvcrXX.dll-style runtime entries beyond genuine Win32 system DLLs). A
|
||||
# MinGW rebuild must reproduce that shape (no libgcc_s_dw2-1.dll,
|
||||
# libstdc++-6.dll, libwinpthread-1.dll or libmcfgthread-*.dll import) or it is
|
||||
# not a true drop-in replacement for the original launcher/Wine (IS-2).
|
||||
#
|
||||
# -static-libgcc / -static-libstdc++ fold libgcc and libstdc++ in statically;
|
||||
# plain -static additionally forces every other -lFOO (including -lmcfgthread,
|
||||
# pulled in by GCC 16.2.0's default i686-w64-mingw32 link spec) to resolve
|
||||
# against its .a archive instead of its .dll.a import-library counterpart when
|
||||
# both exist side by side, which is the case for all three runtime libs here:
|
||||
# libgcc.a / libgcc_s.a (gcc derivation, lib/gcc/.../16.2.0 and i686-w64-mingw32/lib)
|
||||
# libstdc++.a (gcc derivation, i686-w64-mingw32/lib)
|
||||
# libmcfgthread.a (mcfgthreads package, see _gk_mcfgthread_lib above)
|
||||
# All three static archives were confirmed present in this pinned toolchain
|
||||
# before relying on -static here (see task-2.log fix transcript); if a future
|
||||
# toolchain pin drops one of them, -static will fail to link with a clear
|
||||
# "cannot find -l<name>" error rather than silently falling back to the
|
||||
# dynamic import library.
|
||||
#
|
||||
# Set via the *_INIT cache-seed variables (not CMAKE_*_LINKER_FLAGS directly):
|
||||
# the toolchain file runs before project()/enable_language() establish the
|
||||
# CMAKE_*_LINKER_FLAGS cache entries, so a plain set() here would be
|
||||
# overwritten by CMake's own default-flags initialization; the _INIT variables
|
||||
# are what CMake seeds those cache entries from, so every target (now and any
|
||||
# added later) inherits this without each CMakeLists.txt repeating it.
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-L${_gk_mcfgthread_lib} -static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-L${_gk_mcfgthread_lib} -static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-L${_gk_mcfgthread_lib} -static-libgcc -static-libstdc++ -static")
|
||||
Reference in new issue
Block a user