diff options
author | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
commit | 6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch) | |
tree | 34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/test/CMakeLists.txt | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/CMakeLists.txt')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/CMakeLists.txt | 804 |
1 files changed, 804 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/CMakeLists.txt b/src/contrib/SDL-3.2.20/test/CMakeLists.txt new file mode 100644 index 0000000..8bf5c25 --- /dev/null +++ b/src/contrib/SDL-3.2.20/test/CMakeLists.txt | |||
@@ -0,0 +1,804 @@ | |||
1 | # | ||
2 | # CMake script for building the SDL tests | ||
3 | # | ||
4 | |||
5 | cmake_minimum_required(VERSION 3.16) | ||
6 | |||
7 | set(SDL3_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..") | ||
8 | |||
9 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake") | ||
10 | |||
11 | include(CheckIncludeFile) | ||
12 | include(CheckStructHasMember) | ||
13 | include(CMakePushCheckState) | ||
14 | include(sdlcompilers) | ||
15 | |||
16 | find_package(Python3 COMPONENTS Interpreter) | ||
17 | if(NOT PYTHON3_EXECUTABLE) | ||
18 | set(PYTHON3_EXECUTABLE "python3") | ||
19 | endif() | ||
20 | |||
21 | if(SDL_TESTS_LINK_SHARED) | ||
22 | set(sdl_name_component SDL3-shared) | ||
23 | else() | ||
24 | set(sdl_name_component SDL3-static) | ||
25 | endif() | ||
26 | set(HAVE_TESTS_LINK_SHARED "${SDL_TESTS_LINK_SHARED}" PARENT_SCOPE) | ||
27 | |||
28 | # CMake incorrectly detects opengl32.lib being present on MSVC ARM64 | ||
29 | if(NOT (MSVC AND SDL_CPU_ARM64)) | ||
30 | # Prefer GLVND, if present | ||
31 | set(OpenGL_GL_PREFERENCE GLVND) | ||
32 | find_package(OpenGL) | ||
33 | endif() | ||
34 | |||
35 | set(SDL_TEST_EXECUTABLES) | ||
36 | |||
37 | add_library(sdltests_utils OBJECT | ||
38 | testutils.c | ||
39 | ) | ||
40 | target_link_libraries(sdltests_utils PRIVATE SDL3::Headers) | ||
41 | |||
42 | file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt) | ||
43 | |||
44 | option(SDLTEST_TRACKMEM "Run tests with --trackmem" OFF) | ||
45 | |||
46 | if(WIN32) | ||
47 | option(SDLTEST_PROCDUMP "Run tests using sdlprocdump for minidump generation" OFF) | ||
48 | add_executable(sdlprocdump win32/sdlprocdump.c) | ||
49 | set_property(TARGET sdlprocdump PROPERTY C_STANDARD "90") | ||
50 | SDL_AddCommonCompilerFlags(sdlprocdump) | ||
51 | if(SDLTEST_PROCDUMP) | ||
52 | set(CMAKE_TEST_LAUNCHER "$<TARGET_FILE:sdlprocdump>;--") | ||
53 | else() | ||
54 | set_property(TARGET sdlprocdump PROPERTY EXCLUDE_FROM_ALL "1") | ||
55 | endif() | ||
56 | endif() | ||
57 | |||
58 | if(EMSCRIPTEN) | ||
59 | set(SDLTEST_BROWSER "firefox" CACHE STRING "Browser in which to run SDL unit tests (chrome or firefox)") | ||
60 | set(SDLTEST_PORT "8080" CACHE STRING "Port on which to serve the tests") | ||
61 | set(SDLTEST_CHROME_BINARY "" CACHE STRING "Chrome/Chromium browser binary (optional)") | ||
62 | if(TARGET Python3::Interpreter) | ||
63 | add_custom_target(serve-sdl-tests | ||
64 | COMMAND Python3::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/emscripten/server.py" | ||
65 | "${SDLTEST_PORT}" | ||
66 | -d "${CMAKE_CURRENT_BINARY_DIR}" | ||
67 | --map "${SDL3_SOURCE_DIR}:/SDL") | ||
68 | endif() | ||
69 | endif() | ||
70 | |||
71 | if(CMAKE_RUNTIME_OUTPUT_DIRECTORY) | ||
72 | set(test_bin_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") | ||
73 | if(NOT IS_ABSOLUTE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") | ||
74 | set(test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") | ||
75 | endif() | ||
76 | else() | ||
77 | set(test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}") | ||
78 | endif() | ||
79 | if(NOT CMAKE_VERSION VERSION_LESS 3.20) | ||
80 | get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) | ||
81 | set(test_bin_dir "${test_bin_dir}$<$<BOOL:${is_multi_config}>:/$<CONFIG>>") | ||
82 | endif() | ||
83 | |||
84 | set(RESOURCE_FILE_NAMES) | ||
85 | set(RESOURCE_FILES_BINDIR) | ||
86 | foreach(resource_file IN LISTS RESOURCE_FILES) | ||
87 | get_filename_component(res_file_name ${resource_file} NAME) | ||
88 | list(APPEND RESOURCE_FILE_NAMES "${res_file_name}") | ||
89 | set(resource_file_bindir "${test_bin_dir}/${res_file_name}") | ||
90 | add_custom_command(OUTPUT "${resource_file_bindir}" | ||
91 | COMMAND "${CMAKE_COMMAND}" -E copy "${resource_file}" "${resource_file_bindir}" | ||
92 | DEPENDS "${resource_file}" | ||
93 | ) | ||
94 | list(APPEND RESOURCE_FILES_BINDIR "${resource_file_bindir}") | ||
95 | endforeach() | ||
96 | add_custom_target(copy-sdl-test-resources | ||
97 | DEPENDS "${RESOURCE_FILES_BINDIR}" | ||
98 | ) | ||
99 | |||
100 | define_property(TARGET PROPERTY SDL_NONINTERACTIVE BRIEF_DOCS "If true, target is a non-interactive test executable." FULL_DOCS "If true, target is a noninteractive test executable.") | ||
101 | define_property(TARGET PROPERTY SDL_NONINTERACTIVE_ARGUMENTS BRIEF_DOCS "Argument(s) to run executable in non-interactive mode." FULL_DOCS "Argument(s) to run executable in non-interactive mode.") | ||
102 | define_property(TARGET PROPERTY SDL_NONINTERACTIVE_TIMEOUT BRIEF_DOCS "Timeout for noninteractive executable." FULL_DOCS "Timeout for noninteractive executable.") | ||
103 | |||
104 | macro(add_sdl_test_executable TARGET) | ||
105 | cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;THREADS;NO_C90;MAIN_CALLBACKS;NOTRACKMEM" "" "DEPENDS;DISABLE_THREADS_ARGS;NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;INSTALLED_ARGS;SOURCES" ${ARGN}) | ||
106 | if(AST_UNPARSED_ARGUMENTS) | ||
107 | message(FATAL_ERROR "Unknown argument(s): ${AST_UNPARSED_ARGUMENTS}") | ||
108 | endif() | ||
109 | if(NOT AST_SOURCES) | ||
110 | message(FATAL_ERROR "add_sdl_test_executable needs at least one source") | ||
111 | endif() | ||
112 | if(AST_TESTUTILS) | ||
113 | list(APPEND AST_SOURCES $<TARGET_OBJECTS:sdltests_utils>) | ||
114 | endif() | ||
115 | set(EXTRA_SOURCES "") | ||
116 | if(AST_NEEDS_RESOURCES) | ||
117 | list(APPEND EXTRA_SOURCES ${RESOURCE_FILES}) | ||
118 | endif() | ||
119 | if(ANDROID) | ||
120 | add_library(${TARGET} SHARED ${AST_SOURCES} ${EXTRA_SOURCES}) | ||
121 | else() | ||
122 | add_executable(${TARGET} ${AST_SOURCES} ${EXTRA_SOURCES}) | ||
123 | endif() | ||
124 | target_compile_definitions(${TARGET} PRIVATE HAVE_BUILD_CONFIG) | ||
125 | SDL_AddCommonCompilerFlags(${TARGET}) | ||
126 | target_include_directories(${TARGET} PRIVATE "${SDL3_SOURCE_DIR}/src/video/khronos") | ||
127 | target_link_libraries(${TARGET} PRIVATE SDL3::SDL3_test SDL3::${sdl_name_component}) | ||
128 | if(NOT AST_NO_C90 AND NOT SDL_CMAKE_PLATFORM MATCHES "^(n3ds|ps2|psp)$") | ||
129 | set_property(TARGET ${TARGET} PROPERTY C_STANDARD 90) | ||
130 | set_property(TARGET ${TARGET} PROPERTY C_EXTENSIONS FALSE) | ||
131 | endif() | ||
132 | if(AST_DEPENDS) | ||
133 | add_dependencies(${TARGET} ${AST_DEPENDS}) | ||
134 | endif() | ||
135 | |||
136 | list(APPEND SDL_TEST_EXECUTABLES ${TARGET}) | ||
137 | set_property(TARGET ${TARGET} PROPERTY SDL_NOTRACKMEM ${AST_NOTRACKMEM}) | ||
138 | if(AST_NONINTERACTIVE) | ||
139 | set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE 1) | ||
140 | endif() | ||
141 | set_property(TARGET ${TARGET} PROPERTY SDL_DISABLE_THREADS_ARGS "${AST_DISABLE_THREADS_ARGS}") | ||
142 | set_property(TARGET ${TARGET} PROPERTY SDL_THREADS "${AST_THREADS}") | ||
143 | if(AST_NONINTERACTIVE_ARGS) | ||
144 | set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS "${AST_NONINTERACTIVE_ARGS}") | ||
145 | endif() | ||
146 | if(AST_INSTALLED_ARGS) | ||
147 | set_property(TARGET ${TARGET} PROPERTY SDL_INSTALLED_ARGUMENTS "${AST_INSTALLED_ARGS}") | ||
148 | elseif(AST_NONINTERACTIVE_ARGS) | ||
149 | set_property(TARGET ${TARGET} PROPERTY SDL_INSTALLED_ARGUMENTS "${AST_NONINTERACTIVE_ARGS}") | ||
150 | endif() | ||
151 | if(AST_NONINTERACTIVE_TIMEOUT) | ||
152 | set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_TIMEOUT "${AST_NONINTERACTIVE_TIMEOUT}") | ||
153 | endif() | ||
154 | if(AST_NEEDS_RESOURCES) | ||
155 | if(PSP OR PS2 OR N3DS) | ||
156 | add_custom_command(TARGET ${TARGET} POST_BUILD | ||
157 | COMMAND ${CMAKE_COMMAND} ARGS -E make_directory $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET} | ||
158 | COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET}) | ||
159 | else() | ||
160 | add_dependencies(${TARGET} copy-sdl-test-resources) | ||
161 | endif() | ||
162 | if(APPLE) | ||
163 | # Make sure resource files get installed into macOS/iOS .app bundles. | ||
164 | set_target_properties(${TARGET} PROPERTIES RESOURCE "${RESOURCE_FILES}") | ||
165 | endif() | ||
166 | if(EMSCRIPTEN) | ||
167 | foreach(res IN LISTS RESOURCE_FILES) | ||
168 | get_filename_component(res_name "${res}" NAME) | ||
169 | target_link_options(${TARGET} PRIVATE "SHELL:--embed-file ${res}@${res_name}") | ||
170 | set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${res}") | ||
171 | endforeach() | ||
172 | endif() | ||
173 | set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES "$<TARGET_FILE_DIR:${TARGET}>/$<JOIN:${RESOURCE_FILE_NAMES},$<SEMICOLON>$<TARGET_FILE_DIR:${TARGET}>/>") | ||
174 | endif() | ||
175 | if(AST_BUILD_DEPENDENT) | ||
176 | target_include_directories(${TARGET} BEFORE PRIVATE $<TARGET_PROPERTY:SDL3::${sdl_name_component},INCLUDE_DIRECTORIES>) | ||
177 | target_include_directories(${TARGET} BEFORE PRIVATE ${SDL3_SOURCE_DIR}/src) | ||
178 | if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20") | ||
179 | target_include_directories(${TARGET} AFTER PRIVATE "${SDL3_SOURCE_DIR}/include/build_config") | ||
180 | endif() | ||
181 | endif() | ||
182 | |||
183 | if(WINDOWS) | ||
184 | # CET support was added in VS 16.7 | ||
185 | if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64") | ||
186 | set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -CETCOMPAT") | ||
187 | endif() | ||
188 | elseif(PSP) | ||
189 | target_link_libraries(${TARGET} PRIVATE GL) | ||
190 | elseif(EMSCRIPTEN) | ||
191 | set_property(TARGET ${TARGET} PROPERTY SUFFIX ".html") | ||
192 | target_link_options(${TARGET} PRIVATE "SHELL:--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/emscripten/pre.js") | ||
193 | target_link_options(${TARGET} PRIVATE "-sEXIT_RUNTIME=1") | ||
194 | set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/emscripten/pre.js") | ||
195 | endif() | ||
196 | |||
197 | if(OPENGL_FOUND) | ||
198 | target_compile_definitions(${TARGET} PRIVATE HAVE_OPENGL) | ||
199 | endif() | ||
200 | |||
201 | # FIXME: only add "${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>" + include paths of external dependencies | ||
202 | target_include_directories(${TARGET} PRIVATE "$<TARGET_PROPERTY:SDL3::${sdl_name_component},INCLUDE_DIRECTORIES>") | ||
203 | endmacro() | ||
204 | |||
205 | check_include_file(signal.h HAVE_SIGNAL_H) | ||
206 | if(HAVE_SIGNAL_H) | ||
207 | add_definitions(-DHAVE_SIGNAL_H) | ||
208 | endif() | ||
209 | |||
210 | check_include_file(libudev.h HAVE_LIBUDEV_H) | ||
211 | if(HAVE_LIBUDEV_H) | ||
212 | add_definitions(-DHAVE_LIBUDEV_H) | ||
213 | endif() | ||
214 | |||
215 | function(files2headers OUTPUT) | ||
216 | set(xxd "${SDL3_SOURCE_DIR}/cmake/xxd.py") | ||
217 | set(inputs ${ARGN}) | ||
218 | set(outputs ) | ||
219 | foreach(input IN LISTS inputs) | ||
220 | get_filename_component(file_we "${input}" NAME_WE) | ||
221 | set(intermediate "${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h") | ||
222 | set(output "${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.h") | ||
223 | list(APPEND outputs "${output}") | ||
224 | if(TARGET Python3::Interpreter AND NOT CMAKE_CROSSCOMPILING) | ||
225 | list(APPEND outputs "${intermediate}") | ||
226 | # Don't add the 'output' header to the output, to avoid marking them as GENERATED | ||
227 | # (generated files are removed when running the CLEAN target) | ||
228 | add_custom_command(OUTPUT "${intermediate}" | ||
229 | COMMAND Python3::Interpreter "${xxd}" -i "${CMAKE_CURRENT_SOURCE_DIR}/${input}" "-o" "${intermediate}" | ||
230 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${intermediate}" "${output}" | ||
231 | DEPENDS "${xxd}" "${bmp}" | ||
232 | ) | ||
233 | endif() | ||
234 | endforeach() | ||
235 | set(${OUTPUT} "${outputs}" PARENT_SCOPE) | ||
236 | add_custom_target(generate-${OUTPUT} DEPENDS ${outputs}) | ||
237 | endfunction() | ||
238 | |||
239 | files2headers(gamepad_image_headers | ||
240 | gamepad_axis_arrow.bmp | ||
241 | gamepad_axis.bmp | ||
242 | gamepad_back.bmp | ||
243 | gamepad_battery.bmp | ||
244 | gamepad_battery_wired.bmp | ||
245 | gamepad_button_background.bmp | ||
246 | gamepad_button.bmp | ||
247 | gamepad_button_small.bmp | ||
248 | gamepad_face_abxy.bmp | ||
249 | gamepad_face_bayx.bmp | ||
250 | gamepad_face_sony.bmp | ||
251 | gamepad_front.bmp | ||
252 | gamepad_touchpad.bmp | ||
253 | gamepad_wired.bmp | ||
254 | gamepad_wireless.bmp | ||
255 | ) | ||
256 | files2headers(icon_bmp_header icon.bmp) | ||
257 | files2headers(glass_bmp_header glass.bmp) | ||
258 | |||
259 | set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE) | ||
260 | include("${CMAKE_CURRENT_LIST_DIR}/../cmake/FindFFmpeg.cmake") | ||
261 | if(FFmpeg_FOUND) | ||
262 | cmake_push_check_state() | ||
263 | list(APPEND CMAKE_REQUIRED_INCLUDES "${FFmpeg_AVUTIL_INCLUDE_DIRS}") | ||
264 | list(APPEND CMAKE_REQUIRED_INCLUDES "${SDL3_SOURCE_DIR}/src/video/khronos") | ||
265 | check_struct_has_member("AVFrame" "ch_layout" "libavutil/frame.h" LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT) | ||
266 | check_struct_has_member("AVVulkanFramesContext" "format" "libavutil/hwcontext_vulkan.h" LIBAVUTIL_AVFULKANFRAMESCONTEXT_HAS_FORMAT) | ||
267 | cmake_pop_check_state() | ||
268 | endif() | ||
269 | if(FFmpeg_FOUND AND LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT) | ||
270 | add_sdl_test_executable(testffmpeg NO_C90 SOURCES testffmpeg.c testffmpeg_vulkan.c ${icon_bmp_header} DEPENDS generate-icon_bmp_header) | ||
271 | if(LIBAVUTIL_AVFULKANFRAMESCONTEXT_HAS_FORMAT) | ||
272 | target_compile_definitions(testffmpeg PRIVATE FFMPEG_VULKAN_SUPPORT) | ||
273 | endif() | ||
274 | if(APPLE) | ||
275 | target_link_options(testffmpeg PRIVATE "-Wl,-framework,CoreVideo") | ||
276 | endif() | ||
277 | if(TARGET OpenGL::EGL) | ||
278 | message(DEBUG "Enabling EGL support in testffmpeg") | ||
279 | target_link_libraries(testffmpeg PRIVATE OpenGL::EGL) | ||
280 | target_compile_definitions(testffmpeg PRIVATE HAVE_EGL) | ||
281 | endif() | ||
282 | target_include_directories(testffmpeg SYSTEM BEFORE PRIVATE ${SDL3_SOURCE_DIR}/src/video/khronos) | ||
283 | target_link_libraries(testffmpeg PRIVATE ${FFMPEG_LIBRARIES}) | ||
284 | else() | ||
285 | message(STATUS "Can't find ffmpeg 5.1.3 or newer, skipping testffmpeg") | ||
286 | endif() | ||
287 | |||
288 | add_sdl_test_executable(checkkeys SOURCES checkkeys.c) | ||
289 | add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS MAIN_CALLBACKS SOURCES loopwave.c) | ||
290 | add_sdl_test_executable(testsurround SOURCES testsurround.c) | ||
291 | add_sdl_test_executable(testresample NEEDS_RESOURCES SOURCES testresample.c) | ||
292 | add_sdl_test_executable(testaudioinfo SOURCES testaudioinfo.c) | ||
293 | add_sdl_test_executable(testaudiostreamdynamicresample NEEDS_RESOURCES TESTUTILS SOURCES testaudiostreamdynamicresample.c) | ||
294 | |||
295 | file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c) | ||
296 | add_sdl_test_executable(testautomation NONINTERACTIVE NONINTERACTIVE_TIMEOUT 120 NEEDS_RESOURCES BUILD_DEPENDENT NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES}) | ||
297 | if(EMSCRIPTEN) | ||
298 | target_link_options(testautomation PRIVATE -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb) | ||
299 | endif() | ||
300 | add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES TESTUTILS SOURCES testmultiaudio.c) | ||
301 | add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES TESTUTILS SOURCES testaudiohotplug.c) | ||
302 | add_sdl_test_executable(testaudiorecording MAIN_CALLBACKS SOURCES testaudiorecording.c) | ||
303 | add_sdl_test_executable(testatomic NONINTERACTIVE DISABLE_THREADS_ARGS "--no-threads" SOURCES testatomic.c) | ||
304 | add_sdl_test_executable(testintersections SOURCES testintersections.c) | ||
305 | add_sdl_test_executable(testrelative SOURCES testrelative.c) | ||
306 | add_sdl_test_executable(testhittesting SOURCES testhittesting.c) | ||
307 | add_sdl_test_executable(testdraw SOURCES testdraw.c) | ||
308 | add_sdl_test_executable(testdrawchessboard SOURCES testdrawchessboard.c) | ||
309 | add_sdl_test_executable(testdropfile MAIN_CALLBACKS SOURCES testdropfile.c) | ||
310 | add_sdl_test_executable(testerror NONINTERACTIVE DISABLE_THREADS_ARGS "--no-threads" SOURCES testerror.c) | ||
311 | |||
312 | set(build_options_dependent_tests ) | ||
313 | |||
314 | add_sdl_test_executable(testevdev BUILD_DEPENDENT NONINTERACTIVE NO_C90 SOURCES testevdev.c) | ||
315 | |||
316 | if(MACOS) | ||
317 | add_sdl_test_executable(testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS | ||
318 | SOURCES | ||
319 | testnative.c | ||
320 | testnativecocoa.m | ||
321 | testnativex11.c | ||
322 | ) | ||
323 | elseif(WINDOWS) | ||
324 | add_sdl_test_executable(testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS SOURCES testnative.c testnativew32.c) | ||
325 | elseif(HAVE_X11 OR HAVE_WAYLAND) | ||
326 | add_sdl_test_executable(testnative BUILD_DEPENDENT NO_C90 NEEDS_RESOURCES TESTUTILS SOURCES testnative.c) | ||
327 | if(HAVE_X11) | ||
328 | target_sources(testnative PRIVATE testnativex11.c) | ||
329 | target_link_libraries(testnative PRIVATE X11) | ||
330 | endif() | ||
331 | if(HAVE_WAYLAND) | ||
332 | set_property(SOURCE ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1) | ||
333 | target_sources(testnative PRIVATE testnativewayland.c ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c) | ||
334 | |||
335 | # Needed to silence the documentation warning in the generated header file | ||
336 | target_compile_options(testnative PRIVATE -Wno-documentation-unknown-command) | ||
337 | target_link_libraries(testnative PRIVATE wayland-client) | ||
338 | endif () | ||
339 | endif() | ||
340 | |||
341 | add_sdl_test_executable(testasyncio MAIN_CALLBACKS NEEDS_RESOURCES TESTUTILS SOURCES testasyncio.c) | ||
342 | add_sdl_test_executable(testaudio MAIN_CALLBACKS NEEDS_RESOURCES TESTUTILS SOURCES testaudio.c) | ||
343 | add_sdl_test_executable(testcolorspace SOURCES testcolorspace.c) | ||
344 | add_sdl_test_executable(testfile NONINTERACTIVE SOURCES testfile.c) | ||
345 | add_sdl_test_executable(testcontroller TESTUTILS SOURCES testcontroller.c gamepadutils.c ${gamepad_image_headers} DEPENDS generate-gamepad_image_headers) | ||
346 | add_sdl_test_executable(testgeometry TESTUTILS SOURCES testgeometry.c) | ||
347 | add_sdl_test_executable(testgl SOURCES testgl.c) | ||
348 | add_sdl_test_executable(testgles SOURCES testgles.c) | ||
349 | add_sdl_test_executable(testgpu_simple_clear SOURCES testgpu_simple_clear.c) | ||
350 | add_sdl_test_executable(testgpu_spinning_cube SOURCES testgpu_spinning_cube.c) | ||
351 | if(ANDROID) | ||
352 | target_link_libraries(testgles PRIVATE GLESv1_CM) | ||
353 | elseif(IOS OR TVOS) | ||
354 | find_library(GLES_LIB OpenGLES REQUIRED) | ||
355 | target_link_libraries(testgles PRIVATE "${GLES_LIB}") | ||
356 | endif() | ||
357 | add_sdl_test_executable(testgles2 SOURCES testgles2.c) | ||
358 | add_sdl_test_executable(testhaptic SOURCES testhaptic.c) | ||
359 | add_sdl_test_executable(testhotplug SOURCES testhotplug.c) | ||
360 | add_sdl_test_executable(testpen SOURCES testpen.c) | ||
361 | add_sdl_test_executable(testrumble SOURCES testrumble.c) | ||
362 | add_sdl_test_executable(testthread NONINTERACTIVE THREADS NONINTERACTIVE_TIMEOUT 40 SOURCES testthread.c) | ||
363 | add_sdl_test_executable(testiconv NEEDS_RESOURCES TESTUTILS SOURCES testiconv.c) | ||
364 | add_sdl_test_executable(testime NEEDS_RESOURCES TESTUTILS SOURCES testime.c) | ||
365 | add_sdl_test_executable(testkeys SOURCES testkeys.c) | ||
366 | add_sdl_test_executable(testloadso SOURCES testloadso.c) | ||
367 | add_sdl_test_executable(testlocale NONINTERACTIVE SOURCES testlocale.c) | ||
368 | add_sdl_test_executable(testlock NO_C90 SOURCES testlock.c) | ||
369 | add_sdl_test_executable(testrwlock SOURCES testrwlock.c) | ||
370 | add_sdl_test_executable(testmouse SOURCES testmouse.c) | ||
371 | |||
372 | add_sdl_test_executable(testoverlay NEEDS_RESOURCES TESTUTILS SOURCES testoverlay.c) | ||
373 | add_sdl_test_executable(testplatform NONINTERACTIVE SOURCES testplatform.c) | ||
374 | add_sdl_test_executable(testpower NONINTERACTIVE SOURCES testpower.c) | ||
375 | add_sdl_test_executable(testfilesystem NONINTERACTIVE SOURCES testfilesystem.c) | ||
376 | if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) | ||
377 | add_sdl_test_executable(pretest SOURCES pretest.c NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60) | ||
378 | endif() | ||
379 | add_sdl_test_executable(testrendertarget NEEDS_RESOURCES TESTUTILS SOURCES testrendertarget.c) | ||
380 | add_sdl_test_executable(testscale NEEDS_RESOURCES TESTUTILS SOURCES testscale.c) | ||
381 | add_sdl_test_executable(testsem NONINTERACTIVE DISABLE_THREADS_ARGS "--no-threads" NONINTERACTIVE_ARGS 10 NONINTERACTIVE_TIMEOUT 30 SOURCES testsem.c) | ||
382 | add_sdl_test_executable(testsensor SOURCES testsensor.c) | ||
383 | add_sdl_test_executable(testshader NEEDS_RESOURCES TESTUTILS SOURCES testshader.c) | ||
384 | if(EMSCRIPTEN) | ||
385 | target_link_options(testshader PRIVATE "-sLEGACY_GL_EMULATION") | ||
386 | endif() | ||
387 | add_sdl_test_executable(testshape NEEDS_RESOURCES SOURCES testshape.c ${glass_bmp_header} DEPENDS generate-glass_bmp_header) | ||
388 | add_sdl_test_executable(testsprite MAIN_CALLBACKS NEEDS_RESOURCES TESTUTILS SOURCES testsprite.c) | ||
389 | add_sdl_test_executable(testspriteminimal SOURCES testspriteminimal.c ${icon_bmp_header} DEPENDS generate-icon_bmp_header) | ||
390 | add_sdl_test_executable(testspritesurface SOURCES testspritesurface.c ${icon_bmp_header} DEPENDS generate-icon_bmp_header) | ||
391 | add_sdl_test_executable(teststreaming NEEDS_RESOURCES TESTUTILS SOURCES teststreaming.c) | ||
392 | add_sdl_test_executable(testtimer NONINTERACTIVE NONINTERACTIVE_ARGS --no-interactive NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c) | ||
393 | add_sdl_test_executable(testurl SOURCES testurl.c) | ||
394 | add_sdl_test_executable(testver NONINTERACTIVE NOTRACKMEM SOURCES testver.c) | ||
395 | add_sdl_test_executable(testcamera MAIN_CALLBACKS SOURCES testcamera.c) | ||
396 | add_sdl_test_executable(testclipboard MAIN_CALLBACKS SOURCES testclipboard.c ${icon_bmp_header} DEPENDS generate-icon_bmp_header) | ||
397 | add_sdl_test_executable(testviewport NEEDS_RESOURCES TESTUTILS SOURCES testviewport.c) | ||
398 | add_sdl_test_executable(testwm SOURCES testwm.c) | ||
399 | add_sdl_test_executable(testyuv NONINTERACTIVE NONINTERACTIVE_ARGS "--automated" NEEDS_RESOURCES TESTUTILS SOURCES testyuv.c testyuv_cvt.c) | ||
400 | add_sdl_test_executable(torturethread NONINTERACTIVE THREADS NONINTERACTIVE_TIMEOUT 30 SOURCES torturethread.c) | ||
401 | add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES TESTUTILS SOURCES testrendercopyex.c) | ||
402 | add_sdl_test_executable(testmessage SOURCES testmessage.c) | ||
403 | add_sdl_test_executable(testdisplayinfo SOURCES testdisplayinfo.c) | ||
404 | add_sdl_test_executable(testqsort NONINTERACTIVE SOURCES testqsort.c) | ||
405 | add_sdl_test_executable(testbounds NONINTERACTIVE SOURCES testbounds.c) | ||
406 | add_sdl_test_executable(testcustomcursor SOURCES testcustomcursor.c) | ||
407 | add_sdl_test_executable(testvulkan NO_C90 SOURCES testvulkan.c) | ||
408 | add_sdl_test_executable(testoffscreen SOURCES testoffscreen.c) | ||
409 | add_sdl_test_executable(testpopup SOURCES testpopup.c) | ||
410 | add_sdl_test_executable(testdialog SOURCES testdialog.c) | ||
411 | add_sdl_test_executable(testtime SOURCES testtime.c) | ||
412 | add_sdl_test_executable(testmanymouse SOURCES testmanymouse.c) | ||
413 | add_sdl_test_executable(testmodal SOURCES testmodal.c) | ||
414 | add_sdl_test_executable(testtray NEEDS_RESOURCES TESTUTILS SOURCES testtray.c) | ||
415 | |||
416 | |||
417 | add_sdl_test_executable(testprocess | ||
418 | NONINTERACTIVE THREADS | ||
419 | NONINTERACTIVE_ARGS $<TARGET_FILE:childprocess> | ||
420 | INSTALLED_ARGS "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3/childprocess${CMAKE_EXECUTABLE_SUFFIX}" | ||
421 | SOURCES testprocess.c | ||
422 | ) | ||
423 | add_sdl_test_executable(childprocess SOURCES childprocess.c) | ||
424 | add_dependencies(testprocess childprocess) | ||
425 | |||
426 | if (HAVE_WAYLAND) | ||
427 | # Set the GENERATED property on the protocol file, since it is first created at build time | ||
428 | set_property(SOURCE ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1) | ||
429 | add_sdl_test_executable(testwaylandcustom NO_C90 NEEDS_RESOURCES SOURCES testwaylandcustom.c ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c) | ||
430 | # Needed to silence the documentation warning in the generated header file | ||
431 | target_compile_options(testwaylandcustom PRIVATE -Wno-documentation-unknown-command) | ||
432 | target_link_libraries(testwaylandcustom PRIVATE wayland-client) | ||
433 | endif() | ||
434 | |||
435 | check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW) | ||
436 | if(HAVE_WFORMAT_OVERFLOW) | ||
437 | target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW) | ||
438 | endif() | ||
439 | |||
440 | check_c_compiler_flag(-Wformat HAVE_WFORMAT) | ||
441 | if(HAVE_WFORMAT) | ||
442 | target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT) | ||
443 | endif() | ||
444 | |||
445 | cmake_push_check_state() | ||
446 | if(HAVE_WFORMAT) | ||
447 | # Some compilers ignore -Wformat-extra-args without -Wformat | ||
448 | string(APPEND CMAKE_REQUIRED_FLAGS " -Wformat") | ||
449 | endif() | ||
450 | check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS) | ||
451 | cmake_pop_check_state() | ||
452 | if(HAVE_WFORMAT_EXTRA_ARGS) | ||
453 | target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS) | ||
454 | endif() | ||
455 | |||
456 | if(SDL_DUMMYAUDIO) | ||
457 | set_property(TARGET testaudioinfo PROPERTY SDL_NONINTERACTIVE 1) | ||
458 | endif() | ||
459 | |||
460 | if(SDL_DUMMYVIDEO) | ||
461 | set_property(TARGET testkeys PROPERTY SDL_NONINTERACTIVE 1) | ||
462 | set_property(TARGET testbounds PROPERTY SDL_NONINTERACTIVE 1) | ||
463 | set_property(TARGET testdisplayinfo PROPERTY SDL_NONINTERACTIVE 1) | ||
464 | endif() | ||
465 | |||
466 | if(OPENGL_FOUND) | ||
467 | if(TARGET OpenGL::GL) | ||
468 | target_link_libraries(testshader PRIVATE OpenGL::GL) | ||
469 | target_link_libraries(testgl PRIVATE OpenGL::GL) | ||
470 | else() | ||
471 | if(EMSCRIPTEN AND OPENGL_gl_LIBRARY STREQUAL "nul") | ||
472 | set(OPENGL_gl_LIBRARY GL) | ||
473 | endif() | ||
474 | # emscripten's FindOpenGL.cmake does not create OpenGL::GL | ||
475 | target_link_libraries(testshader PRIVATE ${OPENGL_gl_LIBRARY}) | ||
476 | target_link_libraries(testgl PRIVATE ${OPENGL_gl_LIBRARY}) | ||
477 | endif() | ||
478 | endif() | ||
479 | if(MACOS) | ||
480 | target_link_options(testnative PRIVATE "-Wl,-framework,Cocoa") | ||
481 | endif() | ||
482 | if(APPLE) | ||
483 | cmake_push_check_state() | ||
484 | check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS) | ||
485 | cmake_pop_check_state() | ||
486 | if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS) | ||
487 | set_property(SOURCE "testnativecocoa.m" APPEND PROPERTY COMPILE_OPTIONS "-Wno-error=deprecated-declarations") | ||
488 | set_property(TARGET testgles APPEND PROPERTY COMPILE_OPTIONS "-Wno-error=deprecated-declarations") | ||
489 | endif() | ||
490 | endif() | ||
491 | |||
492 | |||
493 | if(PSP) | ||
494 | # Build EBOOT files if building for PSP | ||
495 | foreach(APP ${SDL_TEST_EXECUTABLES}) | ||
496 | create_pbp_file( | ||
497 | TARGET ${APP} | ||
498 | TITLE SDL-${APP} | ||
499 | ICON_PATH NULL | ||
500 | BACKGROUND_PATH NULL | ||
501 | PREVIEW_PATH NULL | ||
502 | OUTPUT_DIR $<TARGET_FILE_DIR:${APP}>/sdl-${APP} | ||
503 | ) | ||
504 | endforeach() | ||
505 | endif() | ||
506 | |||
507 | if(N3DS) | ||
508 | foreach(APP ${SDL_TEST_EXECUTABLES}) | ||
509 | get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR) | ||
510 | set(ROMFS_DIR "${TARGET_BINARY_DIR}/sdl-${APP}") | ||
511 | set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh") | ||
512 | file(MAKE_DIRECTORY ${ROMFS_DIR}) | ||
513 | ctr_generate_smdh("${SMDH_FILE}" | ||
514 | NAME "SDL-${APP}" | ||
515 | DESCRIPTION "SDL3 Test suite" | ||
516 | AUTHOR "SDL3 Contributors" | ||
517 | ICON "${CMAKE_CURRENT_SOURCE_DIR}/n3ds/logo48x48.png" | ||
518 | ) | ||
519 | ctr_create_3dsx( | ||
520 | ${APP} | ||
521 | ROMFS "${ROMFS_DIR}" | ||
522 | SMDH "${SMDH_FILE}" | ||
523 | ) | ||
524 | endforeach() | ||
525 | endif() | ||
526 | |||
527 | if(RISCOS) | ||
528 | set(SDL_TEST_EXECUTABLES_AIF) | ||
529 | foreach(APP ${SDL_TEST_EXECUTABLES}) | ||
530 | set_property(TARGET ${APP} APPEND_STRING PROPERTY LINK_FLAGS " -static") | ||
531 | add_custom_command( | ||
532 | OUTPUT ${APP},ff8 | ||
533 | COMMAND elf2aif ${APP} ${APP},ff8 | ||
534 | DEPENDS ${APP} | ||
535 | ) | ||
536 | add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8) | ||
537 | list(APPEND SDL_TEST_EXECUTABLES_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8) | ||
538 | endforeach() | ||
539 | endif() | ||
540 | |||
541 | # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple | ||
542 | # platforms (iOS, for example). | ||
543 | if(APPLE) | ||
544 | foreach(CURRENT_TARGET ${SDL_TEST_EXECUTABLES}) | ||
545 | set_target_properties("${CURRENT_TARGET}" PROPERTIES | ||
546 | MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}" | ||
547 | MACOSX_BUNDLE_BUNDLE_VERSION "${SDL3_VERSION}" | ||
548 | MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL3_VERSION}" | ||
549 | ) | ||
550 | endforeach() | ||
551 | endif() | ||
552 | |||
553 | set(SDLTEST_TIMEOUT_MULTIPLIER "1" CACHE STRING "SDL test time-out multiplier") | ||
554 | |||
555 | set(SDLTEST_AUDIO_DRIVER_DEFAULT "dummy") | ||
556 | set(SDLTEST_VIDEO_DRIVER_DEFAULT "dummy") | ||
557 | if(EMSCRIPTEN) | ||
558 | set(SDLTEST_AUDIO_DRIVER_DEFAULT "emscripten") | ||
559 | set(SDLTEST_VIDEO_DRIVER_DEFAULT "emscripten") | ||
560 | endif() | ||
561 | set(SDLTEST_AUDIO_DRIVER "${SDLTEST_AUDIO_DRIVER_DEFAULT}" CACHE STRING "SDL audio driver for CTest") | ||
562 | set(SDLTEST_VIDEO_DRIVER "${SDLTEST_VIDEO_DRIVER_DEFAULT}" CACHE STRING "SDL video driver for CTest") | ||
563 | |||
564 | set(TESTS_ENVIRONMENT | ||
565 | "SDL_AUDIO_DRIVER=${SDLTEST_AUDIO_DRIVER}" | ||
566 | "SDL_VIDEO_DRIVER=${SDLTEST_VIDEO_DRIVER}" | ||
567 | "SDL_ASSERT=abort" | ||
568 | ) | ||
569 | |||
570 | function(add_sdl_test TEST TARGET) | ||
571 | cmake_parse_arguments(ast "INSTALL" "" "" ${ARGN}) | ||
572 | get_property(noninteractive TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE) | ||
573 | if(noninteractive) | ||
574 | if(EMSCRIPTEN) | ||
575 | set(command "${PYTHON3_EXECUTABLE};${CMAKE_CURRENT_SOURCE_DIR}/emscripten/driver.py;--server;http://localhost:${SDLTEST_PORT};--browser;${SDLTEST_BROWSER}") | ||
576 | if(SDLTEST_CHROME_BINARY) | ||
577 | list(APPEND command "--chrome-binary;${SDLTEST_CHROME_BINARY}") | ||
578 | endif() | ||
579 | list(APPEND command "--;${TARGET}") | ||
580 | else() | ||
581 | set(command ${TARGET}) | ||
582 | endif() | ||
583 | get_property(noninteractive_arguments TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS) | ||
584 | get_property(installed_arguments TARGET ${TARGET} PROPERTY SDL_INSTALLED_ARGUMENTS) | ||
585 | get_property(disable_threads_args TARGET ${TARGET} PROPERTY SDL_DISABLE_THREADS_ARGS) | ||
586 | get_property(uses_threads TARGET ${TARGET} PROPERTY SDL_THREADS) | ||
587 | if(noninteractive_arguments) | ||
588 | list(APPEND command ${noninteractive_arguments}) | ||
589 | endif() | ||
590 | if(SDLTEST_TRACKMEM) | ||
591 | get_property(notrackmem TARGET ${TARGET} PROPERTY SDL_NOTRACKMEM) | ||
592 | if(NOT notrackmem) | ||
593 | list(APPEND command --trackmem) | ||
594 | endif() | ||
595 | endif() | ||
596 | if(EMSCRIPTEN) | ||
597 | list(APPEND command ${disable_threads_args}) | ||
598 | endif() | ||
599 | add_test( | ||
600 | NAME ${TEST} | ||
601 | COMMAND ${command} | ||
602 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
603 | ) | ||
604 | if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.27") | ||
605 | set_property(TEST ${TEST} APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_RUNTIME_DLL_DIRS:${TARGET}>") | ||
606 | endif() | ||
607 | if(NOT notrackmem) | ||
608 | set_property(TEST ${TEST} PROPERTY FAIL_REGULAR_EXPRESSION "Total: [0-9]+\\.[0-9]+ Kb in [1-9][0-9]* allocations") | ||
609 | endif() | ||
610 | set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}") | ||
611 | if(EMSCRIPTEN AND uses_threads) | ||
612 | set_tests_properties(${TEST} PROPERTIES DISABLED 1) | ||
613 | endif() | ||
614 | get_property(noninteractive_timeout TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_TIMEOUT) | ||
615 | if(NOT noninteractive_timeout) | ||
616 | set(noninteractive_timeout 10) | ||
617 | endif() | ||
618 | math(EXPR noninteractive_timeout "${noninteractive_timeout}*${SDLTEST_TIMEOUT_MULTIPLIER}") | ||
619 | set_tests_properties(${TEST} PROPERTIES TIMEOUT "${noninteractive_timeout}") | ||
620 | if(ast_INSTALL AND SDL_INSTALL_TESTS) | ||
621 | set(exe ${TARGET}) | ||
622 | set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3") | ||
623 | configure_file(template.test.in "${exe}.test" @ONLY) | ||
624 | install( | ||
625 | FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test" | ||
626 | DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL3 | ||
627 | ) | ||
628 | endif() | ||
629 | if(TARGET pretest AND NOT "${TARGET}" MATCHES "pretest") | ||
630 | set_property(TEST ${TEST} APPEND PROPERTY DEPENDS pretest) | ||
631 | endif() | ||
632 | endif() | ||
633 | endfunction() | ||
634 | |||
635 | foreach(TARGET ${SDL_TEST_EXECUTABLES}) | ||
636 | add_sdl_test(${TARGET} ${TARGET} INSTALL) | ||
637 | endforeach() | ||
638 | |||
639 | if(NOT EMSCRIPTEN) | ||
640 | add_sdl_test(testautomation-no-simd testautomation) | ||
641 | add_sdl_test(testplatform-no-simd testplatform) | ||
642 | set_property(TEST testautomation-no-simd testplatform-no-simd APPEND PROPERTY ENVIRONMENT "SDL_CPU_FEATURE_MASK=-all") | ||
643 | |||
644 | # testautomation creates temporary files which might conflict | ||
645 | set_property(TEST testautomation-no-simd testautomation PROPERTY RUN_SERIAL TRUE) | ||
646 | endif() | ||
647 | |||
648 | if(SDL_INSTALL_TESTS) | ||
649 | if(RISCOS) | ||
650 | install( | ||
651 | FILES ${SDL_TEST_EXECUTABLES_AIF} | ||
652 | DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3 | ||
653 | ) | ||
654 | else() | ||
655 | install( | ||
656 | TARGETS ${SDL_TEST_EXECUTABLES} | ||
657 | DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3 | ||
658 | ) | ||
659 | endif() | ||
660 | if(MSVC) | ||
661 | foreach(test IN LISTS SDL_TEST_EXECUTABLES) | ||
662 | SDL_install_pdb(${test} "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3") | ||
663 | endforeach() | ||
664 | endif() | ||
665 | install( | ||
666 | FILES ${RESOURCE_FILES} | ||
667 | DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3 | ||
668 | ) | ||
669 | endif() | ||
670 | |||
671 | if(ANDROID AND TARGET SDL3::Jar) | ||
672 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/android") | ||
673 | find_package(SdlAndroid MODULE) | ||
674 | if(SdlAndroid_FOUND) | ||
675 | set(apks "") | ||
676 | set(packages "") | ||
677 | |||
678 | include(SdlAndroidFunctions) | ||
679 | sdl_create_android_debug_keystore(SDL_test-debug-keystore) | ||
680 | sdl_android_compile_resources(SDL_test-resources RESFOLDER android/res) | ||
681 | add_custom_target(sdl-test-apks) | ||
682 | foreach(TEST ${SDL_TEST_EXECUTABLES}) | ||
683 | set(ANDROID_MANIFEST_APP_NAME "${TEST}") | ||
684 | set(ANDROID_MANIFEST_LABEL "${TEST}") | ||
685 | set(ANDROID_MANIFEST_LIB_NAME "$<TARGET_FILE_BASE_NAME:${TEST}>") | ||
686 | set(ANDROID_MANIFEST_PACKAGE "org.libsdl.sdl.test.${TEST}") | ||
687 | set(generated_manifest_path "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src/AndroidManifest.xml") | ||
688 | string(REPLACE "." "/" JAVA_PACKAGE_DIR "${ANDROID_MANIFEST_PACKAGE}") | ||
689 | set(GENERATED_SRC_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src") | ||
690 | set(GENERATED_RES_FOLDER "${GENERATED_SRC_FOLDER}/res") | ||
691 | set(JAVA_PACKAGE_DIR "${GENERATED_SRC_FOLDER}/${JAVA_PACKAGE_DIR}") | ||
692 | configure_file(android/cmake/SDLEntryTestActivity.java.cmake "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java" @ONLY) | ||
693 | configure_file(android/cmake/SDLTestActivity.java.cmake "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" @ONLY) | ||
694 | configure_file(android/cmake/res/values/strings.xml.cmake android/res/values/strings-${TEST}.xml @ONLY) | ||
695 | configure_file(android/cmake/res/xml/shortcuts.xml.cmake "${GENERATED_RES_FOLDER}/xml/shortcuts.xml" @ONLY) | ||
696 | configure_file(android/cmake/AndroidManifest.xml.cmake "${generated_manifest_path}" @ONLY) | ||
697 | file(GENERATE | ||
698 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-$<CONFIG>/res/values/strings.xml" | ||
699 | INPUT "${CMAKE_CURRENT_BINARY_DIR}/android/res/values/strings-${TEST}.xml" | ||
700 | ) | ||
701 | |||
702 | sdl_android_compile_resources(${TEST}-resources | ||
703 | RESOURCES | ||
704 | "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-$<CONFIG>/res/values/strings.xml" | ||
705 | "${GENERATED_RES_FOLDER}/xml/shortcuts.xml" | ||
706 | ) | ||
707 | |||
708 | sdl_android_link_resources(${TEST}-apk-linked | ||
709 | MANIFEST "${generated_manifest_path}" | ||
710 | PACKAGE ${ANDROID_MANIFEST_PACKAGE} | ||
711 | RES_TARGETS SDL_test-resources ${TEST}-resources | ||
712 | TARGET_SDK_VERSION 31 | ||
713 | ) | ||
714 | |||
715 | set(CMAKE_JAVA_COMPILE_FLAGS "-encoding;utf-8") | ||
716 | set(classes_path "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TEST}-java.dir/classes") | ||
717 | # Some CMake versions have a slow `cmake -E make_directory` implementation | ||
718 | if(NOT IS_DIRECTORY "${classes_path}") | ||
719 | execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}") | ||
720 | endif() | ||
721 | set(OUT_JAR "${CMAKE_CURRENT_BINARY_DIR}/${TEST}.jar") | ||
722 | add_custom_command( | ||
723 | OUTPUT "${OUT_JAR}" | ||
724 | COMMAND ${CMAKE_COMMAND} -E rm -rf "${classes_path}" | ||
725 | COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}" | ||
726 | COMMAND ${Java_JAVAC_EXECUTABLE} | ||
727 | -source 1.8 -target 1.8 | ||
728 | -bootclasspath "$<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>" | ||
729 | "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java" | ||
730 | "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" | ||
731 | $<TARGET_PROPERTY:${TEST}-apk-linked,JAVA_R> | ||
732 | -cp "$<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>:${SDL_ANDROID_PLATFORM_ANDROID_JAR}" | ||
733 | -d "${classes_path}" | ||
734 | COMMAND ${Java_JAR_EXECUTABLE} cf "${OUT_JAR}" -C "${classes_path}" . | ||
735 | DEPENDS $<TARGET_PROPERTY:${TEST}-apk-linked,OUTPUTS> "$<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>" "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java" | ||
736 | ) | ||
737 | add_custom_target(${TEST}-jar DEPENDS "${OUT_JAR}") | ||
738 | set_property(TARGET ${TEST}-jar PROPERTY OUTPUT "${OUT_JAR}") | ||
739 | |||
740 | set(dexworkdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TEST}-dex.dir") | ||
741 | # Some CMake versions have a slow `cmake -E make_directory` implementation | ||
742 | if(NOT IS_DIRECTORY "${dexworkdir}") | ||
743 | execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${dexworkdir}") | ||
744 | endif() | ||
745 | set(classes_dex_base_name "classes.dex") | ||
746 | set(classes_dex "${dexworkdir}/${classes_dex_base_name}") | ||
747 | add_custom_command( | ||
748 | OUTPUT "${classes_dex}" | ||
749 | COMMAND SdlAndroid::d8 | ||
750 | $<TARGET_PROPERTY:${TEST}-jar,OUTPUT> | ||
751 | $<TARGET_PROPERTY:SDL3::Jar,JAR_FILE> | ||
752 | --lib "${SDL_ANDROID_PLATFORM_ANDROID_JAR}" | ||
753 | --output "${dexworkdir}" | ||
754 | DEPENDS $<TARGET_PROPERTY:${TEST}-jar,OUTPUT> $<TARGET_PROPERTY:SDL3::Jar,JAR_FILE> | ||
755 | ) | ||
756 | add_custom_target(${TEST}-dex DEPENDS "${classes_dex}") | ||
757 | set_property(TARGET ${TEST}-dex PROPERTY OUTPUT "${classes_dex}") | ||
758 | set_property(TARGET ${TEST}-dex PROPERTY OUTPUT_BASE_NAME "${classes_dex_base_name}") | ||
759 | |||
760 | sdl_add_to_apk_unaligned(${TEST}-unaligned-apk | ||
761 | APK_IN ${TEST}-apk-linked | ||
762 | OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" | ||
763 | ASSETS ${RESOURCE_FILES} | ||
764 | NATIVE_LIBS SDL3::SDL3-shared ${TEST} | ||
765 | DEX ${TEST}-dex | ||
766 | ) | ||
767 | |||
768 | sdl_apk_align(${TEST}-aligned-apk ${TEST}-unaligned-apk | ||
769 | OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" | ||
770 | ) | ||
771 | sdl_apk_sign(${TEST}-apk ${TEST}-aligned-apk | ||
772 | KEYSTORE SDL_test-debug-keystore | ||
773 | ) | ||
774 | add_dependencies(sdl-test-apks ${TEST}-apk) | ||
775 | |||
776 | if(TARGET SdlAndroid::adb) | ||
777 | add_custom_target(install-${TEST} | ||
778 | COMMAND "${CMAKE_COMMAND}" -DACTION=install "-DAPKS=$<TARGET_PROPERTY:${TEST}-apk,OUTPUT>" -P "${SDL3_SOURCE_DIR}/cmake/android/SdlAndroidScript.cmake" | ||
779 | DEPENDS "${TEST}-apk" | ||
780 | ) | ||
781 | add_custom_target(start-${TEST} | ||
782 | COMMAND "${ADB_BIN}" shell am start-activity -S "${ANDROID_MANIFEST_PACKAGE}/.SDLTestActivity" | ||
783 | ) | ||
784 | add_custom_target(build-install-start-${TEST} | ||
785 | COMMAND "${CMAKE_COMMAND}" -DACTION=build-install-run "-DEXECUTABLES=${TEST}" "-DBUILD_FOLDER=${CMAKE_BINARY_DIR}" -P "${SDL3_SOURCE_DIR}/cmake/android/SdlAndroidScript.cmake" | ||
786 | ) | ||
787 | endif() | ||
788 | |||
789 | list(APPEND packages "${ANDROID_MANIFEST_PACKAGE}") | ||
790 | list(APPEND install_targets install-${TEST}) | ||
791 | endforeach() | ||
792 | |||
793 | if(TARGET SdlAndroid::adb) | ||
794 | add_custom_target(install-sdl-test-apks | ||
795 | DEPENDS ${install_targets} | ||
796 | VERBATIM | ||
797 | ) | ||
798 | add_custom_target(uninstall-sdl-test-apks | ||
799 | COMMAND "${CMAKE_COMMAND}" "-DADB=$<TARGET_FILE:SdlAndroid::adb>" -DACTION=uninstall "-DPACKAGES=${packages}" -P "${SDL3_SOURCE_DIR}/cmake/android/SdlAndroidScript.cmake" | ||
800 | VERBATIM | ||
801 | ) | ||
802 | endif() | ||
803 | endif() | ||
804 | endif() | ||