🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

446 lines
15 KiB

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