Debian Codegraph @

test/CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 if(NOT (WIN32 OR APPLE OR CYGWIN OR HAIKU OR BEOS))
2 find_library(MATH_LIBRARY m)
3 endif()
4
5 set(OpenGL_GL_PREFERENCE GLVND)
6 find_package(OpenGL COMPONENTS OpenGL)
7 if(OPENGL_FOUND)
8 set(HAVE_OPENGL_DEFINE "HAVE_OPENGL")
9 if(WIN32)
10 set(OPENGL_gl_LIBRARY "opengl32")
11 set(OPENGL_opengl_LIBRARY "opengl32")
12 elseif(APPLE)
13 set(OPENGL_gl_LIBRARY "-Wl,-framework,OpenGL")
14 set(OPENGL_opengl_LIBRARY "-Wl,-framework,OpenGL")
15 endif()
16 endif()
17
18 set(RESOURCE_FILES)
19 set(SDL2COMPAT_TEST_EXECUTABLES)
20
21 function(test_program NAME)
22 cmake_parse_arguments(args "NONINTERACTIVE" "TIMEOUT" "SRC" ${ARGN})
23 if(ANDROID)
24 add_library(${NAME} SHARED ${args_SRC})
25 else()
26 add_executable(${NAME} ${args_SRC})
27 endif()
28 list(APPEND SDL2COMPAT_TEST_EXECUTABLES ${NAME})
29 set(SDL2COMPAT_TEST_EXECUTABLES ${SDL2COMPAT_TEST_EXECUTABLES} PARENT_SCOPE)
30 SDL_AddCommonCompilerFlags(${NAME} WERROR "${SDL2COMPAT_WERROR}")
31 target_link_libraries(${NAME} PRIVATE SDL2::SDL2main SDL2::SDL2test SDL2::SDL2)
32 # Turn off MSVC's aggressive C runtime warnings for the old test programs.
33 if(MSVC)
34 target_compile_definitions(${NAME} PRIVATE ${HAVE_OPENGL_DEFINE} _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE)
35 elseif(APPLE)
36 target_compile_definitions(${NAME} PRIVATE ${HAVE_OPENGL_DEFINE} GL_SILENCE_DEPRECATION=1)
37 target_link_libraries(${NAME} PRIVATE "-Wl,-framework,Cocoa")
38 else()
39 target_compile_definitions(${NAME} PRIVATE ${HAVE_OPENGL_DEFINE})
40 endif()
41 if(MATH_LIBRARY)
42 target_link_libraries(${NAME} PRIVATE ${MATH_LIBRARY})
43 endif()
44 if(args_NONINTERACTIVE)
45 add_test(
46 NAME ${NAME}
47 COMMAND ${NAME}
48 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
49 )
50 set(timeout 10)
51 if(args_TIMEOUT)
52 set(timeout ${args_TIMEOUT})
53 endif()
54 set_tests_properties(${NAME}
55 PROPERTIES
56 ENVIRONMENT "SDL_AUDIODRIVER=dummy;SDL_VIDEODRIVER=dummy"
57 TIMEOUT ${timeout}
58 )
59 if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.27")
60 set_property(TEST ${NAME} APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_RUNTIME_DLL_DIRS:${NAME}>")
61 if(TARGET SDL3::SDL3-shared)
62 set_property(TEST ${NAME} APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:SDL3::SDL3-shared>")
63 endif()
64 endif()
65 if(SDL2COMPAT_INSTALL_TESTS)
66 set(exe ${NAME})
67 set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2_compat")
68 configure_file(template.test.in "${exe}.test" @ONLY)
69 install(
70 FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
71 DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL2_compat
72 )
73 endif()
74 endif()
75 endfunction()
76
77 test_program(checkkeys SRC "checkkeys.c")
78 test_program(checkkeysthreads SRC "checkkeysthreads.c")
79 test_program(controllermap SRC "controllermap.c" "testutils.c")
80 test_program(loopwave SRC "loopwave.c" "testutils.c")
81 test_program(loopwavequeue SRC "loopwavequeue.c" "testutils.c")
82 test_program(testatomic NONINTERACTIVE TIMEOUT 120 SRC "testatomic.c")
83 test_program(testaudiocapture SRC "testaudiocapture.c")
84 test_program(testaudiohotplug SRC "testaudiohotplug.c" "testutils.c")
85 test_program(testaudioinfo SRC "testaudioinfo.c")
86 test_program(testbounds SRC "testbounds.c")
87 test_program(testcustomcursor SRC "testcustomcursor.c")
88 test_program(testdisplayinfo SRC "testdisplayinfo.c")
89 test_program(testdraw2 SRC "testdraw2.c")
90 test_program(testdrawchessboard SRC "testdrawchessboard.c")
91 test_program(testdropfile SRC "testdropfile.c")
92 test_program(testerror NONINTERACTIVE SRC "testerror.c")
93 test_program(testevdev NONINTERACTIVE SRC "testevdev.c")
94 test_program(testfile NONINTERACTIVE SRC "testfile.c")
95 test_program(testfilesystem NONINTERACTIVE SRC "testfilesystem.c")
96 test_program(testgamecontroller SRC "testgamecontroller.c" "testutils.c")
97 test_program(testgeometry SRC "testgeometry.c" "testutils.c")
98 test_program(testgesture SRC "testgesture.c")
99 test_program(testhaptic SRC "testhaptic.c")
100 test_program(testhittesting SRC "testhittesting.c")
101 test_program(testhotplug SRC "testhotplug.c")
102 test_program(testiconv SRC "testiconv.c" "testutils.c")
103 test_program(testime SRC "testime.c" "testutils.c")
104 test_program(testintersections SRC "testintersections.c")
105 test_program(testjoystick SRC "testjoystick.c")
106 test_program(testkeys SRC "testkeys.c")
107 test_program(testloadso SRC "testloadso.c")
108 test_program(testlocale NONINTERACTIVE SRC "testlocale.c")
109 test_program(testlock SRC "testlock.c")
110 test_program(testmessage SRC "testmessage.c")
111 test_program(testmouse SRC "testmouse.c")
112 test_program(testmultiaudio SRC "testmultiaudio.c" "testutils.c")
113 if(APPLE)
114 set(TESTNATIVE_EXTRA "testnativecocoa.m")
115 elseif(WIN32)
116 set(TESTNATIVE_EXTRA "testnativew32.c")
117 elseif(UNIX AND NOT ANDROID)
118 if(SDL2COMPAT_X11)
119 find_package(X11 REQUIRED)
120 set(TESTNATIVE_EXTRA "testnativex11.c")
121 endif()
122 endif()
123 test_program(testnative SRC "testnative.c" "testutils.c" "${TESTNATIVE_EXTRA}")
124 if(UNIX AND NOT ANDROID AND NOT APPLE)
125 if(SDL2COMPAT_X11)
126 target_link_libraries(testnative PRIVATE X11)
127 endif()
128 endif()
129 test_program(testoverlay2 SRC "testoverlay2.c" "testutils.c" "testyuv_cvt.c")
130 test_program(testplatform NONINTERACTIVE SRC "testplatform.c")
131 test_program(testpower NONINTERACTIVE SRC "testpower.c")
132 test_program(testqsort NONINTERACTIVE SRC "testqsort.c")
133 test_program(testrelative SRC "testrelative.c")
134 test_program(testrendercopyex SRC "testrendercopyex.c" "testutils.c")
135 test_program(testrendertarget SRC "testrendertarget.c" "testutils.c")
136 test_program(testresample SRC "testresample.c")
137 test_program(testrumble SRC "testrumble.c")
138 test_program(testscale SRC "testscale.c" "testutils.c")
139 test_program(testsem SRC "testsem.c")
140 test_program(testsensor SRC "testsensor.c")
141 test_program(testshape SRC "testshape.c")
142 test_program(testsprite2 SRC "testsprite2.c" "testutils.c")
143 test_program(testspriteminimal SRC "testspriteminimal.c" "testutils.c")
144 test_program(teststreaming SRC "teststreaming.c" "testutils.c")
145 test_program(testsurround SRC "testsurround.c")
146 test_program(testthread NONINTERACTIVE TIMEOUT 40 SRC "testthread.c")
147 test_program(testtimer NONINTERACTIVE TIMEOUT 60 SRC "testtimer.c")
148 test_program(testurl SRC "testurl.c")
149 test_program(testver NONINTERACTIVE SRC "testver.c")
150 test_program(testviewport SRC "testviewport.c" "testutils.c")
151 test_program(testvulkan SRC "testvulkan.c")
152 test_program(testwm2 SRC "testwm2.c")
153 test_program(testyuv SRC "testyuv.c" "testyuv_cvt.c")
154 test_program(torturethread SRC "torturethread.c")
155 test_program(testgl2 SRC "testgl2.c")
156 if(HAVE_OPENGLES)
157 test_program(testgles SRC "testgles.c")
158 if(ANDROID)
159 target_link_libraries(testgles PRIVATE GLESv1_CM)
160 endif()
161 endif()
162 if(HAVE_OPENGLES_V2)
163 test_program(testgles2 SRC "testgles2.c")
164 test_program(testgles2_sdf SRC "testgles2_sdf.c" "testutils.c")
165 if(ANDROID)
166 target_link_libraries(testgles2 PRIVATE GLESv2)
167 target_link_libraries(testgles2_sdf PRIVATE GLESv2)
168 endif()
169 endif()
170
171 test_program(testautomation NONINTERACTIVE TIMEOUT 120
172 SRC
173 "testautomation.c"
174 "testautomation_audio.c"
175 "testautomation_guid.c"
176 "testautomation_log.c"
177 "testautomation_main.c"
178 "testautomation_platform.c"
179 "testautomation_sdltest.c"
180 "testautomation_syswm.c"
181 "testautomation_hints.c"
182 "testautomation_math.c"
183 "testautomation_rect.c"
184 "testautomation_stdlib.c"
185 "testautomation_subsystems.c"
186 "testautomation_timer.c"
187 "testautomation_clipboard.c"
188 "testautomation_joystick.c"
189 "testautomation_mouse.c"
190 "testautomation_render.c"
191 "testautomation_video.c"
192 "testautomation_events.c"
193 "testautomation_keyboard.c"
194 "testautomation_pixels.c"
195 "testautomation_rwops.c"
196 "testautomation_surface.c"
197 )
198
199 if(OPENGL_FOUND)
200 if(CMAKE_VERSION VERSION_LESS 3.10 OR NOT OPENGL_opengl_LIBRARY)
201 target_link_libraries(testgl2 PRIVATE ${OPENGL_gl_LIBRARY})
202 else()
203 target_link_libraries(testgl2 PRIVATE ${OPENGL_opengl_LIBRARY})
204 endif()
205 endif()
206
207 foreach(fname
208 "axis.bmp"
209 "button.bmp"
210 "controllermap.bmp"
211 "controllermap_back.bmp"
212 "icon.bmp"
213 "moose.dat"
214 "sample.bmp"
215 "sample.wav"
216 "testgles2_sdf_img_normal.bmp"
217 "testgles2_sdf_img_sdf.bmp"
218 "testyuv.bmp"
219 "unifont-13.0.06.hex"
220 "utf8.txt")
221 list(APPEND RESOURCE_FILES "${fname}")
222 file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${fname}" DESTINATION "${CMAKE_BINARY_DIR}")
223 endforeach()
224
225 if(SDL2COMPAT_INSTALL_TESTS)
226 install(
227 TARGETS ${SDL2COMPAT_TEST_EXECUTABLES}
228 DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2_compat
229 )
230 install(
231 FILES ${RESOURCE_FILES}
232 DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2_compat
233 )
234 endif()
235
236 check_c_compiler_flag(-Wformat HAVE_WFORMAT)
237 if(HAVE_WFORMAT)
238 target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
239 endif()
240
241 cmake_push_check_state()
242 if(HAVE_WFORMAT)
243 # Some compilers ignore -Wformat-extra-args without -Wformat
244 string(APPEND CMAKE_REQUIRED_FLAGS " -Wformat")
245 endif()
246 check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
247 cmake_pop_check_state()
248 if(HAVE_WFORMAT_EXTRA_ARGS)
249 target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
250 endif()
251
252 add_custom_target(sdl2compat-build-tests)
253
254 check_language(CXX)
255 if(CMAKE_CXX_COMPILER)
256 enable_language(CXX)
257 add_library(test_sdl3_prototypes STATIC EXCLUDE_FROM_ALL "test_sdl3_syms.cpp")
258 target_link_libraries(test_sdl3_prototypes PRIVATE SDL3::Headers)
259 SDL_AddCommonCompilerFlags(test_sdl3_prototypes WERROR TRUE)
260 set_target_properties(test_sdl3_prototypes PROPERTIES SUFFIX ".do_not_use")
261 # Make sure test_sdl3_prototypes is always out-of-date
262 add_custom_command(TARGET test_sdl3_prototypes POST_BUILD COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_SOURCE_DIR}/test_sdl3_syms.cpp")
263 add_dependencies(sdl2compat-build-tests test_sdl3_prototypes)
264 endif()