CMakeLists.txt 21 KB

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