1
0

CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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(testhaptic testhaptic.c)
  87. add_executable(testhotplug testhotplug.c)
  88. add_executable(testrumble testrumble.c)
  89. add_executable(testthread testthread.c)
  90. add_executable(testiconv testiconv.c testutils.c)
  91. add_executable(testime testime.c testutils.c)
  92. add_executable(testjoystick testjoystick.c)
  93. add_executable(testkeys testkeys.c)
  94. add_executable(testloadso testloadso.c)
  95. add_executable(testlocale testlocale.c)
  96. add_executable(testlock testlock.c)
  97. add_executable(testmouse testmouse.c)
  98. if(APPLE)
  99. add_executable(testnative testnative.c
  100. testnativecocoa.m
  101. testnativex11.c
  102. testutils.c)
  103. elseif(WINDOWS)
  104. add_executable(testnative testnative.c testnativew32.c testutils.c)
  105. elseif(SDL_X11)
  106. add_executable(testnative testnative.c testnativex11.c testutils.c)
  107. target_link_libraries(testnative X11)
  108. endif()
  109. add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c testutils.c)
  110. add_executable(testplatform testplatform.c)
  111. add_executable(testpower testpower.c)
  112. add_executable(testfilesystem testfilesystem.c)
  113. add_executable(testrendertarget testrendertarget.c testutils.c)
  114. add_executable(testscale testscale.c testutils.c)
  115. add_executable(testsem testsem.c)
  116. add_executable(testsensor testsensor.c)
  117. add_executable(testshader testshader.c)
  118. add_executable(testshape testshape.c)
  119. add_executable(testsprite2 testsprite2.c testutils.c)
  120. add_executable(testspriteminimal testspriteminimal.c testutils.c)
  121. add_executable(teststreaming teststreaming.c testutils.c)
  122. add_executable(testtimer testtimer.c)
  123. add_executable(testurl testurl.c)
  124. add_executable(testver testver.c)
  125. add_executable(testviewport testviewport.c testutils.c)
  126. add_executable(testwm2 testwm2.c)
  127. add_executable(testyuv testyuv.c testyuv_cvt.c)
  128. add_executable(torturethread torturethread.c)
  129. add_executable(testrendercopyex testrendercopyex.c testutils.c)
  130. add_executable(testmessage testmessage.c)
  131. add_executable(testdisplayinfo testdisplayinfo.c)
  132. add_executable(testqsort testqsort.c)
  133. add_executable(testbounds testbounds.c)
  134. add_executable(testcustomcursor testcustomcursor.c)
  135. add_executable(controllermap controllermap.c testutils.c)
  136. add_executable(testvulkan testvulkan.c)
  137. add_executable(testoffscreen testoffscreen.c)
  138. SET(ALL_TESTS
  139. checkkeys
  140. checkkeysthreads
  141. controllermap
  142. loopwave
  143. loopwavequeue
  144. testatomic
  145. testaudiocapture
  146. testaudiohotplug
  147. testaudioinfo
  148. testautomation
  149. testbounds
  150. testcustomcursor
  151. testdisplayinfo
  152. testdraw2
  153. testdrawchessboard
  154. testdropfile
  155. testerror
  156. testfile
  157. testfilesystem
  158. testgamecontroller
  159. testgeometry
  160. testgesture
  161. testgl2
  162. testgles
  163. testgles2
  164. testhaptic
  165. testhittesting
  166. testhotplug
  167. testiconv
  168. testime
  169. testintersections
  170. testjoystick
  171. testkeys
  172. testloadso
  173. testlocale
  174. testlock
  175. testmessage
  176. testmouse
  177. testmultiaudio
  178. testoffscreen
  179. testoverlay2
  180. testplatform
  181. testpower
  182. testqsort
  183. testrelative
  184. testrendercopyex
  185. testrendertarget
  186. testresample
  187. testrumble
  188. testscale
  189. testsem
  190. testsensor
  191. testshader
  192. testshape
  193. testsprite2
  194. testspriteminimal
  195. teststreaming
  196. testsurround
  197. testthread
  198. testtimer
  199. testurl
  200. testver
  201. testviewport
  202. testvulkan
  203. testwm2
  204. testyuv
  205. torturethread
  206. )
  207. set(NONINTERACTIVE
  208. testatomic
  209. testerror
  210. testfilesystem
  211. testlocale
  212. testplatform
  213. testpower
  214. testqsort
  215. testthread
  216. testtimer
  217. testver
  218. )
  219. if(WINDOWS OR APPLE OR SDL_X11)
  220. list(APPEND ALL_TESTS testnative)
  221. endif()
  222. if(LINUX)
  223. list(APPEND ALL_TESTS testevdev)
  224. list(APPEND NONINTERACTIVE testevdev)
  225. endif()
  226. if(SDL_DUMMYAUDIO)
  227. set(NEEDS_AUDIO
  228. testaudioinfo
  229. testsurround
  230. )
  231. endif()
  232. if(SDL_DUMMYVIDEO)
  233. set(NEEDS_DISPLAY
  234. testkeys
  235. testbounds
  236. testdisplayinfo
  237. )
  238. endif()
  239. if(OPENGL_FOUND)
  240. target_link_libraries(testshader OpenGL::GL)
  241. target_link_libraries(testgl2 OpenGL::GL)
  242. endif()
  243. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  244. file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  245. if(PSP OR PS2)
  246. set(NEEDS_RESOURCES
  247. testscale
  248. testrendercopyex
  249. controllermap
  250. testyuv
  251. testgamecontroller
  252. testshape
  253. testshader
  254. testspriteminimal
  255. testautomation
  256. testrendertarget
  257. testsprite2
  258. loopwave
  259. loopwavequeue
  260. testresample
  261. testaudiohotplug
  262. testmultiaudio
  263. testiconv
  264. testoverlay2
  265. teststreaming
  266. testviewport
  267. )
  268. else()
  269. set(NEEDS_RESOURCES
  270. testscale
  271. testrendercopyex
  272. controllermap
  273. testyuv
  274. testgamecontroller
  275. testshape
  276. testshader
  277. testspriteminimal
  278. testautomation
  279. testcustomcursor
  280. testrendertarget
  281. testsprite2
  282. loopwave
  283. loopwavequeue
  284. testresample
  285. testaudiohotplug
  286. testmultiaudio
  287. testime
  288. testiconv
  289. testoverlay2
  290. teststreaming
  291. testviewport
  292. )
  293. if(WINDOWS OR APPLE OR SDL_X11)
  294. list(APPEND NEEDS_RESOURCES testnative)
  295. endif()
  296. endif()
  297. if(PSP)
  298. # Build EBOOT files if building for PSP
  299. set(BUILD_EBOOT
  300. ${NEEDS_RESOURCES}
  301. testatomic
  302. testaudiocapture
  303. testaudioinfo
  304. testbounds
  305. testdisplayinfo
  306. testdraw2
  307. testdrawchessboard
  308. testerror
  309. testfile
  310. testfilesystem
  311. testgeometry
  312. testgl2
  313. testhittesting
  314. testiconv
  315. testintersections
  316. testjoystick
  317. testlock
  318. testmessage
  319. testoverlay2
  320. testplatform
  321. testpower
  322. testqsort
  323. testsem
  324. teststreaming
  325. testsurround
  326. testthread
  327. testtimer
  328. testver
  329. testviewport
  330. testwm2
  331. torturethread
  332. )
  333. foreach(APP IN LISTS BUILD_EBOOT)
  334. create_pbp_file(
  335. TARGET ${APP}
  336. TITLE SDL-${APP}
  337. ICON_PATH NULL
  338. BACKGROUND_PATH NULL
  339. PREVIEW_PATH NULL
  340. )
  341. add_custom_command(
  342. TARGET ${APP} POST_BUILD
  343. COMMAND ${CMAKE_COMMAND} -E make_directory
  344. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  345. )
  346. add_custom_command(
  347. TARGET ${APP} POST_BUILD
  348. COMMAND ${CMAKE_COMMAND} -E rename
  349. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  350. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  351. )
  352. if(${BUILD_PRX})
  353. add_custom_command(
  354. TARGET ${APP} POST_BUILD
  355. COMMAND ${CMAKE_COMMAND} -E copy
  356. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  357. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  358. )
  359. add_custom_command(
  360. TARGET ${APP} POST_BUILD
  361. COMMAND ${CMAKE_COMMAND} -E rename
  362. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  363. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  364. )
  365. endif()
  366. add_custom_command(
  367. TARGET ${APP} POST_BUILD
  368. COMMAND ${CMAKE_COMMAND} -E remove
  369. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  370. )
  371. endforeach()
  372. endif()
  373. if(RISCOS)
  374. set(ALL_TESTS_AIF "")
  375. foreach(APP IN LISTS ALL_TESTS)
  376. target_link_options(${APP} PRIVATE -static)
  377. add_custom_command(
  378. OUTPUT ${APP},ff8
  379. COMMAND elf2aif ${APP} ${APP},ff8
  380. DEPENDS ${APP}
  381. )
  382. add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
  383. list(APPEND ALL_TESTS_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
  384. endforeach()
  385. endif()
  386. foreach(APP IN LISTS NEEDS_RESOURCES)
  387. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  388. if(PSP OR PS2)
  389. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
  390. else()
  391. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  392. endif()
  393. endforeach(RESOURCE_FILE)
  394. if(APPLE)
  395. # Make sure resource files get installed into macOS/iOS .app bundles.
  396. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  397. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  398. endif()
  399. endforeach()
  400. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  401. # platforms (iOS, for example).
  402. if(APPLE)
  403. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  404. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  405. # CMake 3.7 and above.
  406. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  407. else()
  408. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  409. foreach(CURRENT_TARGET IN LISTS TARGETS)
  410. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  411. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  412. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  413. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  414. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  415. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  416. )
  417. endif()
  418. endforeach()
  419. endif()
  420. endif()
  421. set(TESTS_ENVIRONMENT
  422. SDL_AUDIODRIVER=dummy
  423. SDL_VIDEODRIVER=dummy
  424. )
  425. foreach(TESTCASE ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
  426. add_test(
  427. NAME ${TESTCASE}
  428. COMMAND ${TESTCASE}
  429. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  430. )
  431. set_tests_properties(
  432. ${TESTCASE}
  433. PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}"
  434. )
  435. if(SDL_INSTALL_TESTS)
  436. set(exe ${TESTCASE})
  437. set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")
  438. configure_file(template.test.in "${exe}.test" @ONLY)
  439. install(
  440. FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
  441. DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL2
  442. )
  443. endif()
  444. endforeach()
  445. if(SDL_INSTALL_TESTS)
  446. if(RISCOS)
  447. install(
  448. FILES ${ALL_TESTS_AIF}
  449. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  450. )
  451. else()
  452. install(
  453. TARGETS ${ALL_TESTS}
  454. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  455. )
  456. endif()
  457. install(
  458. FILES ${RESOURCE_FILES}
  459. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  460. )
  461. endif()