CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. cmake_minimum_required(VERSION 3.0.0)
  2. project(SDL2 C)
  3. include(CTest)
  4. # Global settings for all of the test targets
  5. # FIXME: is this wrong?
  6. remove_definitions(-DUSING_GENERATED_CONFIG_H)
  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. find_package(OpenGL)
  39. endif()
  40. if (OPENGL_FOUND)
  41. add_definitions(-DHAVE_OPENGL)
  42. endif()
  43. add_executable(checkkeys checkkeys.c)
  44. add_executable(checkkeysthreads checkkeysthreads.c)
  45. add_executable(loopwave loopwave.c testutils.c)
  46. add_executable(loopwavequeue loopwavequeue.c testutils.c)
  47. add_executable(testsurround testsurround.c)
  48. add_executable(testresample testresample.c)
  49. add_executable(testaudioinfo testaudioinfo.c)
  50. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  51. add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
  52. add_executable(testmultiaudio testmultiaudio.c testutils.c)
  53. add_executable(testaudiohotplug testaudiohotplug.c testutils.c)
  54. add_executable(testaudiocapture testaudiocapture.c)
  55. add_executable(testatomic testatomic.c)
  56. add_executable(testintersections testintersections.c)
  57. add_executable(testrelative testrelative.c)
  58. add_executable(testhittesting testhittesting.c)
  59. add_executable(testdraw2 testdraw2.c)
  60. add_executable(testdrawchessboard testdrawchessboard.c)
  61. add_executable(testdropfile testdropfile.c)
  62. add_executable(testerror testerror.c)
  63. if(LINUX)
  64. add_executable(testevdev testevdev.c)
  65. endif()
  66. add_executable(testfile testfile.c)
  67. add_executable(testgamecontroller testgamecontroller.c testutils.c)
  68. add_executable(testgeometry testgeometry.c testutils.c)
  69. add_executable(testgesture testgesture.c)
  70. add_executable(testgl2 testgl2.c)
  71. add_executable(testgles testgles.c)
  72. add_executable(testgles2 testgles2.c)
  73. add_executable(testhaptic testhaptic.c)
  74. add_executable(testhotplug testhotplug.c)
  75. add_executable(testrumble testrumble.c)
  76. add_executable(testthread testthread.c)
  77. add_executable(testiconv testiconv.c testutils.c)
  78. add_executable(testime testime.c testutils.c)
  79. add_executable(testjoystick testjoystick.c)
  80. add_executable(testkeys testkeys.c)
  81. add_executable(testloadso testloadso.c)
  82. add_executable(testlocale testlocale.c)
  83. add_executable(testlock testlock.c)
  84. add_executable(testmouse testmouse.c)
  85. if(APPLE)
  86. add_executable(testnative testnative.c
  87. testnativecocoa.m
  88. testnativex11.c
  89. testutils.c)
  90. elseif(WINDOWS)
  91. add_executable(testnative testnative.c testnativew32.c testutils.c)
  92. elseif(UNIX)
  93. add_executable(testnative testnative.c testnativex11.c testutils.c)
  94. target_link_libraries(testnative X11)
  95. endif()
  96. add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c testutils.c)
  97. add_executable(testplatform testplatform.c)
  98. add_executable(testpower testpower.c)
  99. add_executable(testfilesystem testfilesystem.c)
  100. add_executable(testrendertarget testrendertarget.c testutils.c)
  101. add_executable(testscale testscale.c testutils.c)
  102. add_executable(testsem testsem.c)
  103. add_executable(testsensor testsensor.c)
  104. add_executable(testshader testshader.c)
  105. add_executable(testshape testshape.c)
  106. add_executable(testsprite2 testsprite2.c testutils.c)
  107. add_executable(testspriteminimal testspriteminimal.c testutils.c)
  108. add_executable(teststreaming teststreaming.c testutils.c)
  109. add_executable(testtimer testtimer.c)
  110. add_executable(testurl testurl.c)
  111. add_executable(testver testver.c)
  112. add_executable(testviewport testviewport.c testutils.c)
  113. add_executable(testwm2 testwm2.c)
  114. add_executable(testyuv testyuv.c testyuv_cvt.c)
  115. add_executable(torturethread torturethread.c)
  116. add_executable(testrendercopyex testrendercopyex.c testutils.c)
  117. add_executable(testmessage testmessage.c)
  118. add_executable(testdisplayinfo testdisplayinfo.c)
  119. add_executable(testqsort testqsort.c)
  120. add_executable(testbounds testbounds.c)
  121. add_executable(testcustomcursor testcustomcursor.c)
  122. add_executable(controllermap controllermap.c testutils.c)
  123. add_executable(testvulkan testvulkan.c)
  124. add_executable(testoffscreen testoffscreen.c)
  125. set(NONINTERACTIVE
  126. testatomic
  127. testerror
  128. testfilesystem
  129. testkeys
  130. testlocale
  131. testplatform
  132. testpower
  133. testqsort
  134. testthread
  135. testtimer
  136. testver
  137. )
  138. if(LINUX)
  139. list(APPEND NONINTERACTIVE testevdev)
  140. endif()
  141. set(NEEDS_AUDIO
  142. testaudioinfo
  143. testsurround
  144. )
  145. set(NEEDS_DISPLAY
  146. testbounds
  147. testdisplayinfo
  148. )
  149. if(OPENGL_FOUND)
  150. add_dependencies(testshader OpenGL::GL)
  151. add_dependencies(testgl2 OpenGL::GL)
  152. target_link_libraries(testshader OpenGL::GL)
  153. target_link_libraries(testgl2 OpenGL::GL)
  154. endif()
  155. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  156. file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  157. if(PSP)
  158. set(NEEDS_RESOURCES
  159. testscale
  160. testrendercopyex
  161. controllermap
  162. testyuv
  163. testgamecontroller
  164. testshape
  165. testshader
  166. testspriteminimal
  167. testautomation
  168. testrendertarget
  169. testsprite2
  170. loopwave
  171. loopwavequeue
  172. testresample
  173. testaudiohotplug
  174. testmultiaudio
  175. testiconv
  176. testoverlay2
  177. teststreaming
  178. testviewport
  179. )
  180. else()
  181. set(NEEDS_RESOURCES
  182. testscale
  183. testrendercopyex
  184. controllermap
  185. testyuv
  186. testgamecontroller
  187. testshape
  188. testshader
  189. testspriteminimal
  190. testautomation
  191. testcustomcursor
  192. testrendertarget
  193. testsprite2
  194. loopwave
  195. loopwavequeue
  196. testresample
  197. testaudiohotplug
  198. testmultiaudio
  199. testime
  200. testnative
  201. testiconv
  202. testoverlay2
  203. teststreaming
  204. testviewport
  205. )
  206. endif()
  207. if(PSP)
  208. # Build EBOOT files if building for PSP
  209. set(BUILD_EBOOT
  210. ${NEEDS_RESOURCES}
  211. testbounds
  212. testgl2
  213. testsem
  214. testdisplayinfo
  215. teststreaming
  216. testgeometry
  217. testfile
  218. testdraw2
  219. testviewport
  220. testhittesting
  221. testoverlay2
  222. testver
  223. testdrawchessboard
  224. testsurround
  225. testintersections
  226. testmessage
  227. testaudiocapture
  228. testerror
  229. testatomic
  230. testjoystick
  231. testiconv
  232. testfilesystem
  233. testplatform
  234. testthread
  235. testqsort
  236. testaudioinfo
  237. testlock
  238. testtimer
  239. testpower
  240. testwm2
  241. torturethread
  242. )
  243. foreach(APP IN LISTS BUILD_EBOOT)
  244. create_pbp_file(
  245. TARGET ${APP}
  246. TITLE SDL-${APP}
  247. ICON_PATH NULL
  248. BACKGROUND_PATH NULL
  249. PREVIEW_PATH NULL
  250. )
  251. add_custom_command(
  252. TARGET ${APP} POST_BUILD
  253. COMMAND ${CMAKE_COMMAND} -E make_directory
  254. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  255. )
  256. add_custom_command(
  257. TARGET ${APP} POST_BUILD
  258. COMMAND ${CMAKE_COMMAND} -E rename
  259. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  260. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  261. )
  262. if(${BUILD_PRX})
  263. add_custom_command(
  264. TARGET ${APP} POST_BUILD
  265. COMMAND ${CMAKE_COMMAND} -E copy
  266. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  267. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  268. )
  269. add_custom_command(
  270. TARGET ${APP} POST_BUILD
  271. COMMAND ${CMAKE_COMMAND} -E rename
  272. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  273. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  274. )
  275. endif()
  276. add_custom_command(
  277. TARGET ${APP} POST_BUILD
  278. COMMAND ${CMAKE_COMMAND} -E remove
  279. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  280. )
  281. endforeach()
  282. endif()
  283. foreach(APP IN LISTS NEEDS_RESOURCES)
  284. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  285. if(PSP)
  286. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
  287. else()
  288. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  289. endif()
  290. endforeach(RESOURCE_FILE)
  291. if(APPLE)
  292. # Make sure resource files get installed into macOS/iOS .app bundles.
  293. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  294. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  295. endif()
  296. endforeach()
  297. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  298. # platforms (iOS, for example).
  299. if(APPLE)
  300. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  301. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  302. # CMake 3.7 and above.
  303. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  304. else()
  305. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  306. foreach(CURRENT_TARGET IN LISTS TARGETS)
  307. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  308. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  309. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  310. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  311. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  312. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  313. )
  314. endif()
  315. endforeach()
  316. endif()
  317. endif()
  318. set(TESTS_ENVIRONMENT
  319. SDL_AUDIODRIVER=dummy
  320. SDL_VIDEODRIVER=dummy
  321. )
  322. foreach(TESTCASE ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
  323. add_test(
  324. NAME ${TESTCASE}
  325. COMMAND ${TESTCASE}
  326. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  327. )
  328. set_tests_properties(
  329. ${TESTCASE}
  330. PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}"
  331. )
  332. endforeach()