Skip to content

Commit

Permalink
LIBS: updated sdl2
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Oct 19, 2024
1 parent f5511c2 commit fcc9ce6
Show file tree
Hide file tree
Showing 80 changed files with 1,407 additions and 691 deletions.
48 changes: 26 additions & 22 deletions contrib/libs/sdl2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ endif()
# so we'll just use libusb when it's available. libusb does not support iOS,
# so we default to yes on iOS.
# TODO: Windows can support libusb, the hid.c file just depends on Unix APIs
if((WINDOWS AND NOT WINDOWS_STORE) OR IOS OR TVOS OR ANDROID)
if((WINDOWS AND NOT WINDOWS_STORE) OR IOS OR TVOS OR VISIONOS OR WATCHOS OR ANDROID)
set(HIDAPI_SKIP_LIBUSB TRUE)
else()
set(HIDAPI_SKIP_LIBUSB FALSE)
Expand Down Expand Up @@ -244,7 +244,7 @@ endif()
if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS OR SDL_CPU_ARM64EC)
set(OPT_DEF_LIBC ON)
endif()
if(WINDOWS OR DARWIN OR MACOSX OR IOS OR TVOS)
if(WINDOWS OR MACOS OR IOS OR TVOS OR VISIONOS OR WATCHOS)
set(SDL_SYSTEM_ICONV_DEFAULT OFF)
else()
set(SDL_SYSTEM_ICONV_DEFAULT ON)
Expand Down Expand Up @@ -2076,7 +2076,7 @@ elseif(APPLE)
# !!! FIXME: we need Carbon for some very old API calls in
# !!! FIXME: src/video/cocoa/SDL_cocoakeyboard.c, but we should figure out
# !!! FIXME: how to dump those.
if(DARWIN OR MACOSX)
if(MACOS)
set(SDL_FRAMEWORK_COCOA 1)
set(SDL_FRAMEWORK_CARBON 1)
endif()
Expand All @@ -2090,12 +2090,12 @@ elseif(APPLE)
set(HAVE_SDL_FILE TRUE)
endif()

