CMakeLists.txt 19 KB

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