CMakeLists.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. cmake_minimum_required(VERSION 3.0...3.10)
  2. project(SDL2_test C)
  3. include(CheckCCompilerFlag)
  4. include(CMakeParseArguments)
  5. include(CMakePushCheckState)
  6. set(SDL_TEST_EXECUTABLES)
  7. set(SDL_TESTS_NONINTERACTIVE)
  8. set(SDL_TESTS_NEEDS_RESOURCES)
  9. macro(add_sdl_test_executable TARGET)
  10. cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES" "" "" ${ARGN})
  11. if(ANDROID)
  12. add_library(${TARGET} SHARED ${AST_UNPARSED_ARGUMENTS})
  13. else()
  14. add_executable(${TARGET} ${AST_UNPARSED_ARGUMENTS})
  15. endif()
  16. list(APPEND SDL_TEST_EXECUTABLES ${TARGET})
  17. if(AST_NONINTERACTIVE)
  18. list(APPEND SDL_TESTS_NONINTERACTIVE ${TARGET})
  19. endif()
  20. if(AST_NEEDS_RESOURCES)
  21. list(APPEND SDL_TESTS_NEEDS_RESOURCES ${TARGET})
  22. endif()
  23. if(HAVE_GCC_WDOCUMENTATION)
  24. target_compile_options(${TARGET} PRIVATE "-Wdocumentation")
  25. if(HAVE_GCC_WERROR_DOCUMENTATION)
  26. target_compile_options(${TARGET} PRIVATE "-Werror=documentation")
  27. endif()
  28. endif()
  29. if(HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND)
  30. if(SDL_WERROR)
  31. if(HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND)
  32. target_compile_options(${TARGET} PRIVATE "-Werror=documentation-unknown-command")
  33. endif()
  34. endif()
  35. target_compile_options(${TARGET} PRIVATE "-Wdocumentation-unknown-command")
  36. endif()
  37. if(HAVE_GCC_COMMENT_BLOCK_COMMANDS)
  38. target_compile_options(${TARGET} PRIVATE "-fcomment-block-commands=threadsafety")
  39. target_compile_options(${TARGET} PRIVATE "-fcomment-block-commands=deprecated")
  40. else()
  41. if(HAVE_CLANG_COMMENT_BLOCK_COMMANDS)
  42. target_compile_options(${TARGET} PRIVATE "/clang:-fcomment-block-commands=threadsafety")
  43. target_compile_options(${TARGET} PRIVATE "/clang:-fcomment-block-commands=deprecated")
  44. endif()
  45. endif()
  46. if(USE_GCC OR USE_CLANG)
  47. check_c_compiler_flag(-fno-fast-math HAVE_GCC_FNO_FAST_MATH)
  48. if(HAVE_GCC_FNO_FAST_MATH)
  49. target_compile_options(${TARGET} PRIVATE -fno-fast-math)
  50. endif()
  51. endif()
  52. endmacro()
  53. if(NOT TARGET SDL2::SDL2-static)
  54. find_package(SDL2 2.0.23 REQUIRED COMPONENTS SDL2-static SDL2test)
  55. endif()
  56. enable_testing()
  57. if(SDL_INSTALL_TESTS)
  58. include(GNUInstallDirs)
  59. endif()
  60. if(N3DS)
  61. link_libraries(SDL2::SDL2main)
  62. endif()
  63. if(PSP)
  64. link_libraries(
  65. SDL2::SDL2main
  66. SDL2::SDL2test
  67. SDL2::SDL2-static
  68. GL
  69. pspvram
  70. pspvfpu
  71. pspdisplay
  72. pspgu
  73. pspge
  74. pspaudio
  75. pspctrl
  76. psphprm
  77. psppower
  78. )
  79. elseif(PS2)
  80. link_libraries(
  81. SDL2main
  82. SDL2_test
  83. SDL2-static
  84. patches
  85. gskit
  86. dmakit
  87. ps2_drivers
  88. )
  89. elseif(IOS OR TVOS)
  90. link_libraries(SDL2::SDL2main SDL2::SDL2test SDL2::SDL2-static)
  91. else()
  92. link_libraries(SDL2::SDL2test SDL2::SDL2-static)
  93. endif()
  94. if(WINDOWS)
  95. # mingw32 must come before SDL2main to link successfully
  96. if(MINGW OR CYGWIN)
  97. link_libraries(mingw32)
  98. endif()
  99. # CET support was added in VS 16.7
  100. if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
  101. link_libraries(-CETCOMPAT)
  102. endif()
  103. # FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
  104. # but we need them for VS as well.
  105. link_libraries(SDL2main)
  106. add_definitions(-Dmain=SDL_main)
  107. endif()
  108. # CMake incorrectly detects opengl32.lib being present on MSVC ARM64
  109. if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
  110. # Prefer GLVND, if present
  111. set(OpenGL_GL_PREFERENCE GLVND)
  112. find_package(OpenGL)
  113. endif()
  114. if (OPENGL_FOUND)
  115. add_definitions(-DHAVE_OPENGL)
  116. endif()
  117. add_sdl_test_executable(checkkeys checkkeys.c)
  118. add_sdl_test_executable(checkkeysthreads checkkeysthreads.c)
  119. add_sdl_test_executable(loopwave NEEDS_RESOURCES loopwave.c testutils.c)
  120. add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES loopwavequeue.c testutils.c)
  121. add_sdl_test_executable(testsurround testsurround.c)
  122. add_sdl_test_executable(testresample NEEDS_RESOURCES testresample.c)
  123. add_sdl_test_executable(testaudioinfo testaudioinfo.c)
  124. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  125. add_sdl_test_executable(testautomation NONINTERACTIVE NEEDS_RESOURCES ${TESTAUTOMATION_SOURCE_FILES})
  126. add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES testmultiaudio.c testutils.c)
  127. add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES testaudiohotplug.c testutils.c)
  128. add_sdl_test_executable(testaudiocapture testaudiocapture.c)
  129. add_sdl_test_executable(testatomic NONINTERACTIVE testatomic.c)
  130. add_sdl_test_executable(testintersections testintersections.c)
  131. add_sdl_test_executable(testrelative testrelative.c)
  132. add_sdl_test_executable(testhittesting testhittesting.c)
  133. add_sdl_test_executable(testdraw2 testdraw2.c)
  134. add_sdl_test_executable(testdrawchessboard testdrawchessboard.c)
  135. add_sdl_test_executable(testdropfile testdropfile.c)
  136. add_sdl_test_executable(testerror NONINTERACTIVE testerror.c)
  137. if(LINUX)
  138. add_sdl_test_executable(testevdev NONINTERACTIVE testevdev.c)
  139. endif()
  140. add_sdl_test_executable(testfile testfile.c)
  141. add_sdl_test_executable(testgamecontroller NEEDS_RESOURCES testgamecontroller.c testutils.c)
  142. add_sdl_test_executable(testgeometry testgeometry.c testutils.c)
  143. add_sdl_test_executable(testgesture testgesture.c)
  144. add_sdl_test_executable(testgl2 testgl2.c)
  145. add_sdl_test_executable(testgles testgles.c)
  146. add_sdl_test_executable(testgles2 testgles2.c)
  147. add_sdl_test_executable(testgles2_sdf NEEDS_RESOURCES testgles2_sdf.c testutils.c)
  148. add_sdl_test_executable(testhaptic testhaptic.c)
  149. add_sdl_test_executable(testhotplug testhotplug.c)
  150. add_sdl_test_executable(testrumble testrumble.c)
  151. add_sdl_test_executable(testthread NONINTERACTIVE testthread.c)
  152. add_sdl_test_executable(testiconv NEEDS_RESOURCES testiconv.c testutils.c)
  153. add_sdl_test_executable(testime NEEDS_RESOURCES testime.c testutils.c)
  154. add_sdl_test_executable(testjoystick testjoystick.c)
  155. add_sdl_test_executable(testkeys testkeys.c)
  156. add_sdl_test_executable(testloadso testloadso.c)
  157. add_sdl_test_executable(testlocale NONINTERACTIVE testlocale.c)
  158. add_sdl_test_executable(testlock testlock.c)
  159. add_sdl_test_executable(testmouse testmouse.c)
  160. if(APPLE)
  161. add_sdl_test_executable(testnative NEEDS_RESOURCES
  162. testnative.c
  163. testnativecocoa.m
  164. testnativex11.c
  165. testutils.c
  166. )
  167. cmake_push_check_state(RESET)
  168. check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
  169. cmake_pop_check_state()
  170. if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
  171. set_property(SOURCE "testnativecocoa.m" APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-error=deprecated-declarations")
  172. endif()
  173. elseif(WINDOWS)
  174. add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativew32.c testutils.c)
  175. elseif(HAVE_X11)
  176. add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativex11.c testutils.c)
  177. target_link_libraries(testnative X11)
  178. elseif(OS2)
  179. add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativeos2.c testutils.c)
  180. endif()
  181. add_sdl_test_executable(testoverlay2 NEEDS_RESOURCES testoverlay2.c testyuv_cvt.c testutils.c)
  182. add_sdl_test_executable(testplatform NONINTERACTIVE testplatform.c)
  183. add_sdl_test_executable(testpower NONINTERACTIVE testpower.c)
  184. add_sdl_test_executable(testfilesystem NONINTERACTIVE testfilesystem.c)
  185. if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
  186. add_sdl_test_executable(testfilesystem_pre NONINTERACTIVE testfilesystem_pre.c)
  187. endif()
  188. add_sdl_test_executable(testrendertarget NEEDS_RESOURCES testrendertarget.c testutils.c)
  189. add_sdl_test_executable(testscale NEEDS_RESOURCES testscale.c testutils.c)
  190. add_sdl_test_executable(testsem testsem.c)
  191. add_sdl_test_executable(testsensor testsensor.c)
  192. add_sdl_test_executable(testshader NEEDS_RESOURCES testshader.c)
  193. add_sdl_test_executable(testshape NEEDS_RESOURCES testshape.c)
  194. add_sdl_test_executable(testsprite2 NEEDS_RESOURCES testsprite2.c testutils.c)
  195. add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES testspriteminimal.c testutils.c)
  196. add_sdl_test_executable(teststreaming NEEDS_RESOURCES teststreaming.c testutils.c)
  197. add_sdl_test_executable(testtimer NONINTERACTIVE testtimer.c)
  198. add_sdl_test_executable(testurl testurl.c)
  199. add_sdl_test_executable(testver NONINTERACTIVE testver.c)
  200. add_sdl_test_executable(testviewport NEEDS_RESOURCES testviewport.c testutils.c)
  201. add_sdl_test_executable(testwm2 testwm2.c)
  202. add_sdl_test_executable(testyuv NEEDS_RESOURCES testyuv.c testyuv_cvt.c)
  203. add_sdl_test_executable(torturethread torturethread.c)
  204. add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES testrendercopyex.c testutils.c)
  205. add_sdl_test_executable(testmessage testmessage.c)
  206. add_sdl_test_executable(testdisplayinfo testdisplayinfo.c)
  207. add_sdl_test_executable(testqsort NONINTERACTIVE testqsort.c)
  208. add_sdl_test_executable(testbounds testbounds.c)
  209. add_sdl_test_executable(testcustomcursor testcustomcursor.c)
  210. add_sdl_test_executable(controllermap NEEDS_RESOURCES controllermap.c testutils.c)
  211. add_sdl_test_executable(testvulkan testvulkan.c)
  212. add_sdl_test_executable(testoffscreen testoffscreen.c)
  213. cmake_push_check_state(RESET)
  214. check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
  215. if(HAVE_WFORMAT_OVERFLOW)
  216. target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
  217. endif()
  218. check_c_compiler_flag(-Wformat HAVE_WFORMAT)
  219. if(HAVE_WFORMAT)
  220. target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
  221. endif()
  222. check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
  223. if(HAVE_WFORMAT_EXTRA_ARGS)
  224. target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
  225. endif()
  226. cmake_pop_check_state()
  227. if(SDL_DUMMYAUDIO)
  228. list(APPEND SDL_TESTS_NONINTERACTIVE
  229. testaudioinfo
  230. testsurround
  231. )
  232. endif()
  233. if(SDL_DUMMYVIDEO)
  234. list(APPEND SDL_TESTS_NONINTERACTIVE
  235. testkeys
  236. testbounds
  237. testdisplayinfo
  238. )
  239. endif()
  240. if(OPENGL_FOUND)
  241. if(TARGET OpenGL::GL)
  242. target_link_libraries(testshader OpenGL::GL)
  243. target_link_libraries(testgl2 OpenGL::GL)
  244. else()
  245. if(EMSCRIPTEN AND OPENGL_gl_LIBRARY STREQUAL "nul")
  246. set(OPENGL_gl_LIBRARY GL)
  247. endif()
  248. # emscripten's FindOpenGL.cmake does not create OpenGL::GL
  249. target_link_libraries(testshader ${OPENGL_gl_LIBRARY})
  250. target_link_libraries(testgl2 ${OPENGL_gl_LIBRARY})
  251. endif()
  252. endif()
  253. if(EMSCRIPTEN)
  254. target_link_libraries(testshader -sLEGACY_GL_EMULATION)
  255. endif()
  256. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  257. file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  258. if(PSP)
  259. # Build EBOOT files if building for PSP
  260. set(BUILD_EBOOT
  261. ${SDL_TESTS_NEEDS_RESOURCES}
  262. testatomic
  263. testaudiocapture
  264. testaudioinfo
  265. testbounds
  266. testdisplayinfo
  267. testdraw2
  268. testdrawchessboard
  269. testerror
  270. testfile
  271. testfilesystem
  272. testgeometry
  273. testgl2
  274. testhittesting
  275. testiconv
  276. testintersections
  277. testjoystick
  278. testlock
  279. testmessage
  280. testoverlay2
  281. testplatform
  282. testpower
  283. testqsort
  284. testsem
  285. teststreaming
  286. testsurround
  287. testthread
  288. testtimer
  289. testver
  290. testviewport
  291. testwm2
  292. torturethread
  293. )
  294. foreach(APP IN LISTS BUILD_EBOOT)
  295. create_pbp_file(
  296. TARGET ${APP}
  297. TITLE SDL-${APP}
  298. ICON_PATH NULL
  299. BACKGROUND_PATH NULL
  300. PREVIEW_PATH NULL
  301. )
  302. add_custom_command(
  303. TARGET ${APP} POST_BUILD
  304. COMMAND ${CMAKE_COMMAND} -E make_directory
  305. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  306. )
  307. add_custom_command(
  308. TARGET ${APP} POST_BUILD
  309. COMMAND ${CMAKE_COMMAND} -E rename
  310. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  311. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  312. )
  313. if(${BUILD_PRX})
  314. add_custom_command(
  315. TARGET ${APP} POST_BUILD
  316. COMMAND ${CMAKE_COMMAND} -E copy
  317. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  318. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  319. )
  320. add_custom_command(
  321. TARGET ${APP} POST_BUILD
  322. COMMAND ${CMAKE_COMMAND} -E rename
  323. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  324. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  325. )
  326. endif()
  327. add_custom_command(
  328. TARGET ${APP} POST_BUILD
  329. COMMAND ${CMAKE_COMMAND} -E remove
  330. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  331. )
  332. endforeach()
  333. endif()
  334. if(N3DS)
  335. foreach(APP IN LISTS SDL_TEST_EXECUTABLES)
  336. get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR)
  337. set(ROMFS_DIR "${TARGET_BINARY_DIR}/sdl-${APP}")
  338. set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh")
  339. file(MAKE_DIRECTORY ${ROMFS_DIR})
  340. ctr_generate_smdh("${SMDH_FILE}"
  341. NAME "SDL-${APP}"
  342. DESCRIPTION "SDL2 Test suite"
  343. AUTHOR "SDL2 Contributors"
  344. ICON "${CMAKE_CURRENT_SOURCE_DIR}/n3ds/logo48x48.png"
  345. )
  346. ctr_create_3dsx(
  347. ${APP}
  348. ROMFS "${ROMFS_DIR}"
  349. SMDH "${SMDH_FILE}"
  350. )
  351. endforeach()
  352. endif()
  353. if(RISCOS)
  354. set(SDL_TEST_EXECUTABLES_AIF)
  355. foreach(APP IN LISTS SDL_TEST_EXECUTABLES)
  356. target_link_options(${APP} PRIVATE -static)
  357. add_custom_command(
  358. OUTPUT ${APP},ff8
  359. COMMAND elf2aif ${APP} ${APP},ff8
  360. DEPENDS ${APP}
  361. )
  362. add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
  363. list(APPEND SDL_TEST_EXECUTABLES_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
  364. endforeach()
  365. endif()
  366. if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  367. set(test_bin_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
  368. if(NOT IS_ABSOLUTE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
  369. set(test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
  370. endif()
  371. else()
  372. set(test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}")
  373. endif()
  374. if(NOT CMAKE_VERSION VERSION_LESS 3.20)
  375. get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  376. set(test_bin_dir "${test_bin_dir}$<$<BOOL:${is_multi_config}>:/$<CONFIG>>")
  377. endif()
  378. set(RESOURCE_FILES_BINDIR)
  379. foreach(resource_file IN LISTS RESOURCE_FILES)
  380. get_filename_component(res_file_name ${resource_file} NAME)
  381. set(resource_file_bindir "${test_bin_dir}/${res_file_name}")
  382. add_custom_command(OUTPUT "${resource_file_bindir}"
  383. COMMAND "${CMAKE_COMMAND}" -E copy "${resource_file}" "${resource_file_bindir}"
  384. DEPENDS "${resource_file}"
  385. )
  386. list(APPEND RESOURCE_FILES_BINDIR "${resource_file_bindir}")
  387. endforeach()
  388. add_custom_target(copy-sdl-test-resources
  389. DEPENDS "${RESOURCE_FILES_BINDIR}"
  390. )
  391. foreach(APP IN LISTS SDL_TESTS_NEEDS_RESOURCES)
  392. if(PSP OR PS2 OR N3DS)
  393. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  394. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
  395. endforeach()
  396. else()
  397. add_dependencies(${APP} copy-sdl-test-resources)
  398. endif()
  399. if(APPLE)
  400. # Make sure resource files get installed into macOS/iOS .app bundles.
  401. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  402. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  403. endif()
  404. endforeach()
  405. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  406. # platforms (iOS, for example).
  407. if(APPLE)
  408. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  409. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  410. # CMake 3.7 and above.
  411. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  412. else()
  413. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  414. foreach(CURRENT_TARGET IN LISTS TARGETS)
  415. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  416. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  417. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  418. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  419. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  420. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  421. )
  422. endif()
  423. endforeach()
  424. endif()
  425. endif()
  426. set(TESTS_ENVIRONMENT
  427. SDL_AUDIODRIVER=dummy
  428. SDL_VIDEODRIVER=dummy
  429. )
  430. foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE})
  431. add_test(
  432. NAME ${TESTCASE}
  433. COMMAND ${TESTCASE}
  434. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  435. )
  436. set_tests_properties(${TESTCASE}
  437. PROPERTIES
  438. ENVIRONMENT "${TESTS_ENVIRONMENT}"
  439. TIMEOUT 10
  440. )
  441. if(SDL_INSTALL_TESTS)
  442. set(exe ${TESTCASE})
  443. set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")
  444. configure_file(template.test.in "${exe}.test" @ONLY)
  445. install(
  446. FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
  447. DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL2
  448. )
  449. endif()
  450. endforeach()
  451. set_tests_properties(testautomation PROPERTIES TIMEOUT 120)
  452. set_tests_properties(testthread PROPERTIES TIMEOUT 40)
  453. set_tests_properties(testtimer PROPERTIES TIMEOUT 60)
  454. if(TARGET testfilesystem_pre)
  455. set_property(TEST testfilesystem_pre PROPERTY TIMEOUT 60)
  456. set_property(TEST testfilesystem APPEND PROPERTY DEPENDS testfilesystem_pre)
  457. endif()
  458. if(SDL_INSTALL_TESTS)
  459. if(RISCOS)
  460. install(
  461. FILES ${SDL_TEST_EXECUTABLES_AIF}
  462. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  463. )
  464. else()
  465. install(
  466. TARGETS ${SDL_TEST_EXECUTABLES}
  467. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  468. )
  469. endif()
  470. if(MSVC)
  471. foreach(test ${SDL_TEST_EXECUTABLES})
  472. SDL_install_pdb(${test} "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2")
  473. endforeach()
  474. endif()
  475. install(
  476. FILES ${RESOURCE_FILES}
  477. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  478. )
  479. endif()