diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/cmake/test')
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/CMakeLists.txt | 135 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/inc_sdl_slash.c | 8 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/main.swift | 13 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/main_cli.c | 15 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/main_gui.c | 24 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/main_lib.c | 34 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/sdltest.c | 9 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/swift/module.modulemap | 4 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/cmake/test/swift/shim.h | 3 | ||||
-rwxr-xr-x | src/contrib/SDL-3.2.20/cmake/test/test_pkgconfig.sh | 51 |
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 | |||
3 | cmake_minimum_required(VERSION 3.12) | ||
4 | project(SDL_cmake_selftest LANGUAGES C) | ||
5 | |||
6 | include(CheckLanguage) | ||
7 | |||
8 | # FIXME: how to target ios/tvos with Swift? | ||
9 | # https://gitlab.kitware.com/cmake/cmake/-/issues/20104 | ||
10 | if(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() | ||
19 | endif() | ||
20 | |||
21 | message(STATUS "CMAKE_SYSTEM_NAME= ${CMAKE_SYSTEM_NAME}") | ||
22 | message(STATUS "CMAKE_SYSTEM_PROCESSOR= ${CMAKE_SYSTEM_PROCESSOR}") | ||
23 | |||
24 | include(GenerateExportHeader) | ||
25 | |||
26 | if(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() | ||
33 | endif() | ||
34 | |||
35 | cmake_policy(SET CMP0074 NEW) | ||
36 | |||
37 | # Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3 outside of sysroot | ||
38 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) | ||
39 | |||
40 | include(FeatureSummary) | ||
41 | |||
42 | option(TEST_SHARED "Test linking to shared SDL3 library" ON) | ||
43 | add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") | ||
44 | |||
45 | option(TEST_STATIC "Test linking to static SDL3 library" ON) | ||
46 | add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") | ||
47 | |||
48 | option(TEST_TEST "Test linking to SDL3_test library" ON) | ||
49 | add_feature_info("TEST_TEST" TEST_STATIC "Test linking to SDL test library") | ||
50 | |||
51 | option(TEST_FULL "Run complete SDL test suite" OFF) | ||
52 | add_feature_info("TEST_FULL" TEST_FULL "Build full SDL testsuite") | ||
53 | |||
54 | find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers) | ||
55 | add_library(headers_test_slash OBJECT inc_sdl_slash.c) | ||
56 | target_link_libraries(headers_test_slash PRIVATE SDL3::Headers) | ||
57 | |||
58 | if(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() | ||
92 | endif() | ||
93 | |||
94 | if(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() | ||
116 | endif() | ||
117 | |||
118 | find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3) | ||
119 | add_executable(gui-whatever WIN32 main_gui.c) | ||
120 | target_link_libraries(gui-whatever PRIVATE SDL3::SDL3) | ||
121 | |||
122 | if(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) | ||
129 | endif() | ||
130 | |||
131 | if(ANDROID) | ||
132 | find_package(SDL3 REQUIRED CONFIG COMPONENTS Jar) | ||
133 | endif() | ||
134 | |||
135 | feature_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 | |||
4 | void 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 | |||
3 | import SDL3 | ||
4 | |||
5 | guard SDL_Init(SDL_INIT_VIDEO) else { | ||
6 | fatalError("SDL_Init error: \(String(cString: SDL_GetError()))") | ||
7 | } | ||
8 | |||
9 | var sdlVersion = SDL_GetVersion() | ||
10 | |||
11 | print("SDL version: \(sdlVersion)") | ||
12 | |||
13 | SDL_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 | |||
5 | int 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 | |||
4 | int 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> | ||
9 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { | ||
10 | return TRUE; | ||
11 | } | ||
12 | #endif | ||
13 | |||
14 | int MYLIBRARY_EXPORT mylibrary_init(void); | ||
15 | void MYLIBRARY_EXPORT mylibrary_quit(void); | ||
16 | int MYLIBRARY_EXPORT mylibrary_work(void); | ||
17 | |||
18 | int 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 | |||
27 | void mylibrary_quit(void) { | ||
28 | SDL_Quit(); | ||
29 | } | ||
30 | |||
31 | int 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 | |||
5 | int 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 @@ | |||
1 | module 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 | |||
3 | if test "x$CC" = "x"; then | ||
4 | CC=cc | ||
5 | fi | ||
6 | |||
7 | machine="$($CC -dumpmachine)" | ||
8 | case "$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 | ;; | ||
22 | esac | ||
23 | |||
24 | set -e | ||
25 | |||
26 | # Get the canonical path of the folder containing this script | ||
27 | testdir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)") | ||
28 | SDL_CFLAGS="$( pkg-config sdl3 --cflags )" | ||
29 | SDL_LDFLAGS="$( pkg-config sdl3 --libs )" | ||
30 | SDL_STATIC_LDFLAGS="$( pkg-config sdl3 --libs --static )" | ||
31 | |||
32 | compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_pkgconfig.c.o $SDL_CFLAGS $CFLAGS" | ||
33 | link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig${EXESUFFIX} $SDL_LDFLAGS $LDFLAGS" | ||
34 | static_link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig_static${EXESUFFIX} $SDL_STATIC_LDFLAGS $LDFLAGS" | ||
35 | |||
36 | echo "-- CC: $CC" | ||
37 | echo "-- CFLAGS: $CFLAGS" | ||
38 | echo "-- LDFLASG: $LDFLAGS" | ||
39 | echo "-- SDL_CFLAGS: $SDL_CFLAGS" | ||
40 | echo "-- SDL_LDFLAGS: $SDL_LDFLAGS" | ||
41 | echo "-- SDL_STATIC_LDFLAGS: $SDL_STATIC_LDFLAGS" | ||
42 | |||
43 | echo "-- COMPILE: $compile_cmd" | ||
44 | echo "-- LINK: $link_cmd" | ||
45 | echo "-- STATIC_LINK: $static_link_cmd" | ||
46 | |||
47 | set -x | ||
48 | |||
49 | $compile_cmd | ||
50 | $link_cmd | ||
51 | $static_link_cmd | ||