CMakeLists.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. cmake_minimum_required(VERSION 3.0)
  2. project(SDL3_test)
  3. enable_testing()
  4. include("${CMAKE_CURRENT_LIST_DIR}/../cmake/sdlplatform.cmake")
  5. SDL_DetectCMakePlatform()
  6. include(CheckCCompilerFlag)
  7. include(CheckIncludeFile)
  8. include(CMakeParseArguments)
  9. include(CMakePushCheckState)
  10. include(GNUInstallDirs)
  11. set(SDL_TESTS_LINK_SHARED_DEFAULT ON)
  12. if(EMSCRIPTEN OR N3DS OR PS2 OR PSP OR RISCOS OR VITA)
  13. set(SDL_TESTS_LINK_SHARED_DEFAULT OFF)
  14. endif()
  15. option(SDL_TESTS_LINK_SHARED "link tests to shared SDL library" ${SDL_TESTS_LINK_SHARED_DEFAULT})
  16. set(SDL_TESTS_TIMEOUT_MULTIPLIER "1" CACHE STRING "Timeout multiplier to account for really slow machines")
  17. if(SDL_TESTS_LINK_SHARED)
  18. set(sdl_name_component SDL3-shared)
  19. else()
  20. set(sdl_name_component SDL3-static)
  21. endif()
  22. if(NOT TARGET SDL3::${sdl_name_component})
  23. find_package(SDL3 3.0.0 REQUIRED CONFIG COMPONENTS ${sdl_name_component} SDL3_test)
  24. endif()
  25. if(TARGET sdl-build-options)
  26. set(SDL3_TESTS_SUBPROJECT ON)
  27. else()
  28. set(SDL3_TESTS_SUBPROJECT OFF)
  29. endif()
  30. # CMake incorrectly detects opengl32.lib being present on MSVC ARM64
  31. if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
  32. # Prefer GLVND, if present
  33. set(OpenGL_GL_PREFERENCE GLVND)
  34. find_package(OpenGL)
  35. endif()
  36. set(SDL_TEST_EXECUTABLES)
  37. # FIXME: can be OBJECT library for CMake 3.16
  38. add_library(sdltests_utils STATIC
  39. testutils.c
  40. )
  41. target_link_libraries(sdltests_utils PRIVATE SDL3::${sdl_name_component})
  42. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  43. set(RESOURCE_FILE_NAMES)
  44. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  45. get_filename_component(res_file_name ${RESOURCE_FILE} NAME)
  46. list(APPEND RESOURCE_FILE_NAMES "${res_file_name}")
  47. endforeach()
  48. 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.")
  49. 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.")
  50. define_property(TARGET PROPERTY SDL_NONINTERACTIVE_TIMEOUT BRIEF_DOCS "Timeout for noninteractive executable." FULL_DOCS "Timeout for noninteractive executable.")
  51. macro(add_sdl_test_executable TARGET)
  52. cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
  53. if(AST_UNPARSED_ARGUMENTS)
  54. message(FATAL_ERROR "Unknown argument(s): ${AST_UNPARSED_ARGUMENTS}")
  55. endif()
  56. if(NOT AST_SOURCES)
  57. message(FATAL_ERROR "add_sdl_test_executable needs at least one source")
  58. endif()
  59. if(AST_NEEDS_RESOURCES)
  60. list(APPEND AST_SOURCES ${RESOURCE_FILES})
  61. endif()
  62. add_executable(${TARGET} ${AST_SOURCES})
  63. target_link_libraries(${TARGET} PRIVATE SDL3::SDL3_test SDL3::${sdl_name_component})
  64. if(AST_TESTUTILS)
  65. target_link_libraries(${TARGET} PRIVATE sdltests_utils)
  66. endif()
  67. list(APPEND SDL_TEST_EXECUTABLES ${TARGET})
  68. if(AST_NONINTERACTIVE)
  69. set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE 1)
  70. endif()
  71. if(AST_NONINTERACTIVE_ARGS)
  72. set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS "${AST_NONINTERACTIVE_ARGS}")
  73. endif()
  74. if(AST_NONINTERACTIVE_TIMEOUT)
  75. set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_TIMEOUT "${AST_NONINTERACTIVE_TIMEOUT}")
  76. endif()
  77. if(AST_NEEDS_RESOURCES)
  78. if(PSP OR PS2)
  79. add_custom_command(TARGET ${TARGET} POST_BUILD
  80. COMMAND ${CMAKE_COMMAND} ARGS -E make_directory $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET}
  81. COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET})
  82. else()
  83. add_custom_command(TARGET ${TARGET} POST_BUILD
  84. COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>)
  85. endif()
  86. if(APPLE)
  87. # Make sure resource files get installed into macOS/iOS .app bundles.
  88. set_target_properties(${TARGET} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  89. endif()
  90. set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES "$<TARGET_FILE_DIR:${TARGET}>/$<JOIN:${RESOURCE_FILE_NAMES},$<SEMICOLON>$<TARGET_FILE_DIR:${TARGET}>/>")
  91. endif()
  92. if(WINDOWS)
  93. # CET support was added in VS 16.7
  94. if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
  95. set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -CETCOMPAT")
  96. endif()
  97. elseif(PSP)
  98. target_link_libraries(${TARGET} PRIVATE GL)
  99. endif()
  100. if(OPENGL_FOUND)
  101. target_compile_definitions(${TARGET} PRIVATE HAVE_OPENGL)
  102. endif()
  103. if(TARGET sdl-global-options)
  104. target_link_libraries(${TARGET} PRIVATE $<BUILD_INTERFACE:sdl-global-options>)
  105. endif()
  106. if(SDL3_TESTS_SUBPROJECT)
  107. # FIXME: only add "${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>" + include paths of external dependencies
  108. target_include_directories(${TARGET} PRIVATE "$<TARGET_PROPERTY:SDL3::${sdl_name_component},INCLUDE_DIRECTORIES>")
  109. else()
  110. target_include_directories(${TARGET} PRIVATE "../include")
  111. endif()
  112. endmacro()
  113. check_include_file(signal.h HAVE_SIGNAL_H)
  114. if(HAVE_SIGNAL_H)
  115. add_definitions(-DHAVE_SIGNAL_H)
  116. endif()
  117. check_include_file(libudev.h HAVE_LIBUDEV_H)
  118. if(HAVE_LIBUDEV_H)
  119. add_definitions(-DHAVE_LIBUDEV_H)
  120. endif()
  121. add_sdl_test_executable(checkkeys SOURCES checkkeys.c)
  122. add_sdl_test_executable(checkkeysthreads SOURCES checkkeysthreads.c)
  123. add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS SOURCES loopwave.c)
  124. add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES TESTUTILS SOURCES loopwavequeue.c)
  125. add_sdl_test_executable(testsurround SOURCES testsurround.c)
  126. add_sdl_test_executable(testresample NEEDS_RESOURCES SOURCES testresample.c)
  127. add_sdl_test_executable(testaudioinfo SOURCES testaudioinfo.c)
  128. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  129. add_sdl_test_executable(testautomation NEEDS_RESOURCES SOURCES ${TESTAUTOMATION_SOURCE_FILES})
  130. add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES TESTUTILS SOURCES testmultiaudio.c)
  131. add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES TESTUTILS SOURCES testaudiohotplug.c)
  132. add_sdl_test_executable(testaudiocapture SOURCES testaudiocapture.c)
  133. add_sdl_test_executable(testatomic NONINTERACTIVE SOURCES testatomic.c)
  134. add_sdl_test_executable(testintersections SOURCES testintersections.c)
  135. add_sdl_test_executable(testrelative SOURCES testrelative.c)
  136. add_sdl_test_executable(testhittesting SOURCES testhittesting.c)
  137. add_sdl_test_executable(testdraw SOURCES testdraw.c)
  138. add_sdl_test_executable(testdrawchessboard SOURCES testdrawchessboard.c)
  139. add_sdl_test_executable(testdropfile SOURCES testdropfile.c)
  140. add_sdl_test_executable(testerror NONINTERACTIVE SOURCES testerror.c)
  141. if(LINUX AND SDL3_TESTS_SUBPROJECT)
  142. set(build_options_dependent_tests )
  143. add_sdl_test_executable(testevdev NONINTERACTIVE SOURCES testevdev.c)
  144. list(APPEND build_options_dependent_tests testevdev)
  145. if(APPLE)
  146. add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS
  147. SOURCES
  148. testnative.c
  149. testnativecocoa.m
  150. testnativex11.c
  151. )
  152. target_compile_definitions(testnative PRIVATE TEST_NATIVE_COCOA)
  153. cmake_push_check_state()
  154. check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
  155. cmake_pop_check_state()
  156. if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
  157. set_property(SOURCE "testnativecocoa.m" APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-error=deprecated-declarations")
  158. endif()
  159. list(APPEND build_options_dependent_tests testnative)
  160. elseif(WINDOWS)
  161. add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS SOURCES testnative.ctestnativew32.c)
  162. list(APPEND build_options_dependent_tests testnative)
  163. elseif(HAVE_X11)
  164. add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS SOURCES testnative.c testnativex11.c)
  165. target_link_libraries(testnative PRIVATE X11)
  166. list(APPEND build_options_dependent_tests testnative)
  167. endif()
  168. foreach(t ${build_options_dependent_tests})
  169. target_include_directories(${t} BEFORE PRIVATE $<TARGET_PROPERTY:sdl-build-options,INTERFACE_INCLUDE_DIRECTORIES>)
  170. target_include_directories(${t} BEFORE PRIVATE ${SDL3_SOURCE_DIR}/src)
  171. endforeach()
  172. endif()
  173. add_sdl_test_executable(testfile NONINTERACTIVE SOURCES testfile.c)
  174. add_sdl_test_executable(testgamepad NEEDS_RESOURCES TESTUTILS SOURCES testgamepad.c)
  175. add_sdl_test_executable(testgeometry TESTUTILS SOURCES testgeometry.c)
  176. add_sdl_test_executable(testgl SOURCES testgl.c)
  177. add_sdl_test_executable(testgles SOURCES testgles.c)
  178. add_sdl_test_executable(testgles2 SOURCES testgles2.c)
  179. add_sdl_test_executable(testgles2_sdf TESTUTILS SOURCES testgles2_sdf.c)
  180. add_sdl_test_executable(testhaptic SOURCES testhaptic.c)
  181. add_sdl_test_executable(testhotplug SOURCES testhotplug.c)
  182. add_sdl_test_executable(testrumble SOURCES testrumble.c)
  183. add_sdl_test_executable(testthread NONINTERACTIVE NONINTERACTIVE_TIMEOUT 40 SOURCES testthread.c)
  184. add_sdl_test_executable(testiconv NEEDS_RESOURCES TESTUTILS SOURCES testiconv.c)
  185. add_sdl_test_executable(testime NEEDS_RESOURCES TESTUTILS SOURCES testime.c)
  186. add_sdl_test_executable(testjoystick SOURCES testjoystick.c)
  187. add_sdl_test_executable(testkeys SOURCES testkeys.c)
  188. add_sdl_test_executable(testloadso SOURCES testloadso.c)
  189. add_sdl_test_executable(testlocale NONINTERACTIVE SOURCES testlocale.c)
  190. add_sdl_test_executable(testlock SOURCES testlock.c)
  191. add_sdl_test_executable(testmouse SOURCES testmouse.c)
  192. add_sdl_test_executable(testoverlay NEEDS_RESOURCES TESTUTILS SOURCES testoverlay.c)
  193. add_sdl_test_executable(testplatform NONINTERACTIVE SOURCES testplatform.c)
  194. add_sdl_test_executable(testpower NONINTERACTIVE SOURCES testpower.c)
  195. add_sdl_test_executable(testfilesystem NONINTERACTIVE SOURCES testfilesystem.c)
  196. add_sdl_test_executable(testrendertarget NEEDS_RESOURCES TESTUTILS SOURCES testrendertarget.c)
  197. add_sdl_test_executable(testscale NEEDS_RESOURCES TESTUTILS SOURCES testscale.c)
  198. add_sdl_test_executable(testsem NONINTERACTIVE NONINTERACTIVE_ARGS 10 NONINTERACTIVE_TIMEOUT 30 SOURCES testsem.c)
  199. add_sdl_test_executable(testsensor SOURCES testsensor.c)
  200. add_sdl_test_executable(testshader NEEDS_RESOURCES TESTUTILS SOURCES testshader.c)
  201. add_sdl_test_executable(testshape NEEDS_RESOURCES SOURCES testshape.c)
  202. add_sdl_test_executable(testsprite NEEDS_RESOURCES TESTUTILS SOURCES testsprite.c)
  203. add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES TESTUTILS SOURCES testspriteminimal.c)
  204. add_sdl_test_executable(teststreaming NEEDS_RESOURCES TESTUTILS SOURCES teststreaming.c)
  205. add_sdl_test_executable(testtimer NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c)
  206. add_sdl_test_executable(testurl SOURCES testurl.c)
  207. add_sdl_test_executable(testver NONINTERACTIVE SOURCES testver.c)
  208. add_sdl_test_executable(testviewport NEEDS_RESOURCES TESTUTILS SOURCES testviewport.c)
  209. add_sdl_test_executable(testwm SOURCES testwm.c)
  210. add_sdl_test_executable(testyuv NONINTERACTIVE NONINTERACTIVE_ARGS "--automated" NEEDS_RESOURCES TESTUTILS SOURCES testyuv.c testyuv_cvt.c)
  211. add_sdl_test_executable(torturethread NONINTERACTIVE NONINTERACTIVE_TIMEOUT 30 SOURCES torturethread.c)
  212. add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES TESTUTILS SOURCES testrendercopyex.c)
  213. add_sdl_test_executable(testmessage SOURCES testmessage.c)
  214. add_sdl_test_executable(testdisplayinfo SOURCES testdisplayinfo.c)
  215. add_sdl_test_executable(testqsort NONINTERACTIVE SOURCES testqsort.c)
  216. add_sdl_test_executable(testbounds NONINTERACTIVE SOURCES testbounds.c)
  217. add_sdl_test_executable(testcustomcursor SOURCES testcustomcursor.c)
  218. add_sdl_test_executable(gamepadmap NEEDS_RESOURCES TESTUTILS SOURCES gamepadmap.c)
  219. add_sdl_test_executable(testvulkan SOURCES testvulkan.c)
  220. add_sdl_test_executable(testoffscreen SOURCES testoffscreen.c)
  221. add_sdl_test_executable(testpopup SOURCES testpopup.c)
  222. check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
  223. if(HAVE_WFORMAT_OVERFLOW)
  224. target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
  225. endif()
  226. check_c_compiler_flag(-Wformat HAVE_WFORMAT)
  227. if(HAVE_WFORMAT)
  228. target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
  229. endif()
  230. cmake_push_check_state()
  231. if(HAVE_WFORMAT)
  232. # Some compilers ignore -Wformat-extra-args without -Wformat
  233. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wformat")
  234. endif()
  235. check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
  236. cmake_pop_check_state()
  237. if(HAVE_WFORMAT_EXTRA_ARGS)
  238. target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
  239. endif()
  240. if(SDL_DUMMYAUDIO)
  241. set_property(TARGET testaudioinfo PROPERTY SDL_NONINTERACTIVE 1)
  242. set_property(TARGET testsurround PROPERTY SDL_NONINTERACTIVE 1)
  243. endif()
  244. if(SDL_DUMMYVIDEO)
  245. set_property(TARGET testkeys PROPERTY SDL_NONINTERACTIVE 1)
  246. set_property(TARGET testbounds PROPERTY SDL_NONINTERACTIVE 1)
  247. set_property(TARGET testdisplayinfo PROPERTY SDL_NONINTERACTIVE 1)
  248. endif()
  249. if(OPENGL_FOUND)
  250. if(TARGET OpenGL::GL)
  251. target_link_libraries(testshader PRIVATE OpenGL::GL)
  252. target_link_libraries(testgl PRIVATE OpenGL::GL)
  253. else()
  254. if(EMSCRIPTEN AND OPENGL_gl_LIBRARY STREQUAL "nul")
  255. set(OPENGL_gl_LIBRARY GL)
  256. endif()
  257. # emscripten's FindOpenGL.cmake does not create OpenGL::GL
  258. target_link_libraries(testshader PRIVATE ${OPENGL_gl_LIBRARY})
  259. target_link_libraries(testgl PRIVATE ${OPENGL_gl_LIBRARY})
  260. endif()
  261. endif()
  262. if(EMSCRIPTEN)
  263. set_property(TARGET testshader APPEND_STRING PROPERTY LINK_FLAGS " -sLEGACY_GL_EMULATION")
  264. endif()
  265. if(PSP)
  266. # Build EBOOT files if building for PSP
  267. foreach(APP ${SDL_TEST_EXECUTABLES})
  268. create_pbp_file(
  269. TARGET ${APP}
  270. TITLE SDL-${APP}
  271. ICON_PATH NULL
  272. BACKGROUND_PATH NULL
  273. PREVIEW_PATH NULL
  274. )
  275. add_custom_command(
  276. TARGET ${APP} POST_BUILD
  277. COMMAND ${CMAKE_COMMAND} -E make_directory
  278. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  279. )
  280. add_custom_command(
  281. TARGET ${APP} POST_BUILD
  282. COMMAND ${CMAKE_COMMAND} -E rename
  283. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  284. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  285. )
  286. if(BUILD_PRX)
  287. add_custom_command(
  288. TARGET ${APP} POST_BUILD
  289. COMMAND ${CMAKE_COMMAND} -E copy
  290. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  291. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  292. )
  293. add_custom_command(
  294. TARGET ${APP} POST_BUILD
  295. COMMAND ${CMAKE_COMMAND} -E rename
  296. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  297. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  298. )
  299. endif()
  300. add_custom_command(
  301. TARGET ${APP} POST_BUILD
  302. COMMAND ${CMAKE_COMMAND} -E remove
  303. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  304. )
  305. endforeach()
  306. endif()
  307. if(N3DS)
  308. set(ROMFS_DIR "${CMAKE_CURRENT_BINARY_DIR}/romfs")
  309. file(COPY ${RESOURCE_FILES} DESTINATION "${ROMFS_DIR}")
  310. foreach(APP ${SDL_TEST_EXECUTABLES})
  311. get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR)
  312. set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh")
  313. ctr_generate_smdh("${SMDH_FILE}"
  314. NAME "SDL-${APP}"
  315. DESCRIPTION "SDL3 Test suite"
  316. AUTHOR "SDL3 Contributors"
  317. ICON "${CMAKE_CURRENT_SOURCE_DIR}/n3ds/logo48x48.png"
  318. )
  319. ctr_create_3dsx(
  320. ${APP}
  321. ROMFS "${ROMFS_DIR}"
  322. SMDH "${SMDH_FILE}"
  323. )
  324. endforeach()
  325. endif()
  326. if(RISCOS)
  327. set(SDL_TEST_EXECUTABLES_AIF)
  328. foreach(APP ${SDL_TEST_EXECUTABLES})
  329. set_property(TARGET ${APP} APPEND_STRING PROPERTY LINK_FLAGS " -static")
  330. add_custom_command(
  331. OUTPUT ${APP},ff8
  332. COMMAND elf2aif ${APP} ${APP},ff8
  333. DEPENDS ${APP}
  334. )
  335. add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
  336. list(APPEND SDL_TEST_EXECUTABLES_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
  337. endforeach()
  338. endif()
  339. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  340. # platforms (iOS, for example).
  341. if(APPLE)
  342. if(CMAKE_VERSION VERSION_LESS "3.7.0")
  343. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  344. # CMake 3.7 and above.
  345. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  346. else()
  347. foreach(CURRENT_TARGET ${SDL_TEST_EXECUTABLES})
  348. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  349. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  350. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL3_VERSION}"
  351. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL3_VERSION}"
  352. )
  353. endforeach()
  354. endif()
  355. endif()
  356. set(TESTS_ENVIRONMENT
  357. SDL_AUDIO_DRIVER=dummy
  358. SDL_VIDEO_DRIVER=dummy
  359. PATH=$<TARGET_FILE_DIR:SDL3::${sdl_name_component}>
  360. )
  361. foreach(TEST ${SDL_TEST_EXECUTABLES})
  362. get_property(noninteractive TARGET ${TEST} PROPERTY SDL_NONINTERACTIVE)
  363. if(noninteractive)
  364. set(command ${TEST})
  365. get_property(noninteractive_arguments TARGET ${TEST} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS)
  366. if(noninteractive_arguments)
  367. list(APPEND command ${noninteractive_arguments})
  368. endif()
  369. add_test(
  370. NAME ${TEST}
  371. COMMAND ${command}
  372. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  373. )
  374. set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}")
  375. get_property(noninteractive_timeout TARGET ${TEST} PROPERTY SDL_NONINTERACTIVE_TIMEOUT)
  376. if(NOT noninteractive_timeout)
  377. set(noninteractive_timeout 10)
  378. endif()
  379. math(EXPR noninteractive_timeout "${noninteractive_timeout}*${SDL_TESTS_TIMEOUT_MULTIPLIER}")
  380. set_tests_properties(${TEST} PROPERTIES TIMEOUT "${noninteractive_timeout}")
  381. if(SDL_INSTALL_TESTS)
  382. set(exe ${TEST})
  383. set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3")
  384. configure_file(template.test.in "${exe}.test" @ONLY)
  385. install(
  386. FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
  387. DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL3
  388. )
  389. endif()
  390. endif()
  391. endforeach()
  392. if(SDL_INSTALL_TESTS)
  393. if(RISCOS)
  394. install(
  395. FILES ${SDL_TEST_EXECUTABLES_AIF}
  396. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3
  397. )
  398. else()
  399. install(
  400. TARGETS ${SDL_TEST_EXECUTABLES}
  401. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3
  402. )
  403. endif()
  404. install(
  405. FILES ${RESOURCE_FILES}
  406. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3
  407. )
  408. endif()