CMakeLists.txt 19 KB

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