CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. cmake_minimum_required(VERSION 3.0)
  2. project(SDL2_test)
  3. if(NOT TARGET SDL2::SDL2-static)
  4. find_package(SDL2 2.0.23 REQUIRED COMPONENTS SDL2-static SDL2test)
  5. endif()
  6. enable_testing()
  7. if(SDL_INSTALL_TESTS)
  8. include(GNUInstallDirs)
  9. endif()
  10. if(PSP)
  11. link_libraries(
  12. SDL2::SDL2main
  13. SDL2::SDL2test
  14. SDL2::SDL2-static
  15. GL
  16. pspvram
  17. pspvfpu
  18. pspdisplay
  19. pspgu
  20. pspge
  21. pspaudio
  22. pspctrl
  23. psphprm
  24. psppower
  25. )
  26. elseif(PS2)
  27. link_libraries(
  28. SDL2main
  29. SDL2_test
  30. SDL2-static
  31. patches
  32. gskit
  33. dmakit
  34. ps2_drivers
  35. )
  36. else()
  37. link_libraries(SDL2::SDL2test SDL2::SDL2-static)
  38. endif()
  39. if(WINDOWS)
  40. # mingw32 must come before SDL2main to link successfully
  41. if(MINGW OR CYGWIN)
  42. link_libraries(mingw32)
  43. endif()
  44. # FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
  45. # but we need them for VS as well.
  46. link_libraries(SDL2main)
  47. add_definitions(-Dmain=SDL_main)
  48. endif()
  49. # CMake incorrectly detects opengl32.lib being present on MSVC ARM64
  50. if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
  51. # Prefer GLVND, if present
  52. set(OpenGL_GL_PREFERENCE GLVND)
  53. find_package(OpenGL)
  54. endif()
  55. if (OPENGL_FOUND)
  56. add_definitions(-DHAVE_OPENGL)
  57. endif()
  58. add_executable(checkkeys checkkeys.c)
  59. add_executable(checkkeysthreads checkkeysthreads.c)
  60. add_executable(loopwave loopwave.c testutils.c)
  61. add_executable(loopwavequeue loopwavequeue.c testutils.c)
  62. add_executable(testsurround testsurround.c)
  63. add_executable(testresample testresample.c)
  64. add_executable(testaudioinfo testaudioinfo.c)
  65. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  66. add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
  67. add_executable(testmultiaudio testmultiaudio.c testutils.c)
  68. add_executable(testaudiohotplug testaudiohotplug.c testutils.c)
  69. add_executable(testaudiocapture testaudiocapture.c)
  70. add_executable(testatomic testatomic.c)
  71. add_executable(testintersections testintersections.c)
  72. add_executable(testrelative testrelative.c)
  73. add_executable(testhittesting testhittesting.c)
  74. add_executable(testdraw2 testdraw2.c)
  75. add_executable(testdrawchessboard testdrawchessboard.c)
  76. add_executable(testdropfile testdropfile.c)
  77. add_executable(testerror testerror.c)
  78. if(LINUX)
  79. add_executable(testevdev testevdev.c)
  80. endif()
  81. add_executable(testfile testfile.c)
  82. add_executable(testgamecontroller testgamecontroller.c testutils.c)
  83. add_executable(testgeometry testgeometry.c testutils.c)
  84. add_executable(testgesture testgesture.c)
  85. add_executable(testgl2 testgl2.c)
  86. add_executable(testgles testgles.c)
  87. add_executable(testgles2 testgles2.c)
  88. add_executable(testhaptic testhaptic.c)
  89. add_executable(testhotplug testhotplug.c)
  90. add_executable(testrumble testrumble.c)
  91. add_executable(testthread testthread.c)
  92. add_executable(testiconv testiconv.c testutils.c)
  93. add_executable(testime testime.c testutils.c)
  94. add_executable(testjoystick testjoystick.c)
  95. add_executable(testkeys testkeys.c)
  96. add_executable(testloadso testloadso.c)
  97. add_executable(testlocale testlocale.c)
  98. add_executable(testlock testlock.c)
  99. add_executable(testmouse testmouse.c)
  100. if(APPLE)
  101. add_executable(testnative testnative.c
  102. testnativecocoa.m
  103. testnativex11.c
  104. testutils.c)
  105. elseif(WINDOWS)
  106. add_executable(testnative testnative.c testnativew32.c testutils.c)
  107. elseif(HAVE_X11)
  108. add_executable(testnative testnative.c testnativex11.c testutils.c)
  109. target_link_libraries(testnative X11)
  110. endif()
  111. add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c testutils.c)
  112. add_executable(testplatform testplatform.c)
  113. add_executable(testpower testpower.c)
  114. add_executable(testfilesystem testfilesystem.c)
  115. add_executable(testrendertarget testrendertarget.c testutils.c)
  116. add_executable(testscale testscale.c testutils.c)
  117. add_executable(testsem testsem.c)
  118. add_executable(testsensor testsensor.c)
  119. add_executable(testshader testshader.c)
  120. add_executable(testshape testshape.c)
  121. add_executable(testsprite2 testsprite2.c testutils.c)
  122. add_executable(testspriteminimal testspriteminimal.c testutils.c)
  123. add_executable(teststreaming teststreaming.c testutils.c)
  124. add_executable(testtimer testtimer.c)
  125. add_executable(testurl testurl.c)
  126. add_executable(testver testver.c)
  127. add_executable(testviewport testviewport.c testutils.c)
  128. add_executable(testwm2 testwm2.c)
  129. add_executable(testyuv testyuv.c testyuv_cvt.c)
  130. add_executable(torturethread torturethread.c)
  131. add_executable(testrendercopyex testrendercopyex.c testutils.c)
  132. add_executable(testmessage testmessage.c)
  133. add_executable(testdisplayinfo testdisplayinfo.c)
  134. add_executable(testqsort testqsort.c)
  135. add_executable(testbounds testbounds.c)
  136. add_executable(testcustomcursor testcustomcursor.c)
  137. add_executable(controllermap controllermap.c testutils.c)
  138. add_executable(testvulkan testvulkan.c)
  139. add_executable(testoffscreen testoffscreen.c)
  140. SET(ALL_TESTS
  141. checkkeys
  142. checkkeysthreads
  143. controllermap
  144. loopwave
  145. loopwavequeue
  146. testatomic
  147. testaudiocapture
  148. testaudiohotplug
  149. testaudioinfo
  150. testautomation
  151. testbounds
  152. testcustomcursor
  153. testdisplayinfo
  154. testdraw2
  155. testdrawchessboard
  156. testdropfile
  157. testerror
  158. testfile
  159. testfilesystem
  160. testgamecontroller
  161. testgeometry
  162. testgesture
  163. testgl2
  164. testgles
  165. testgles2
  166. testhaptic
  167. testhittesting
  168. testhotplug
  169. testiconv
  170. testime
  171. testintersections
  172. testjoystick
  173. testkeys
  174. testloadso
  175. testlocale
  176. testlock
  177. testmessage
  178. testmouse
  179. testmultiaudio
  180. testoffscreen
  181. testoverlay2
  182. testplatform
  183. testpower
  184. testqsort
  185. testrelative
  186. testrendercopyex
  187. testrendertarget
  188. testresample
  189. testrumble
  190. testscale
  191. testsem
  192. testsensor
  193. testshader
  194. testshape
  195. testsprite2
  196. testspriteminimal
  197. teststreaming
  198. testsurround
  199. testthread
  200. testtimer
  201. testurl
  202. testver
  203. testviewport
  204. testvulkan
  205. testwm2
  206. testyuv
  207. torturethread
  208. )
  209. set(NONINTERACTIVE
  210. testatomic
  211. testerror
  212. testfilesystem
  213. testlocale
  214. testplatform
  215. testpower
  216. testqsort
  217. testthread
  218. testtimer
  219. testver
  220. )
  221. if(WINDOWS OR APPLE OR SDL_X11)
  222. list(APPEND ALL_TESTS testnative)
  223. endif()
  224. if(LINUX)
  225. list(APPEND ALL_TESTS testevdev)
  226. list(APPEND NONINTERACTIVE testevdev)
  227. endif()
  228. if(SDL_DUMMYAUDIO)
  229. set(NEEDS_AUDIO
  230. testaudioinfo
  231. testsurround
  232. )
  233. endif()
  234. if(SDL_DUMMYVIDEO)
  235. set(NEEDS_DISPLAY
  236. testkeys
  237. testbounds
  238. testdisplayinfo
  239. )
  240. endif()
  241. if(OPENGL_FOUND)
  242. target_link_libraries(testshader OpenGL::GL)
  243. target_link_libraries(testgl2 OpenGL::GL)
  244. endif()
  245. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  246. file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  247. if(PSP OR PS2)
  248. set(NEEDS_RESOURCES
  249. testscale
  250. testrendercopyex
  251. controllermap
  252. testyuv
  253. testgamecontroller
  254. testshape
  255. testshader
  256. testspriteminimal
  257. testautomation
  258. testrendertarget
  259. testsprite2
  260. loopwave
  261. loopwavequeue
  262. testresample
  263. testaudiohotplug
  264. testmultiaudio
  265. testiconv
  266. testoverlay2
  267. teststreaming
  268. testviewport
  269. )
  270. else()
  271. set(NEEDS_RESOURCES
  272. testscale
  273. testrendercopyex
  274. controllermap
  275. testyuv
  276. testgamecontroller
  277. testshape
  278. testshader
  279. testspriteminimal
  280. testautomation
  281. testcustomcursor
  282. testrendertarget
  283. testsprite2
  284. loopwave
  285. loopwavequeue
  286. testresample
  287. testaudiohotplug
  288. testmultiaudio
  289. testime
  290. testiconv
  291. testoverlay2
  292. teststreaming
  293. testviewport
  294. )
  295. if(WINDOWS OR APPLE OR HAVE_X11)
  296. list(APPEND NEEDS_RESOURCES testnative)
  297. endif()
  298. endif()
  299. if(PSP)
  300. # Build EBOOT files if building for PSP
  301. set(BUILD_EBOOT
  302. ${NEEDS_RESOURCES}
  303. testatomic
  304. testaudiocapture
  305. testaudioinfo
  306. testbounds
  307. testdisplayinfo
  308. testdraw2
  309. testdrawchessboard
  310. testerror
  311. testfile
  312. testfilesystem
  313. testgeometry
  314. testgl2
  315. testhittesting
  316. testiconv
  317. testintersections
  318. testjoystick
  319. testlock
  320. testmessage
  321. testoverlay2
  322. testplatform
  323. testpower
  324. testqsort
  325. testsem
  326. teststreaming
  327. testsurround
  328. testthread
  329. testtimer
  330. testver
  331. testviewport
  332. testwm2
  333. torturethread
  334. )
  335. foreach(APP IN LISTS BUILD_EBOOT)
  336. create_pbp_file(
  337. TARGET ${APP}
  338. TITLE SDL-${APP}
  339. ICON_PATH NULL
  340. BACKGROUND_PATH NULL
  341. PREVIEW_PATH NULL
  342. )
  343. add_custom_command(
  344. TARGET ${APP} POST_BUILD
  345. COMMAND ${CMAKE_COMMAND} -E make_directory
  346. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  347. )
  348. add_custom_command(
  349. TARGET ${APP} POST_BUILD
  350. COMMAND ${CMAKE_COMMAND} -E rename
  351. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  352. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  353. )
  354. if(${BUILD_PRX})
  355. add_custom_command(
  356. TARGET ${APP} POST_BUILD
  357. COMMAND ${CMAKE_COMMAND} -E copy
  358. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  359. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  360. )
  361. add_custom_command(
  362. TARGET ${APP} POST_BUILD
  363. COMMAND ${CMAKE_COMMAND} -E rename
  364. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  365. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  366. )
  367. endif()
  368. add_custom_command(
  369. TARGET ${APP} POST_BUILD
  370. COMMAND ${CMAKE_COMMAND} -E remove
  371. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  372. )
  373. endforeach()
  374. endif()
  375. if(RISCOS)
  376. set(ALL_TESTS_AIF "")
  377. foreach(APP IN LISTS ALL_TESTS)
  378. target_link_options(${APP} PRIVATE -static)
  379. add_custom_command(
  380. OUTPUT ${APP},ff8
  381. COMMAND elf2aif ${APP} ${APP},ff8
  382. DEPENDS ${APP}
  383. )
  384. add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
  385. list(APPEND ALL_TESTS_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
  386. endforeach()
  387. endif()
  388. foreach(APP IN LISTS NEEDS_RESOURCES)
  389. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  390. if(PSP OR PS2)
  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. else()
  393. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  394. endif()
  395. endforeach(RESOURCE_FILE)
  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 ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
  428. add_test(
  429. NAME ${TESTCASE}
  430. COMMAND ${TESTCASE}
  431. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  432. )
  433. set_tests_properties(
  434. ${TESTCASE}
  435. PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}"
  436. )
  437. if(SDL_INSTALL_TESTS)
  438. set(exe ${TESTCASE})
  439. set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")
  440. configure_file(template.test.in "${exe}.test" @ONLY)
  441. install(
  442. FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
  443. DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL2
  444. )
  445. endif()
  446. endforeach()
  447. if(SDL_INSTALL_TESTS)
  448. if(RISCOS)
  449. install(
  450. FILES ${ALL_TESTS_AIF}
  451. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  452. )
  453. else()
  454. install(
  455. TARGETS ${ALL_TESTS}
  456. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  457. )
  458. endif()
  459. install(
  460. FILES ${RESOURCE_FILES}
  461. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  462. )
  463. endif()