CMakeLists.txt 13 KB

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