CMakeLists.txt 13 KB

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