CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. ps2_drivers
  33. )
  34. else()
  35. link_libraries(SDL2::SDL2test SDL2::SDL2-static)
  36. endif()
  37. if(WINDOWS)
  38. # mingw32 must come before SDL2main to link successfully
  39. if(MINGW OR CYGWIN)
  40. link_libraries(mingw32)
  41. endif()
  42. # FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
  43. # but we need them for VS as well.
  44. link_libraries(SDL2main)
  45. add_definitions(-Dmain=SDL_main)
  46. endif()
  47. # CMake incorrectly detects opengl32.lib being present on MSVC ARM64
  48. if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
  49. # Prefer GLVND, if present
  50. set(OpenGL_GL_PREFERENCE GLVND)
  51. find_package(OpenGL)
  52. endif()
  53. if (OPENGL_FOUND)
  54. add_definitions(-DHAVE_OPENGL)
  55. endif()
  56. add_executable(checkkeys checkkeys.c)
  57. add_executable(checkkeysthreads checkkeysthreads.c)
  58. add_executable(loopwave loopwave.c testutils.c)
  59. add_executable(loopwavequeue loopwavequeue.c testutils.c)
  60. add_executable(testsurround testsurround.c)
  61. add_executable(testresample testresample.c)
  62. add_executable(testaudioinfo testaudioinfo.c)
  63. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  64. add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
  65. add_executable(testmultiaudio testmultiaudio.c testutils.c)
  66. add_executable(testaudiohotplug testaudiohotplug.c testutils.c)
  67. add_executable(testaudiocapture testaudiocapture.c)
  68. add_executable(testatomic testatomic.c)
  69. add_executable(testintersections testintersections.c)
  70. add_executable(testrelative testrelative.c)
  71. add_executable(testhittesting testhittesting.c)
  72. add_executable(testdraw2 testdraw2.c)
  73. add_executable(testdrawchessboard testdrawchessboard.c)
  74. add_executable(testdropfile testdropfile.c)
  75. add_executable(testerror testerror.c)
  76. if(LINUX)
  77. add_executable(testevdev testevdev.c)
  78. endif()
  79. add_executable(testfile testfile.c)
  80. add_executable(testgamecontroller testgamecontroller.c testutils.c)
  81. add_executable(testgeometry testgeometry.c testutils.c)
  82. add_executable(testgesture testgesture.c)
  83. add_executable(testgl2 testgl2.c)
  84. add_executable(testgles testgles.c)
  85. add_executable(testgles2 testgles2.c)
  86. add_executable(testguid testguid.c)
  87. add_executable(testhaptic testhaptic.c)
  88. add_executable(testhotplug testhotplug.c)
  89. add_executable(testrumble testrumble.c)
  90. add_executable(testthread testthread.c)
  91. add_executable(testiconv testiconv.c testutils.c)
  92. add_executable(testime testime.c testutils.c)
  93. add_executable(testjoystick testjoystick.c)
  94. add_executable(testkeys testkeys.c)
  95. add_executable(testloadso testloadso.c)
  96. add_executable(testlocale testlocale.c)
  97. add_executable(testlock testlock.c)
  98. add_executable(testmouse testmouse.c)
  99. if(APPLE)
  100. add_executable(testnative testnative.c
  101. testnativecocoa.m
  102. testnativex11.c
  103. testutils.c)
  104. elseif(WINDOWS)
  105. add_executable(testnative testnative.c testnativew32.c testutils.c)
  106. elseif(SDL_X11)
  107. add_executable(testnative testnative.c testnativex11.c testutils.c)
  108. target_link_libraries(testnative X11)
  109. endif()
  110. add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c testutils.c)
  111. add_executable(testplatform testplatform.c)
  112. add_executable(testpower testpower.c)
  113. add_executable(testfilesystem testfilesystem.c)
  114. add_executable(testrendertarget testrendertarget.c testutils.c)
  115. add_executable(testscale testscale.c testutils.c)
  116. add_executable(testsem testsem.c)
  117. add_executable(testsensor testsensor.c)
  118. add_executable(testshader testshader.c)
  119. add_executable(testshape testshape.c)
  120. add_executable(testsprite2 testsprite2.c testutils.c)
  121. add_executable(testspriteminimal testspriteminimal.c testutils.c)
  122. add_executable(teststreaming teststreaming.c testutils.c)
  123. add_executable(testtimer testtimer.c)
  124. add_executable(testurl testurl.c)
  125. add_executable(testver testver.c)
  126. add_executable(testviewport testviewport.c testutils.c)
  127. add_executable(testwm2 testwm2.c)
  128. add_executable(testyuv testyuv.c testyuv_cvt.c)
  129. add_executable(torturethread torturethread.c)
  130. add_executable(testrendercopyex testrendercopyex.c testutils.c)
  131. add_executable(testmessage testmessage.c)
  132. add_executable(testdisplayinfo testdisplayinfo.c)
  133. add_executable(testqsort testqsort.c)
  134. add_executable(testbounds testbounds.c)
  135. add_executable(testcustomcursor testcustomcursor.c)
  136. add_executable(controllermap controllermap.c testutils.c)
  137. add_executable(testvulkan testvulkan.c)
  138. add_executable(testoffscreen testoffscreen.c)
  139. SET(ALL_TESTS
  140. checkkeys
  141. checkkeysthreads
  142. controllermap
  143. loopwave
  144. loopwavequeue
  145. testatomic
  146. testaudiocapture
  147. testaudiohotplug
  148. testaudioinfo
  149. testautomation
  150. testbounds
  151. testcustomcursor
  152. testdisplayinfo
  153. testdraw2
  154. testdrawchessboard
  155. testdropfile
  156. testerror
  157. testfile
  158. testfilesystem
  159. testgamecontroller
  160. testgeometry
  161. testgesture
  162. testgl2
  163. testgles
  164. testgles2
  165. testguid
  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. testguid
  214. testlocale
  215. testplatform
  216. testpower
  217. testqsort
  218. testthread
  219. testtimer
  220. testver
  221. )
  222. if(WINDOWS OR APPLE OR SDL_X11)
  223. list(APPEND ALL_TESTS testnative)
  224. endif()
  225. if(LINUX)
  226. list(APPEND ALL_TESTS testevdev)
  227. list(APPEND NONINTERACTIVE testevdev)
  228. endif()
  229. if(SDL_DUMMYAUDIO)
  230. set(NEEDS_AUDIO
  231. testaudioinfo
  232. testsurround
  233. )
  234. endif()
  235. if(SDL_DUMMYVIDEO)
  236. set(NEEDS_DISPLAY
  237. testkeys
  238. testbounds
  239. testdisplayinfo
  240. )
  241. endif()
  242. if(OPENGL_FOUND)
  243. target_link_libraries(testshader OpenGL::GL)
  244. target_link_libraries(testgl2 OpenGL::GL)
  245. endif()
  246. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  247. file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  248. if(PSP OR PS2)
  249. set(NEEDS_RESOURCES
  250. testscale
  251. testrendercopyex
  252. controllermap
  253. testyuv
  254. testgamecontroller
  255. testshape
  256. testshader
  257. testspriteminimal
  258. testautomation
  259. testrendertarget
  260. testsprite2
  261. loopwave
  262. loopwavequeue
  263. testresample
  264. testaudiohotplug
  265. testmultiaudio
  266. testiconv
  267. testoverlay2
  268. teststreaming
  269. testviewport
  270. )
  271. else()
  272. set(NEEDS_RESOURCES
  273. testscale
  274. testrendercopyex
  275. controllermap
  276. testyuv
  277. testgamecontroller
  278. testshape
  279. testshader
  280. testspriteminimal
  281. testautomation
  282. testcustomcursor
  283. testrendertarget
  284. testsprite2
  285. loopwave
  286. loopwavequeue
  287. testresample
  288. testaudiohotplug
  289. testmultiaudio
  290. testime
  291. testiconv
  292. testoverlay2
  293. teststreaming
  294. testviewport
  295. )
  296. if(WINDOWS OR APPLE OR SDL_X11)
  297. list(APPEND NEEDS_RESOURCES testnative)
  298. endif()
  299. endif()
  300. if(PSP)
  301. # Build EBOOT files if building for PSP
  302. set(BUILD_EBOOT
  303. ${NEEDS_RESOURCES}
  304. testatomic
  305. testaudiocapture
  306. testaudioinfo
  307. testbounds
  308. testdisplayinfo
  309. testdraw2
  310. testdrawchessboard
  311. testerror
  312. testfile
  313. testfilesystem
  314. testgeometry
  315. testgl2
  316. testguid
  317. testhittesting
  318. testiconv
  319. testintersections
  320. testjoystick
  321. testlock
  322. testmessage
  323. testoverlay2
  324. testplatform
  325. testpower
  326. testqsort
  327. testsem
  328. teststreaming
  329. testsurround
  330. testthread
  331. testtimer
  332. testver
  333. testviewport
  334. testwm2
  335. torturethread
  336. )
  337. foreach(APP IN LISTS BUILD_EBOOT)
  338. create_pbp_file(
  339. TARGET ${APP}
  340. TITLE SDL-${APP}
  341. ICON_PATH NULL
  342. BACKGROUND_PATH NULL
  343. PREVIEW_PATH NULL
  344. )
  345. add_custom_command(
  346. TARGET ${APP} POST_BUILD
  347. COMMAND ${CMAKE_COMMAND} -E make_directory
  348. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  349. )
  350. add_custom_command(
  351. TARGET ${APP} POST_BUILD
  352. COMMAND ${CMAKE_COMMAND} -E rename
  353. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  354. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  355. )
  356. if(${BUILD_PRX})
  357. add_custom_command(
  358. TARGET ${APP} POST_BUILD
  359. COMMAND ${CMAKE_COMMAND} -E copy
  360. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  361. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  362. )
  363. add_custom_command(
  364. TARGET ${APP} POST_BUILD
  365. COMMAND ${CMAKE_COMMAND} -E rename
  366. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  367. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  368. )
  369. endif()
  370. add_custom_command(
  371. TARGET ${APP} POST_BUILD
  372. COMMAND ${CMAKE_COMMAND} -E remove
  373. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  374. )
  375. endforeach()
  376. endif()
  377. if(RISCOS)
  378. set(ALL_TESTS_AIF "")
  379. foreach(APP IN LISTS ALL_TESTS)
  380. target_link_options(${APP} PRIVATE -static)
  381. add_custom_command(
  382. OUTPUT ${APP},ff8
  383. COMMAND elf2aif ${APP} ${APP},ff8
  384. DEPENDS ${APP}
  385. )
  386. add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
  387. list(APPEND ALL_TESTS_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
  388. endforeach()
  389. endif()
  390. foreach(APP IN LISTS NEEDS_RESOURCES)
  391. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  392. if(PSP OR PS2)
  393. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
  394. else()
  395. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  396. endif()
  397. endforeach(RESOURCE_FILE)
  398. if(APPLE)
  399. # Make sure resource files get installed into macOS/iOS .app bundles.
  400. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  401. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  402. endif()
  403. endforeach()
  404. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  405. # platforms (iOS, for example).
  406. if(APPLE)
  407. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  408. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  409. # CMake 3.7 and above.
  410. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  411. else()
  412. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  413. foreach(CURRENT_TARGET IN LISTS TARGETS)
  414. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  415. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  416. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  417. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  418. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  419. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  420. )
  421. endif()
  422. endforeach()
  423. endif()
  424. endif()
  425. set(TESTS_ENVIRONMENT
  426. SDL_AUDIODRIVER=dummy
  427. SDL_VIDEODRIVER=dummy
  428. )
  429. foreach(TESTCASE ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
  430. add_test(
  431. NAME ${TESTCASE}
  432. COMMAND ${TESTCASE}
  433. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  434. )
  435. set_tests_properties(
  436. ${TESTCASE}
  437. PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}"
  438. )
  439. if(SDL_INSTALL_TESTS)
  440. set(exe ${TESTCASE})
  441. set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")
  442. configure_file(template.test.in "${exe}.test" @ONLY)
  443. install(
  444. FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
  445. DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL2
  446. )
  447. endif()
  448. endforeach()
  449. if(SDL_INSTALL_TESTS)
  450. if(RISCOS)
  451. install(
  452. FILES ${ALL_TESTS_AIF}
  453. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  454. )
  455. else()
  456. install(
  457. TARGETS ${ALL_TESTS}
  458. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  459. )
  460. endif()
  461. install(
  462. FILES ${RESOURCE_FILES}
  463. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  464. )
  465. endif()