if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/uikit/*.c)
endif()

if(SDL_MISC)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/ios/*.m)
else()
file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/macosx/*.m)
Expand All @@ -2120,10 +2120,10 @@ elseif(APPLE)

if(SDL_JOYSTICK)
file(GLOB MFI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
set(SDL_JOYSTICK_MFI 1)
if(IOS)
if(IOS OR VISIONOS OR WATCHOS)
set(SDL_FRAMEWORK_COREMOTION 1)
endif()
set(SDL_FRAMEWORK_GAMECONTROLLER 1)
Expand Down Expand Up @@ -2164,7 +2164,7 @@ elseif(APPLE)
endif()

if(SDL_HAPTIC)
if (IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
set(SDL_HAPTIC_DUMMY 1)
else()
Expand All @@ -2178,7 +2178,7 @@ elseif(APPLE)
endif()

if(SDL_POWER)
if (IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
set(SDL_POWER_UIKIT 1)
else()
Expand Down Expand Up @@ -2211,7 +2211,7 @@ elseif(APPLE)
endif()

if(SDL_SENSOR)
if(IOS)
if(IOS OR VISIONOS OR WATCHOS)
set(SDL_SENSOR_COREMOTION 1)
set(HAVE_SDL_SENSORS TRUE)
file(GLOB SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/coremotion/*.m)
Expand All @@ -2221,7 +2221,7 @@ elseif(APPLE)

# iOS hack needed - http://code.google.com/p/ios-cmake/ ?
if(SDL_VIDEO)
if (IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
set(SDL_VIDEO_DRIVER_UIKIT 1)
set(SDL_FRAMEWORK_COREGRAPHICS 1)
set(SDL_FRAMEWORK_QUARTZCORE 1)
Expand All @@ -2242,7 +2242,7 @@ elseif(APPLE)
endif()

if(SDL_OPENGLES)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
set(SDL_FRAMEWORK_OPENGLES 1)
set(SDL_VIDEO_OPENGL_ES 1)
set(SDL_VIDEO_RENDER_OGL_ES 1)
Expand Down Expand Up @@ -2345,7 +2345,7 @@ elseif(APPLE)
endif()
endif()
if(SDL_FRAMEWORK_METAL)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
list(APPEND PKGCONFIG_LDFLAGS "-Wl,-framework,Metal")
list(APPEND CMAKE_LIBS "$<LINK_LIBRARY:FRAMEWORK,Metal>")
else()
Expand All @@ -2358,7 +2358,7 @@ elseif(APPLE)
list(APPEND CMAKE_LIBS "$<LINK_LIBRARY:FRAMEWORK,OpenGLES>")
endif()
if(SDL_FRAMEWORK_QUARTZCORE)
if(IOS OR TVOS)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
list(APPEND PKGCONFIG_LDFLAGS "-Wl,-framework,QuartzCore")
list(APPEND CMAKE_LIBS "$<LINK_LIBRARY:FRAMEWORK,QuartzCore>")
else()
Expand Down Expand Up @@ -3210,9 +3210,11 @@ macro(check_add_debug_flag FLAG SUFFIX)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
endif()

check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
if (HAS_CXX_${SUFFIX})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
if(CMAKE_CXX_COMPILER)
check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
if (HAS_CXX_${SUFFIX})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
endif()
endif()
endmacro()

Expand All @@ -3231,18 +3233,20 @@ macro(asan_check_add_debug_flag2 ASAN_FLAG)

set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES})
set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan")
check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})

check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
if (HAS_C_FLAG_${ASAN_FLAG})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
endif()

if (HAS_CXX_${ASAN_FLAG})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
if(CMAKE_CXX_COMPILER)
check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
if (HAS_CXX_${ASAN_FLAG})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
endif()
endif()

set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
set(HAVE_ASAN ON)
endif()
Expand Down
2 changes: 1 addition & 1 deletion contrib/libs/sdl2/cmake/sdlchecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ macro(CheckPTHREAD)
elseif(BSDI)
set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
set(PTHREAD_LDFLAGS "")
elseif(DARWIN)
elseif(MACOS)
set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
# causes Carbon.p complaints?
# set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
Expand Down
10 changes: 6 additions & 4 deletions contrib/libs/sdl2/cmake/sdlplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ macro(SDL_DetectCMakePlatform)
set(SDL_CMAKE_PLATFORM QNX)
endif()
elseif(APPLE)
if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
set(SDL_CMAKE_PLATFORM DARWIN)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
set(SDL_CMAKE_PLATFORM MACOSX)
if(CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*")
set(SDL_CMAKE_PLATFORM MACOS)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
set(SDL_CMAKE_PLATFORM TVOS)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*")
# !!! FIXME: remove the version check when we start requiring >= 3.14.0
if(CMAKE_VERSION VERSION_LESS 3.14)
set(SDL_CMAKE_PLATFORM IOS)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES ".*watchOS.*")
set(SDL_CMAKE_PLATFORM WATCHOS)
elseif (CMAKE_SYSTEM_NAME MATCHES "visionOS")
set(SDL_CMAKE_PLATFORM VISIONOS)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
message_error("BeOS support has been removed as of SDL 2.0.2.")
Expand Down
29 changes: 28 additions & 1 deletion contrib/libs/sdl2/cmake/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library")
option(TEST_STATIC "Test linking to static SDL2 library" ON)
add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")

if(APPLE)
option(TEST_TEST "Test linking to SDL3_test library" ON)
add_feature_info("TEST_TEST" TEST_STATIC "Test linking to SDL test library")

option(TEST_FULL "Run complete SDL test suite" OFF)
add_feature_info("TEST_FULL" TEST_FULL "Build full SDL testsuite")

# FIXME: how to target ios/tvos with Swift?
# https://gitlab.kitware.com/cmake/cmake/-/issues/20104
if(APPLE AND CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*")
# multiple values for CMAKE_OSX_ARCHITECTURES not supported with Swift
list(LENGTH CMAKE_OSX_ARCHITECTURES count_osx_archs)
if(count_osx_archs LESS_EQUAL 1)
Expand Down Expand Up @@ -87,6 +95,11 @@ if(TEST_SHARED)
target_compile_definitions(sharedlib-shared-vars PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared-vars_export.h\"")
set_target_properties(sharedlib-shared-vars PROPERTIES C_VISIBILITY_PRESET "hidden")

if(TEST_TEST)
add_executable(sdltest-shared sdltest.c)
target_link_libraries(sdltest-shared PRIVATE SDL2::SDL2main SDL2::SDL2test SDL2::SDL2)
endif()

if(CMAKE_Swift_COMPILER)
add_executable(swift-shared main.swift)
target_include_directories(swift-shared PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift")
Expand Down Expand Up @@ -129,13 +142,27 @@ if(TEST_STATIC)
target_include_directories(cli-static-vars PRIVATE ${SDL2_INCLUDE_DIRS})
endif()

if(TEST_TEST)
add_executable(sdltest-static sdltest.c)
target_link_libraries(sdltest-static PRIVATE SDL2::SDL2main SDL2::SDL2test SDL2::SDL2-static)
endif()

if(CMAKE_Swift_COMPILER)
add_executable(swift-static main.swift)
target_include_directories(swift-static PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift")
target_link_libraries(swift-static PRIVATE SDL2::SDL2-static)
endif()
endif()

if(TEST_FULL)
enable_testing()
set(SDL_TESTS_TIMEOUT_MULTIPLIER "1" CACHE STRING "Test timeout multiplier")
set(SDL_TESTS_LINK_SHARED ${TEST_SHARED})

add_definitions(-DNO_BUILD_CONFIG)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../test" SDL_test)
endif()

message(STATUS "SDL2_PREFIX: ${SDL2_PREFIX}")
message(STATUS "SDL2_INCLUDE_DIR: ${SDL2_INCLUDE_DIR}")
message(STATUS "SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}")
Expand Down
12 changes: 12 additions & 0 deletions contrib/libs/sdl2/cmake/test/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */

