CMakeLists.txt 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. cmake_minimum_required(VERSION 3.0.0)
  2. project(SDL2 C)
  3. # Global settings for all of the test targets
  4. # FIXME: is this wrong?
  5. remove_definitions(-DUSING_GENERATED_CONFIG_H)
  6. if(PSP)
  7. link_libraries(
  8. SDL2main
  9. SDL2_test
  10. SDL2-static
  11. GL
  12. pspvram
  13. pspvfpu
  14. pspdisplay
  15. pspgu
  16. pspge
  17. pspaudio
  18. pspctrl
  19. psphprm
  20. psppower
  21. )
  22. else()
  23. link_libraries(SDL2_test SDL2-static)
  24. endif()
  25. if(WINDOWS)
  26. # mingw32 must come before SDL2main to link successfully
  27. if(MINGW OR CYGWIN)
  28. link_libraries(mingw32)
  29. endif()
  30. # FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
  31. # but we need them for VS as well.
  32. link_libraries(SDL2main)
  33. add_definitions(-Dmain=SDL_main)
  34. endif()
  35. # CMake incorrectly detects opengl32.lib being present on MSVC ARM64
  36. if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
  37. find_package(OpenGL)
  38. endif()
  39. if (OPENGL_FOUND)
  40. add_definitions(-DHAVE_OPENGL)
  41. endif()
  42. add_executable(checkkeys checkkeys.c)
  43. add_executable(checkkeysthreads checkkeysthreads.c)
  44. add_executable(loopwave loopwave.c)
  45. add_executable(loopwavequeue loopwavequeue.c)
  46. add_executable(testsurround testsurround.c)
  47. add_executable(testresample testresample.c)
  48. add_executable(testaudioinfo testaudioinfo.c)
  49. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  50. add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
  51. add_executable(testmultiaudio testmultiaudio.c)
  52. add_executable(testaudiohotplug testaudiohotplug.c)
  53. add_executable(testaudiocapture testaudiocapture.c)
  54. add_executable(testatomic testatomic.c)
  55. add_executable(testintersections testintersections.c)
  56. add_executable(testrelative testrelative.c)
  57. add_executable(testhittesting testhittesting.c)
  58. add_executable(testdraw2 testdraw2.c)
  59. add_executable(testdrawchessboard testdrawchessboard.c)
  60. add_executable(testdropfile testdropfile.c)
  61. add_executable(testerror testerror.c)
  62. add_executable(testfile testfile.c)
  63. add_executable(testgamecontroller testgamecontroller.c)
  64. add_executable(testgeometry testgeometry.c)
  65. add_executable(testgesture testgesture.c)
  66. add_executable(testgl2 testgl2.c)
  67. add_executable(testgles testgles.c)
  68. add_executable(testgles2 testgles2.c)
  69. add_executable(testhaptic testhaptic.c)
  70. add_executable(testhotplug testhotplug.c)
  71. add_executable(testrumble testrumble.c)
  72. add_executable(testthread testthread.c)
  73. add_executable(testiconv testiconv.c)
  74. add_executable(testime testime.c)
  75. add_executable(testjoystick testjoystick.c)
  76. add_executable(testkeys testkeys.c)
  77. add_executable(testloadso testloadso.c)
  78. add_executable(testlock testlock.c)
  79. add_executable(testmouse testmouse.c)
  80. if(APPLE)
  81. add_executable(testnative testnative.c
  82. testnativecocoa.m
  83. testnativex11.c)
  84. elseif(WINDOWS)
  85. add_executable(testnative testnative.c testnativew32.c)
  86. elseif(UNIX)
  87. add_executable(testnative testnative.c testnativex11.c)
  88. endif()
  89. add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c)
  90. add_executable(testplatform testplatform.c)
  91. add_executable(testpower testpower.c)
  92. add_executable(testfilesystem testfilesystem.c)
  93. add_executable(testrendertarget testrendertarget.c)
  94. add_executable(testscale testscale.c)
  95. add_executable(testsem testsem.c)
  96. add_executable(testshader testshader.c)
  97. add_executable(testshape testshape.c)
  98. add_executable(testsprite2 testsprite2.c)
  99. add_executable(testspriteminimal testspriteminimal.c)
  100. add_executable(teststreaming teststreaming.c)
  101. add_executable(testtimer testtimer.c)
  102. add_executable(testver testver.c)
  103. add_executable(testviewport testviewport.c)
  104. add_executable(testwm2 testwm2.c)
  105. add_executable(testyuv testyuv.c testyuv_cvt.c)
  106. add_executable(torturethread torturethread.c)
  107. add_executable(testrendercopyex testrendercopyex.c)
  108. add_executable(testmessage testmessage.c)
  109. add_executable(testdisplayinfo testdisplayinfo.c)
  110. add_executable(testqsort testqsort.c)
  111. add_executable(testbounds testbounds.c)
  112. add_executable(testcustomcursor testcustomcursor.c)
  113. add_executable(controllermap controllermap.c)
  114. add_executable(testvulkan testvulkan.c)
  115. add_executable(testoffscreen testoffscreen.c)
  116. if(OPENGL_FOUND)
  117. add_dependencies(testshader OpenGL::GL)
  118. add_dependencies(testgl2 OpenGL::GL)
  119. target_link_libraries(testshader OpenGL::GL)
  120. target_link_libraries(testgl2 OpenGL::GL)
  121. endif()
  122. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  123. file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  124. if(PSP)
  125. set(NEEDS_RESOURCES
  126. testscale
  127. testrendercopyex
  128. controllermap
  129. testyuv
  130. testgamecontroller
  131. testshape
  132. testshader
  133. testspriteminimal
  134. testautomation
  135. testrendertarget
  136. testsprite2
  137. loopwave
  138. loopwavequeue
  139. testresample
  140. testaudiohotplug
  141. testmultiaudio
  142. testiconv
  143. testoverlay2
  144. teststreaming
  145. testviewport
  146. )
  147. else()
  148. set(NEEDS_RESOURCES
  149. testscale
  150. testrendercopyex
  151. controllermap
  152. testyuv
  153. testgamecontroller
  154. testshape
  155. testshader
  156. testspriteminimal
  157. testautomation
  158. testcustomcursor
  159. testrendertarget
  160. testsprite2
  161. loopwave
  162. loopwavequeue
  163. testresample
  164. testaudiohotplug
  165. testmultiaudio
  166. testime
  167. testnative
  168. testiconv
  169. testoverlay2
  170. teststreaming
  171. testviewport
  172. )
  173. endif()
  174. if(PSP)
  175. # Build EBOOT files if building for PSP
  176. set(BUILD_EBOOT
  177. ${NEEDS_RESOURCES}
  178. testoffscreen
  179. testbounds
  180. testgl2
  181. testsem
  182. testdisplayinfo
  183. teststreaming
  184. testgeometry
  185. testfile
  186. testdraw2
  187. testviewport
  188. testhittesting
  189. testoverlay2
  190. testver
  191. testdrawchessboard
  192. testsurround
  193. testintersections
  194. testmessage
  195. testaudiocapture
  196. testerror
  197. testatomic
  198. testjoystick
  199. testiconv
  200. testfilesystem
  201. testplatform
  202. testthread
  203. testloadso
  204. testqsort
  205. testaudioinfo
  206. testlock
  207. testtimer
  208. testpower
  209. testwm2
  210. torturethread
  211. )
  212. foreach(APP IN LISTS BUILD_EBOOT)
  213. create_pbp_file(
  214. TARGET ${APP}
  215. TITLE SDL-${APP}
  216. ICON_PATH NULL
  217. BACKGROUND_PATH NULL
  218. PREVIEW_PATH NULL
  219. )
  220. add_custom_command(
  221. TARGET ${APP} POST_BUILD
  222. COMMAND ${CMAKE_COMMAND} -E make_directory
  223. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  224. )
  225. add_custom_command(
  226. TARGET ${APP} POST_BUILD
  227. COMMAND ${CMAKE_COMMAND} -E rename
  228. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  229. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  230. )
  231. if(${BUILD_PRX})
  232. add_custom_command(
  233. TARGET ${APP} POST_BUILD
  234. COMMAND ${CMAKE_COMMAND} -E copy
  235. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  236. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  237. )
  238. add_custom_command(
  239. TARGET ${APP} POST_BUILD
  240. COMMAND ${CMAKE_COMMAND} -E rename
  241. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  242. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  243. )
  244. endif()
  245. add_custom_command(
  246. TARGET ${APP} POST_BUILD
  247. COMMAND ${CMAKE_COMMAND} -E remove
  248. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  249. )
  250. endforeach()
  251. endif()
  252. foreach(APP IN LISTS NEEDS_RESOURCES)
  253. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  254. if(PSP)
  255. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
  256. else()
  257. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  258. endif()
  259. endforeach(RESOURCE_FILE)
  260. if(APPLE)
  261. # Make sure resource files get installed into macOS/iOS .app bundles.
  262. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  263. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  264. endif()
  265. endforeach()
  266. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  267. # platforms (iOS, for example).
  268. if(APPLE)
  269. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  270. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  271. # CMake 3.7 and above.
  272. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  273. else()
  274. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  275. foreach(CURRENT_TARGET IN LISTS TARGETS)
  276. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  277. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  278. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  279. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  280. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  281. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  282. )
  283. endif()
  284. endforeach()
  285. endif()
  286. endif()