diff options
Diffstat (limited to 'src/contrib/SDL-2.30.2/cmake/test')
-rw-r--r-- | src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt | 124 | ||||
-rw-r--r-- | src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk | 11 | ||||
-rw-r--r-- | src/contrib/SDL-2.30.2/cmake/test/main_cli.c | 14 | ||||
-rw-r--r-- | src/contrib/SDL-2.30.2/cmake/test/main_gui.c | 28 | ||||
-rw-r--r-- | src/contrib/SDL-2.30.2/cmake/test/main_lib.c | 33 | ||||
-rwxr-xr-x | src/contrib/SDL-2.30.2/cmake/test/test_pkgconfig.sh | 51 | ||||
-rwxr-xr-x | src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.sh | 51 |
7 files changed, 312 insertions, 0 deletions
diff --git a/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt b/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt new file mode 100644 index 0000000..388e86c --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt | |||
@@ -0,0 +1,124 @@ | |||
1 | # This cmake build script is meant for verifying the various CMake configuration script. | ||
2 | |||
3 | cmake_minimum_required(VERSION 3.12) | ||
4 | project(sdl_test LANGUAGES C) | ||
5 | |||
6 | include(GenerateExportHeader) | ||
7 | |||
8 | if(ANDROID) | ||
9 | macro(add_executable NAME) | ||
10 | set(args ${ARGN}) | ||
11 | list(REMOVE_ITEM args WIN32) | ||
12 | add_library(${NAME} SHARED ${args}) | ||
13 | unset(args) | ||
14 | endmacro() | ||
15 | endif() | ||
16 | |||
17 | cmake_policy(SET CMP0074 NEW) | ||
18 | |||
19 | # Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL2 outside of sysroot | ||
20 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) | ||
21 | |||
22 | include(FeatureSummary) | ||
23 | |||
24 | option(TEST_SHARED "Test linking to shared SDL2 library" ON) | ||
25 | add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") | ||
26 | |||
27 | option(TEST_STATIC "Test linking to static SDL2 library" ON) | ||
28 | add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") | ||
29 | |||
30 | if(TEST_SHARED) | ||
31 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2) | ||
32 | if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE)) | ||
33 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) | ||
34 | endif() | ||
35 | add_executable(gui-shared WIN32 main_gui.c) | ||
36 | if(TARGET SDL2::SDL2main) | ||
37 | target_link_libraries(gui-shared PRIVATE SDL2::SDL2main) | ||
38 | endif() | ||
39 | target_link_libraries(gui-shared PRIVATE SDL2::SDL2) | ||
40 | if(WIN32) | ||
41 | add_custom_command(TARGET gui-shared POST_BUILD | ||
42 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:gui-shared>" | ||
43 | ) | ||
44 | endif() | ||
45 | |||
46 | add_library(sharedlib-shared SHARED main_lib.c) | ||
47 | target_link_libraries(sharedlib-shared PRIVATE SDL2::SDL2) | ||
48 | generate_export_header(sharedlib-shared EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
49 | target_compile_definitions(sharedlib-shared PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared_export.h\"") | ||
50 | set_target_properties(sharedlib-shared PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
51 | |||
52 | add_executable(gui-shared-vars WIN32 main_gui.c) | ||
53 | target_link_libraries(gui-shared-vars PRIVATE ${SDL2_LIBRARIES}) | ||
54 | target_include_directories(gui-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
55 | |||
56 | add_executable(cli-shared main_cli.c) | ||
57 | target_link_libraries(cli-shared PRIVATE SDL2::SDL2) | ||
58 | if(WIN32) | ||
59 | add_custom_command(TARGET cli-shared POST_BUILD | ||
60 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:cli-shared>" | ||
61 | ) | ||
62 | endif() | ||
63 | |||
64 | # SDL2_LIBRARIES does not support creating a cli SDL2 application | ||
65 | # (it is possible that SDL2main is a stub, but we don't know for sure) | ||
66 | if(NOT TARGET SDL2::SDL2main) | ||
67 | add_executable(cli-shared-vars main_cli.c) | ||
68 | target_link_libraries(cli-shared-vars PRIVATE ${SDL2_LIBRARIES}) | ||
69 | target_include_directories(cli-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
70 | endif() | ||
71 | |||
72 | add_library(sharedlib-shared-vars SHARED main_lib.c) | ||
73 | target_link_libraries(sharedlib-shared-vars PRIVATE ${SDL2_LIBRARIES}) | ||
74 | target_include_directories(sharedlib-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
75 | generate_export_header(sharedlib-shared-vars EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
76 | target_compile_definitions(sharedlib-shared-vars PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared-vars_export.h\"") | ||
77 | set_target_properties(sharedlib-shared-vars PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
78 | endif() | ||
79 | |||
80 | if(TEST_STATIC) | ||
81 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2-static) | ||
82 | if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE)) | ||
83 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) | ||
84 | endif() | ||
85 | add_executable(gui-static WIN32 main_gui.c) | ||
86 | if(TARGET SDL2::SDL2main) | ||
87 | target_link_libraries(gui-static PRIVATE SDL2::SDL2main) | ||
88 | endif() | ||
89 | target_link_libraries(gui-static PRIVATE SDL2::SDL2-static) | ||
90 | |||
91 | option(SDL_STATIC_PIC "SDL static library has been built with PIC") | ||
92 | if(SDL_STATIC_PIC OR WIN32) | ||
93 | add_library(sharedlib-static SHARED main_lib.c) | ||
94 | target_link_libraries(sharedlib-static PRIVATE SDL2::SDL2-static) | ||
95 | generate_export_header(sharedlib-static EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
96 | target_compile_definitions(sharedlib-static PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-static_export.h\"") | ||
97 | set_target_properties(sharedlib-static PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
98 | endif() | ||
99 | |||
100 | add_executable(gui-static-vars WIN32 main_gui.c) | ||
101 | target_link_libraries(gui-static-vars PRIVATE ${SDL2MAIN_LIBRARY} ${SDL2_STATIC_LIBRARIES}) | ||
102 | target_include_directories(gui-static-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
103 | |||
104 | add_executable(cli-static main_cli.c) | ||
105 | target_link_libraries(cli-static PRIVATE SDL2::SDL2-static) | ||
106 | |||
107 | # SDL2_LIBRARIES does not support creating a cli SDL2 application (when SDL2::SDL2main is available) | ||
108 | # (it is possible that SDL2main is a stub, but we don't know for sure) | ||
109 | if(NOT TARGET SDL2::SDL2main) | ||
110 | add_executable(cli-static-vars main_cli.c) | ||
111 | target_link_libraries(cli-static-vars PRIVATE ${SDL2_STATIC_LIBRARIES}) | ||
112 | target_include_directories(cli-static-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
113 | endif() | ||
114 | endif() | ||
115 | |||
116 | message(STATUS "SDL2_PREFIX: ${SDL2_PREFIX}") | ||
117 | message(STATUS "SDL2_INCLUDE_DIR: ${SDL2_INCLUDE_DIR}") | ||
118 | message(STATUS "SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}") | ||
119 | message(STATUS "SDL2_LIBRARIES: ${SDL2_LIBRARIES}") | ||
120 | message(STATUS "SDL2_STATIC_LIBRARIES: ${SDL2_STATIC_LIBRARIES}") | ||
121 | message(STATUS "SDL2MAIN_LIBRARY: ${SDL2MAIN_LIBRARY}") | ||
122 | message(STATUS "SDL2TEST_LIBRARY: ${SDL2TEST_LIBRARY}") | ||
123 | |||
124 | feature_summary(WHAT ALL) | ||
diff --git a/src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk b/src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk new file mode 100644 index 0000000..c4956d6 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk | |||
@@ -0,0 +1,11 @@ | |||
1 | LOCAL_PATH := $(call my-dir) | ||
2 | |||
3 | include $(CLEAR_VARS) | ||
4 | |||
5 | LOCAL_MODULE := main_gui_androidmk | ||
6 | LOCAL_SRC_FILES := ../main_gui.c | ||
7 | LOCAL_SHARED_LIBRARIES += SDL2 | ||
8 | include $(BUILD_SHARED_LIBRARY) | ||
9 | |||
10 | $(call import-module,SDL2main) | ||
11 | $(call import-module,SDL2) | ||
diff --git a/src/contrib/SDL-2.30.2/cmake/test/main_cli.c b/src/contrib/SDL-2.30.2/cmake/test/main_cli.c new file mode 100644 index 0000000..f6b0836 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/main_cli.c | |||
@@ -0,0 +1,14 @@ | |||
1 | #define SDL_MAIN_HANDLED | ||
2 | #include "SDL.h" | ||
3 | #include <stdio.h> | ||
4 | |||
5 | int main(int argc, char *argv[]) { | ||
6 | SDL_SetMainReady(); | ||
7 | if (SDL_Init(0) < 0) { | ||
8 | fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); | ||
9 | return 1; | ||
10 | } | ||
11 | SDL_Delay(100); | ||
12 | SDL_Quit(); | ||
13 | return 0; | ||
14 | } | ||
diff --git a/src/contrib/SDL-2.30.2/cmake/test/main_gui.c b/src/contrib/SDL-2.30.2/cmake/test/main_gui.c new file mode 100644 index 0000000..ca2d92e --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/main_gui.c | |||
@@ -0,0 +1,28 @@ | |||
1 | #include "SDL.h" | ||
2 | #include <stdio.h> | ||
3 | |||
4 | int main(int argc, char *argv[]) { | ||
5 | SDL_Window *window = NULL; | ||
6 | SDL_Surface *screenSurface = NULL; | ||
7 | if (SDL_Init(SDL_INIT_VIDEO) < 0) { | ||
8 | fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); | ||
9 | return 1; | ||
10 | } | ||
11 | window = SDL_CreateWindow( | ||
12 | "hello_sdl2", | ||
13 | SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, | ||
14 | 640, 480, | ||
15 | SDL_WINDOW_SHOWN | ||
16 | ); | ||
17 | if (!window) { | ||
18 | fprintf(stderr, "could not create window: %s\n", SDL_GetError()); | ||
19 | return 1; | ||
20 | } | ||
21 | screenSurface = SDL_GetWindowSurface(window); | ||
22 | SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xff, 0xff, 0xff)); | ||
23 | SDL_UpdateWindowSurface(window); | ||
24 | SDL_Delay(100); | ||
25 | SDL_DestroyWindow(window); | ||
26 | SDL_Quit(); | ||
27 | return 0; | ||
28 | } | ||
diff --git a/src/contrib/SDL-2.30.2/cmake/test/main_lib.c b/src/contrib/SDL-2.30.2/cmake/test/main_lib.c new file mode 100644 index 0000000..9801ed5 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/main_lib.c | |||
@@ -0,0 +1,33 @@ | |||
1 | #include "SDL.h" | ||
2 | #include <stdio.h> | ||
3 | |||
4 | #include EXPORT_HEADER | ||
5 | |||
6 | #if defined(_WIN32) | ||
7 | #include <windows.h> | ||
8 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { | ||
9 | return TRUE; | ||
10 | } | ||
11 | #endif | ||
12 | |||
13 | int MYLIBRARY_EXPORT mylibrary_init(void); | ||
14 | void MYLIBRARY_EXPORT mylibrary_quit(void); | ||
15 | int MYLIBRARY_EXPORT mylibrary_work(void); | ||
16 | |||
17 | int mylibrary_init(void) { | ||
18 | SDL_SetMainReady(); | ||
19 | if (SDL_Init(0) < 0) { | ||
20 | fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); | ||
21 | return 1; | ||
22 | } | ||
23 | return 0; | ||
24 | } | ||
25 | |||
26 | void mylibrary_quit(void) { | ||
27 | SDL_Quit(); | ||
28 | } | ||
29 | |||
30 | int mylibrary_work(void) { | ||
31 | SDL_Delay(100); | ||
32 | return 0; | ||
33 | } | ||
diff --git a/src/contrib/SDL-2.30.2/cmake/test/test_pkgconfig.sh b/src/contrib/SDL-2.30.2/cmake/test/test_pkgconfig.sh new file mode 100755 index 0000000..500cd09 --- /dev/null +++ b/src/contrib/SDL-2.30.2/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="$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 sdl2 --cflags )" | ||
29 | SDL_LDFLAGS="$( pkg-config sdl2 --libs )" | ||
30 | SDL_STATIC_LDFLAGS="$( pkg-config sdl2 --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 | ||
diff --git a/src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.sh b/src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.sh new file mode 100755 index 0000000..fa41dbb --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.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="$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="$( sdl2-config --cflags )" | ||
29 | SDL_LDFLAGS="$( sdl2-config --libs )" | ||
30 | SDL_STATIC_LDFLAGS="$( sdl2-config --static-libs )" | ||
31 | |||
32 | compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_sdlconfig.c.o $CFLAGS $SDL_CFLAGS" | ||
33 | link_cmd="$CC main_gui_sdlconfig.c.o -o ${EXEPREFIX}main_gui_sdlconfig${EXESUFFIX} $SDL_LDFLAGS $LDFLAGS" | ||
34 | static_link_cmd="$CC main_gui_sdlconfig.c.o -o ${EXEPREFIX}main_gui_sdlconfig_static${EXESUFFIX} $SDL_STATIC_LDFLAGS $LDFLAGS" | ||
35 | |||
36 | echo "-- CC: $CC" | ||
37 | echo "-- CFLAGS: $CFLAGS" | ||
38 | echo "-- LDFLAGS: $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 | ||