import SDL2

guard SDL_Init(Uint32(SDL_INIT_VIDEO)) == 0 else {
fatalError("SDL_Init error: \(String(cString: SDL_GetError()))")
}

var sdlVersion = SDL_version()
SDL_GetVersion(&sdlVersion)

print("SDL version: \(sdlVersion.major).\(sdlVersion.minor).\(sdlVersion.patch)")
9 changes: 9 additions & 0 deletions contrib/libs/sdl2/cmake/test/sdltest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "SDL.h"
#include "SDL_test.h"


int main(int argc, char *argv[]) {
SDLTest_CommonState state;
SDLTest_CommonDefaultArgs(&state, argc, argv);
return 0;
}
4 changes: 4 additions & 0 deletions contrib/libs/sdl2/cmake/test/swift/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module SDL2 [extern_c] {
header "shim.h"
export *
}
3 changes: 3 additions & 0 deletions contrib/libs/sdl2/cmake/test/swift/shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */

#include "SDL.h"
7 changes: 3 additions & 4 deletions contrib/libs/sdl2/include/SDL_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ extern DECLSPEC int SDLCALL SDL_GetDefaultAudioInfo(char **name,
* frames_ (with stereo output, two samples--left and right--would make a
* single sample frame). This number should be a power of two, and may be
* adjusted by the audio driver to a value more suitable for the hardware.
* Good values seem to range between 512 and 8096 inclusive, depending on
* Good values seem to range between 512 and 4096 inclusive, depending on
* the application and CPU speed. Smaller values reduce latency, but can
* lead to underflow if the application is doing heavy processing and cannot
* fill the audio buffer in time. Note that the number of sample frames is
Expand Down Expand Up @@ -1172,9 +1172,8 @@ extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
* \param format the SDL_AudioFormat structure representing the desired audio
* format.
* \param len the length of the audio buffer in bytes.
* \param volume ranges from -128 - ∞ (at -128, the volume is at 0%, at 0 -
* 100% and the higher the number, the bigger the %), and should
* be set to SDL_MIX_MAXVOLUME for full audio volume.
* \param volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME
* for full audio volume.
*
* \since This function is available since SDL 2.0.0.
*/
Expand Down
8 changes: 8 additions & 0 deletions contrib/libs/sdl2/include/SDL_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,14 @@ typedef struct SDL_SysWMEvent

/**
* General event structure
*
* The SDL_Event structure is the core of all event handling in SDL. SDL_Event
* is a union of all event structures used in SDL. Using it is a simple matter
* of knowing which event type corresponds to which union member. The table
* below lists these relationships.
*
* The SDL_Event structure has two uses: * Reading events from the event queue
* * Placing events on the event queue
*/
typedef union SDL_Event
{
Expand Down
5 changes: 4 additions & 1 deletion contrib/libs/sdl2/include/SDL_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,10 @@ extern DECLSPEC SDL_bool SDLCALL SDL_RenderTargetSupported(SDL_Renderer *rendere
*
* The default render target is the window for which the renderer was created.
* To stop rendering to a texture and render to the window again, call this
* function with a NULL `texture`.
* function with a NULL `texture`. This will reset the renderer's viewport,
* clipping rectangle, and scaling settings to the state they were in before
* setting a non-NULL `texture` target, losing any changes made in the
* meantime.
*
* \param renderer the rendering context.
* \param texture the targeted texture, which must be created with the
Expand Down
5 changes: 4 additions & 1 deletion contrib/libs/sdl2/include/SDL_stdinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ typedef uint64_t Uint64;
#define SDL_PRIs64 "I64d"
#elif defined(PRIs64)
#define SDL_PRIs64 PRIs64
#elif defined(__LP64__) && !defined(__APPLE__)
#elif defined(__LP64__) && !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
#define SDL_PRIs64 "ld"
#else
#define SDL_PRIs64 "lld"
Expand Down Expand Up @@ -749,6 +749,9 @@ size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
#endif

/* strdup is not ANSI but POSIX, and its prototype might be hidden... */
char *strdup(const char *str);

/* Starting LLVM 16, the analyser errors out if these functions do not have
their prototype defined (clang-diagnostic-implicit-function-declaration) */
#include <stdlib.h>
Expand Down
Loading

0 comments on commit fcc9ce6

Please sign in to comment.