Fix SDL static linking

This commit is contained in:
OPNA2608 2022-04-02 17:36:04 +02:00
parent 8483f85397
commit 54a36c4950
3 changed files with 7 additions and 42 deletions

View file

@ -264,11 +264,6 @@ jobs:
else
CMAKE_EXTRA_ARGS+=('-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded')
fi
# Fix SDL static linking (see linked issues in patch file)
pushd extern/SDL
env EMAIL=root@localhost git am ../SDL-Fix-MSVC-static-runtime-linking.patch
popd
elif [ '${{ matrix.config.compiler }}' == 'mingw' ]; then
CMAKE_EXTRA_ARGS+=('-DCMAKE_TOOLCHAIN_FILE=scripts/Cross-MinGW-${{ steps.windows-identify.outputs.mingw-target }}.cmake')
elif [ '${{ runner.os }}' == 'macOS' ]; then

View file

@ -167,8 +167,13 @@ if (SYSTEM_SDL2)
endif()
message(STATUS "Using system-installed SDL2")
else()
set(SDL_SHARED OFF)
set(SDL_STATIC ON)
set(SDL_SHARED OFF CACHE BOOL "Force no dynamically-linked SDL" FORCE)
set(SDL_STATIC ON CACHE BOOL "Force statically-linked SDL" FORCE)
# https://github.com/libsdl-org/SDL/issues/1481
# On 2014-06-22 17:15:50 +0000, Sam Lantinga wrote:
# If you link SDL statically, you also need to define HAVE_LIBC so it builds with the C runtime that your application uses.
# This should probably go in a FAQ.
set(SDL_LIBC ON CACHE BOOL "Tell SDL that we want it to use our C runtime (required for proper static linking)" FORCE)
add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
list(APPEND DEPENDENCIES_INCLUDE_DIRS extern/SDL/include)
list(APPEND DEPENDENCIES_LIBRARIES SDL2-static)

View file

@ -1,35 +0,0 @@
From 34d3dcd98697af081625ccea7a41a3c47806c4ff Mon Sep 17 00:00:00 2001
From: OPNA2608 <christoph.neidahl@gmail.com>
Date: Mon, 28 Mar 2022 16:43:16 +0200
Subject: [PATCH] SDL: Fix MSVC static runtime linking
See https://github.com/libsdl-org/SDL/issues/3662, https://github.com/libsdl-org/SDL/issues/4258.
---
src/stdlib/SDL_stdlib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c
index 9d785aad5..dfac4d7c3 100644
--- a/src/stdlib/SDL_stdlib.c
+++ b/src/stdlib/SDL_stdlib.c
@@ -550,7 +550,7 @@ __declspec(selectany) int _fltused = 1;
#endif
/* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls */
-#if _MSC_VER >= 1400
+#if (_MSC_VER >= 1400) && !defined(_MT)
extern void *memcpy(void* dst, const void* src, size_t len);
#pragma intrinsic(memcpy)
@@ -570,7 +570,7 @@ memset(void *dst, int c, size_t len)
{
return SDL_memset(dst, c, len);
}
-#endif /* _MSC_VER >= 1400 */
+#endif /* (_MSC_VER >= 1400) && !defined(_MT) */
#ifdef _M_IX86
--
2.33.1