summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/cmake/test
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
committer3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
commit6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch)
tree34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/cmake/test
parent8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff)
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/cmake/test')
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/CMakeLists.txt135
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/inc_sdl_slash.c8
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/main.swift13
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/main_cli.c15
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/main_gui.c24
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/main_lib.c34
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/sdltest.c9
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/swift/module.modulemap4
-rw-r--r--src/contrib/SDL-3.2.20/cmake/test/swift/shim.h3
-rwxr-xr-xsrc/contrib/SDL-3.2.20/cmake/test/test_pkgconfig.sh51
10 files changed, 296 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/cmake/test/CMakeLists.txt b/src/contrib/SDL-3.2.20/cmake/test/CMakeLists.txt
new file mode 100644
index 0000000..e3766f0
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/CMakeLists.txt
@@ -0,0 +1,135 @@
1# This cmake build script is meant for verifying the various CMake configuration scripts.
2
3cmake_minimum_required(VERSION 3.12)
4project(SDL_cmake_selftest LANGUAGES C)
5
6include(CheckLanguage)
7
8# FIXME: how to target ios/tvos with Swift?
9# https://gitlab.kitware.com/cmake/cmake/-/issues/20104
10if(APPLE AND CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*")
11 # multiple values for CMAKE_OSX_ARCHITECTURES not supported with Swift
12 list(LENGTH CMAKE_OSX_ARCHITECTURES count_osx_archs)
13 if(count_osx_archs LESS_EQUAL 1)
14 check_language(Swift)
15 if(CMAKE_Swift_COMPILER)
16 enable_language(Swift)
17 endif()
18 endif()
19endif()
20
21message(STATUS "CMAKE_SYSTEM_NAME= ${CMAKE_SYSTEM_NAME}")
22message(STATUS "CMAKE_SYSTEM_PROCESSOR= ${CMAKE_SYSTEM_PROCESSOR}")
23
24include(GenerateExportHeader)
25
26if(ANDROID)
27 macro(add_executable NAME)
28 set(args ${ARGN})
29 list(REMOVE_ITEM args WIN32)
30 add_library(${NAME} SHARED ${args})
31 unset(args)
32 endmacro()
33endif()
34
35cmake_policy(SET CMP0074 NEW)
36
37# Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3 outside of sysroot
38set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
39
40include(FeatureSummary)
41
42option(TEST_SHARED "Test linking to shared SDL3 library" ON)
43add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library")
44
45option(TEST_STATIC "Test linking to static SDL3 library" ON)
46add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")
47
48option(TEST_TEST "Test linking to SDL3_test library" ON)
49add_feature_info("TEST_TEST" TEST_STATIC "Test linking to SDL test library")
50
51option(TEST_FULL "Run complete SDL test suite" OFF)
52add_feature_info("TEST_FULL" TEST_FULL "Build full SDL testsuite")
53
54find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers)
55add_library(headers_test_slash OBJECT inc_sdl_slash.c)
56target_link_libraries(headers_test_slash PRIVATE SDL3::Headers)
57
58if(TEST_SHARED)
59 find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-shared)
60 add_executable(gui-shared WIN32 main_gui.c)
61 target_link_libraries(gui-shared PRIVATE SDL3::SDL3-shared)
62 if(WIN32)
63 add_custom_command(TARGET gui-shared POST_BUILD
64 COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:gui-shared>"
65 )
66 endif()
67
68 add_library(sharedlib-shared SHARED main_lib.c)
69 target_link_libraries(sharedlib-shared PRIVATE SDL3::SDL3-shared)
70 generate_export_header(sharedlib-shared EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
71 target_compile_definitions(sharedlib-shared PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared_export.h\"")
72 set_target_properties(sharedlib-shared PROPERTIES C_VISIBILITY_PRESET "hidden")
73
74 add_executable(cli-shared main_cli.c)
75 target_link_libraries(cli-shared PRIVATE SDL3::SDL3-shared)
76 if(WIN32)
77 add_custom_command(TARGET cli-shared POST_BUILD
78 COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:cli-shared>"
79 )
80 endif()
81
82 if(TEST_TEST)
83 add_executable(sdltest-shared sdltest.c)
84 target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared)
85 endif()
86
87 if(CMAKE_Swift_COMPILER)
88 add_executable(swift-shared main.swift)
89 target_include_directories(swift-shared PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift")
90 target_link_libraries(swift-shared PRIVATE SDL3::SDL3-shared)
91 endif()
92endif()
93
94if(TEST_STATIC)
95 find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-static)
96 add_executable(gui-static WIN32 main_gui.c)
97 target_link_libraries(gui-static PRIVATE SDL3::SDL3-static)
98
99 # Assume SDL library has been built with `set(CMAKE_POSITION_INDEPENDENT_CODE ON)`
100 add_library(sharedlib-static SHARED main_lib.c)
101 target_link_libraries(sharedlib-static PRIVATE SDL3::SDL3-static)
102 generate_export_header(sharedlib-static EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
103 target_compile_definitions(sharedlib-static PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-static_export.h\"")
104 set_target_properties(sharedlib-static PROPERTIES C_VISIBILITY_PRESET "hidden")
105
106 if(TEST_TEST)
107 add_executable(sdltest-static sdltest.c)
108 target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static)
109 endif()
110
111 if(CMAKE_Swift_COMPILER)
112 add_executable(swift-static main.swift)
113 target_include_directories(swift-static PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift")
114 target_link_libraries(swift-static PRIVATE SDL3::SDL3-static)
115 endif()
116endif()
117
118find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3)
119add_executable(gui-whatever WIN32 main_gui.c)
120target_link_libraries(gui-whatever PRIVATE SDL3::SDL3)
121
122if(TEST_FULL)
123 enable_testing()
124 set(SDL_TESTS_TIMEOUT_MULTIPLIER "1" CACHE STRING "Test timeout multiplier")
125 set(SDL_TESTS_LINK_SHARED ${TEST_SHARED})
126
127 add_definitions(-DNO_BUILD_CONFIG)
128 add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../test" SDL_test)
129endif()
130
131if(ANDROID)
132 find_package(SDL3 REQUIRED CONFIG COMPONENTS Jar)
133endif()
134
135feature_summary(WHAT ALL)
diff --git a/src/contrib/SDL-3.2.20/cmake/test/inc_sdl_slash.c b/src/contrib/SDL-3.2.20/cmake/test/inc_sdl_slash.c
new file mode 100644
index 0000000..7acca15
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/inc_sdl_slash.c
@@ -0,0 +1,8 @@
1#include "SDL3/SDL.h"
2#include "SDL3/SDL_main.h"
3
4void inc_sdl_slash(void) {
5 SDL_SetMainReady();
6 SDL_Init(0);
7 SDL_Quit();
8}
diff --git a/src/contrib/SDL-3.2.20/cmake/test/main.swift b/src/contrib/SDL-3.2.20/cmake/test/main.swift
new file mode 100644
index 0000000..1943f7c
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/main.swift
@@ -0,0 +1,13 @@
1/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */
2
3import SDL3
4
5guard SDL_Init(SDL_INIT_VIDEO) else {
6 fatalError("SDL_Init error: \(String(cString: SDL_GetError()))")
7}
8
9var sdlVersion = SDL_GetVersion()
10
11print("SDL version: \(sdlVersion)")
12
13SDL_Quit()
diff --git a/src/contrib/SDL-3.2.20/cmake/test/main_cli.c b/src/contrib/SDL-3.2.20/cmake/test/main_cli.c
new file mode 100644
index 0000000..39c5ce2
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/main_cli.c
@@ -0,0 +1,15 @@
1#define SDL_MAIN_HANDLED
2#include <SDL3/SDL.h>
3#include <SDL3/SDL_main.h>
4
5int main(int argc, char *argv[])
6{
7 SDL_SetMainReady();
8 if (!SDL_Init(0)) {
9 SDL_Log("Could not initialize SDL: %s", SDL_GetError());
10 return 1;
11 }
12 SDL_Delay(100);
13 SDL_Quit();
14 return 0;
15}
diff --git a/src/contrib/SDL-3.2.20/cmake/test/main_gui.c b/src/contrib/SDL-3.2.20/cmake/test/main_gui.c
new file mode 100644
index 0000000..18ed101
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/main_gui.c
@@ -0,0 +1,24 @@
1#include <SDL3/SDL.h>
2#include <SDL3/SDL_main.h>
3
4int main(int argc, char *argv[])
5{
6 SDL_Window *window = NULL;
7 SDL_Surface *screenSurface = NULL;
8 if (!SDL_Init(SDL_INIT_VIDEO)) {
9 SDL_Log("Could not initialize SDL: %s", SDL_GetError());
10 return 1;
11 }
12 window = SDL_CreateWindow("Hello SDL", 640, 480, 0);
13 if (!window) {
14 SDL_Log("could not create window: %s", SDL_GetError());
15 return 1;
16 }
17 screenSurface = SDL_GetWindowSurface(window);
18 SDL_FillSurfaceRect(screenSurface, NULL, SDL_MapSurfaceRGB(screenSurface, 0xff, 0xff, 0xff));
19 SDL_UpdateWindowSurface(window);
20 SDL_Delay(100);
21 SDL_DestroyWindow(window);
22 SDL_Quit();
23 return 0;
24}
diff --git a/src/contrib/SDL-3.2.20/cmake/test/main_lib.c b/src/contrib/SDL-3.2.20/cmake/test/main_lib.c
new file mode 100644
index 0000000..6aec1f6
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/main_lib.c
@@ -0,0 +1,34 @@
1#include <SDL3/SDL.h>
2#define SDL_MAIN_HANDLED /* don't drag in header-only SDL_main implementation */
3#include <SDL3/SDL_main.h>
4
5#include EXPORT_HEADER
6
7#ifdef _WIN32
8#include <windows.h>
9BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
10 return TRUE;
11}
12#endif
13
14int MYLIBRARY_EXPORT mylibrary_init(void);
15void MYLIBRARY_EXPORT mylibrary_quit(void);
16int MYLIBRARY_EXPORT mylibrary_work(void);
17
18int mylibrary_init(void) {
19 SDL_SetMainReady();
20 if (!SDL_Init(0)) {
21 SDL_Log("Could not initialize SDL: %s", SDL_GetError());
22 return 1;
23 }
24 return 0;
25}
26
27void mylibrary_quit(void) {
28 SDL_Quit();
29}
30
31int mylibrary_work(void) {
32 SDL_Delay(100);
33 return 0;
34}
diff --git a/src/contrib/SDL-3.2.20/cmake/test/sdltest.c b/src/contrib/SDL-3.2.20/cmake/test/sdltest.c
new file mode 100644
index 0000000..f598a98
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/sdltest.c
@@ -0,0 +1,9 @@
1#include <SDL3/SDL.h>
2#include <SDL3/SDL_test.h>
3
4
5int main(int argc, char *argv[]) {
6 SDLTest_CommonState state;
7 SDLTest_CommonDefaultArgs(&state, argc, argv);
8 return 0;
9}
diff --git a/src/contrib/SDL-3.2.20/cmake/test/swift/module.modulemap b/src/contrib/SDL-3.2.20/cmake/test/swift/module.modulemap
new file mode 100644
index 0000000..bbc26a9
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/swift/module.modulemap
@@ -0,0 +1,4 @@
1module SDL3 [extern_c] {
2 header "shim.h"
3 export *
4}
diff --git a/src/contrib/SDL-3.2.20/cmake/test/swift/shim.h b/src/contrib/SDL-3.2.20/cmake/test/swift/shim.h
new file mode 100644
index 0000000..dba8c6f
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/swift/shim.h
@@ -0,0 +1,3 @@
1/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */
2
3#include <SDL3/SDL.h>
diff --git a/src/contrib/SDL-3.2.20/cmake/test/test_pkgconfig.sh b/src/contrib/SDL-3.2.20/cmake/test/test_pkgconfig.sh
new file mode 100755
index 0000000..5bb84df
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/test/test_pkgconfig.sh
@@ -0,0 +1,51 @@
1#!/bin/sh
2
3if test "x$CC" = "x"; then
4 CC=cc
5fi
6
7machine="$($CC -dumpmachine)"
8case "$machine" in
9 *mingw* )
10 EXEPREFIX=""
11 EXESUFFIX=".exe"
12 ;;
13 *android* )
14 EXEPREFIX="lib"
15 EXESUFFIX=".so"
16 LDFLAGS="$EXTRA_LDFLAGS -shared"
17 ;;
18 * )
19 EXEPREFIX=""
20 EXESUFFIX=""
21 ;;
22esac
23
24set -e
25
26# Get the canonical path of the folder containing this script
27testdir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
28SDL_CFLAGS="$( pkg-config sdl3 --cflags )"
29SDL_LDFLAGS="$( pkg-config sdl3 --libs )"
30SDL_STATIC_LDFLAGS="$( pkg-config sdl3 --libs --static )"
31
32compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_pkgconfig.c.o $SDL_CFLAGS $CFLAGS"
33link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig${EXESUFFIX} $SDL_LDFLAGS $LDFLAGS"
34static_link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig_static${EXESUFFIX} $SDL_STATIC_LDFLAGS $LDFLAGS"
35
36echo "-- CC: $CC"
37echo "-- CFLAGS: $CFLAGS"
38echo "-- LDFLASG: $LDFLAGS"
39echo "-- SDL_CFLAGS: $SDL_CFLAGS"
40echo "-- SDL_LDFLAGS: $SDL_LDFLAGS"
41echo "-- SDL_STATIC_LDFLAGS: $SDL_STATIC_LDFLAGS"
42
43echo "-- COMPILE: $compile_cmd"
44echo "-- LINK: $link_cmd"
45echo "-- STATIC_LINK: $static_link_cmd"
46
47set -x
48
49$compile_cmd
50$link_cmd
51$static_link_cmd