CMakeLists.txt 13 KB

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