CMakeLists.txt 19 KB

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