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. if(PSP)
  8. link_libraries(
  9. SDL2main
  10. SDL2_test
  11. SDL2-static
  12. GL
  13. pspvram
  14. pspvfpu
  15. pspdisplay
  16. pspgu
  17. pspge
  18. pspaudio
  19. pspctrl
  20. psphprm
  21. psppower
  22. )
  23. else()
  24. link_libraries(SDL2_test SDL2-static)
  25. endif()
  26. if(WINDOWS)
  27. # mingw32 must come before SDL2main to link successfully
  28. if(MINGW OR CYGWIN)
  29. link_libraries(mingw32)
  30. endif()
  31. # FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
  32. # but we need them for VS as well.
  33. link_libraries(SDL2main)
  34. add_definitions(-Dmain=SDL_main)
  35. endif()
  36. # CMake incorrectly detects opengl32.lib being present on MSVC ARM64
  37. if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
  38. # Prefer GLVND, if present
  39. set(OpenGL_GL_PREFERENCE GLVND)
  40. find_package(OpenGL)
  41. endif()
  42. if (OPENGL_FOUND)
  43. add_definitions(-DHAVE_OPENGL)
  44. endif()
  45. add_executable(checkkeys checkkeys.c)
  46. add_executable(checkkeysthreads checkkeysthreads.c)
  47. add_executable(loopwave loopwave.c testutils.c)
  48. add_executable(loopwavequeue loopwavequeue.c testutils.c)
  49. add_executable(testsurround testsurround.c)
  50. add_executable(testresample testresample.c)
  51. add_executable(testaudioinfo testaudioinfo.c)
  52. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  53. add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
  54. add_executable(testmultiaudio testmultiaudio.c testutils.c)
  55. add_executable(testaudiohotplug testaudiohotplug.c testutils.c)
  56. add_executable(testaudiocapture testaudiocapture.c)
  57. add_executable(testatomic testatomic.c)
  58. add_executable(testintersections testintersections.c)
  59. add_executable(testrelative testrelative.c)
  60. add_executable(testhittesting testhittesting.c)
  61. add_executable(testdraw2 testdraw2.c)
  62. add_executable(testdrawchessboard testdrawchessboard.c)
  63. add_executable(testdropfile testdropfile.c)
  64. add_executable(testerror testerror.c)
  65. if(LINUX)
  66. add_executable(testevdev testevdev.c)
  67. endif()
  68. add_executable(testfile testfile.c)
  69. add_executable(testgamecontroller testgamecontroller.c testutils.c)
  70. add_executable(testgeometry testgeometry.c testutils.c)
  71. add_executable(testgesture testgesture.c)
  72. add_executable(testgl2 testgl2.c)
  73. add_executable(testgles testgles.c)
  74. add_executable(testgles2 testgles2.c)
  75. add_executable(testguid testguid.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. testguid
  155. testhaptic
  156. testhittesting
  157. testhotplug
  158. testiconv
  159. testime
  160. testintersections
  161. testjoystick
  162. testkeys
  163. testloadso
  164. testlocale
  165. testlock
  166. testmessage
  167. testmouse
  168. testmultiaudio
  169. testoffscreen
  170. testoverlay2
  171. testplatform
  172. testpower
  173. testqsort
  174. testrelative
  175. testrendercopyex
  176. testrendertarget
  177. testresample
  178. testrumble
  179. testscale
  180. testsem
  181. testsensor
  182. testshader
  183. testshape
  184. testsprite2
  185. testspriteminimal
  186. teststreaming
  187. testsurround
  188. testthread
  189. testtimer
  190. testurl
  191. testver
  192. testviewport
  193. testvulkan
  194. testwm2
  195. testyuv
  196. torturethread
  197. )
  198. set(NONINTERACTIVE
  199. testatomic
  200. testerror
  201. testfilesystem
  202. testguid
  203. testlocale
  204. testplatform
  205. testpower
  206. testqsort
  207. testthread
  208. testtimer
  209. testver
  210. )
  211. if(WINDOWS OR APPLE OR SDL_X11)
  212. list(APPEND ALL_TESTS testnative)
  213. endif()
  214. if(LINUX)
  215. list(APPEND ALL_TESTS testevdev)
  216. list(APPEND NONINTERACTIVE testevdev)
  217. endif()
  218. if(SDL_DUMMYAUDIO)
  219. set(NEEDS_AUDIO
  220. testaudioinfo
  221. testsurround
  222. )
  223. endif()
  224. if(SDL_DUMMYVIDEO)
  225. set(NEEDS_DISPLAY
  226. testkeys
  227. testbounds
  228. testdisplayinfo
  229. )
  230. endif()
  231. if(OPENGL_FOUND)
  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 OR PS2)
  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. testatomic
  294. testaudiocapture
  295. testaudioinfo
  296. testbounds
  297. testdisplayinfo
  298. testdraw2
  299. testdrawchessboard
  300. testerror
  301. testfile
  302. testfilesystem
  303. testgeometry
  304. testgl2
  305. testguid
  306. testhittesting
  307. testiconv
  308. testintersections
  309. testjoystick
  310. testlock
  311. testmessage
  312. testoverlay2
  313. testplatform
  314. testpower
  315. testqsort
  316. testsem
  317. teststreaming
  318. testsurround
  319. testthread
  320. testtimer
  321. testver
  322. testviewport
  323. testwm2
  324. torturethread
  325. )
  326. foreach(APP IN LISTS BUILD_EBOOT)
  327. create_pbp_file(
  328. TARGET ${APP}
  329. TITLE SDL-${APP}
  330. ICON_PATH NULL
  331. BACKGROUND_PATH NULL
  332. PREVIEW_PATH NULL
  333. )
  334. add_custom_command(
  335. TARGET ${APP} POST_BUILD
  336. COMMAND ${CMAKE_COMMAND} -E make_directory
  337. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  338. )
  339. add_custom_command(
  340. TARGET ${APP} POST_BUILD
  341. COMMAND ${CMAKE_COMMAND} -E rename
  342. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  343. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  344. )
  345. if(${BUILD_PRX})
  346. add_custom_command(
  347. TARGET ${APP} POST_BUILD
  348. COMMAND ${CMAKE_COMMAND} -E copy
  349. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  350. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  351. )
  352. add_custom_command(
  353. TARGET ${APP} POST_BUILD
  354. COMMAND ${CMAKE_COMMAND} -E rename
  355. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  356. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  357. )
  358. endif()
  359. add_custom_command(
  360. TARGET ${APP} POST_BUILD
  361. COMMAND ${CMAKE_COMMAND} -E remove
  362. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  363. )
  364. endforeach()
  365. endif()
  366. if(RISCOS)
  367. set(ALL_TESTS_AIF "")
  368. foreach(APP IN LISTS ALL_TESTS)
  369. target_link_options(${APP} PRIVATE -static)
  370. add_custom_command(
  371. OUTPUT ${APP},ff8
  372. COMMAND elf2aif ${APP} ${APP},ff8
  373. DEPENDS ${APP}
  374. )
  375. add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
  376. list(APPEND ALL_TESTS_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
  377. endforeach()
  378. endif()
  379. foreach(APP IN LISTS NEEDS_RESOURCES)
  380. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  381. if(PSP OR PS2)
  382. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
  383. else()
  384. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  385. endif()
  386. endforeach(RESOURCE_FILE)
  387. if(APPLE)
  388. # Make sure resource files get installed into macOS/iOS .app bundles.
  389. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  390. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  391. endif()
  392. endforeach()
  393. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  394. # platforms (iOS, for example).
  395. if(APPLE)
  396. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  397. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  398. # CMake 3.7 and above.
  399. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  400. else()
  401. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  402. foreach(CURRENT_TARGET IN LISTS TARGETS)
  403. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  404. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  405. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  406. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  407. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  408. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  409. )
  410. endif()
  411. endforeach()
  412. endif()
  413. endif()
  414. set(TESTS_ENVIRONMENT
  415. SDL_AUDIODRIVER=dummy
  416. SDL_VIDEODRIVER=dummy
  417. )
  418. foreach(TESTCASE ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
  419. add_test(
  420. NAME ${TESTCASE}
  421. COMMAND ${TESTCASE}
  422. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  423. )
  424. set_tests_properties(
  425. ${TESTCASE}
  426. PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}"
  427. )
  428. if(SDL_INSTALL_TESTS)
  429. set(exe ${TESTCASE})
  430. set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")
  431. configure_file(template.test.in "${exe}.test" @ONLY)
  432. install(
  433. FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
  434. DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL2
  435. )
  436. endif()
  437. endforeach()
  438. if(SDL_INSTALL_TESTS)
  439. if(RISCOS)
  440. install(
  441. FILES ${ALL_TESTS_AIF}
  442. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  443. )
  444. else()
  445. install(
  446. TARGETS ${ALL_TESTS}
  447. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  448. )
  449. endif()
  450. install(
  451. FILES ${RESOURCE_FILES}
  452. DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
  453. )
  454. endif()