From b4ba2bc927bf054aebed7d24a92be2db62b6e3a3 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sun, 6 Aug 2023 20:56:09 +0200
Subject: [PATCH] Explicitly link to clang_rt.builtins with clang on Windows +
libgcc for 32-bit
---
CMakeLists.txt | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56ace1b..8162a1d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -265,8 +265,18 @@ else()
endif()
if(MINGW)
- target_link_libraries(SDL2 PRIVATE -nostdlib)
- target_link_libraries(SDL2 PRIVATE -static-libgcc -lgcc) # libgcc is needed for 32 bit (x86) builds
+ set_property(TARGET SDL2 APPEND_STRING PROPERTY LINK_FLAGS " -nostdlib")
+ if(USE_CLANG)
+ if(SDL_CPU_X86)
+ target_link_libraries(SDL2 PRIVATE clang_rt.builtins-i386)
+ endif()
+ else()
+ if(SDL_CPU_X86 OR SDL_CPU_ARM32)
+ # 32-bit architectures need libgcc for emulating 64-bit operations (e.g. 64-bit division)
+ target_link_libraries(SDL2 PRIVATE gcc)
+ set_property(TARGET SDL2 APPEND_STRING PROPERTY LINK_FALGS " -static-libgcc")
+ endif()
+ endif()
endif()
if(MSVC)
# Don't try to link with the default set of libraries.