CMakeLists.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. set(NEEDS_RESOURCES
  125. testscale
  126. testrendercopyex
  127. controllermap
  128. testyuv
  129. testgamecontroller
  130. testshape
  131. testshader
  132. testspriteminimal
  133. testautomation
  134. testcustomcursor
  135. testrendertarget
  136. testsprite2
  137. loopwave
  138. loopwavequeue
  139. testresample
  140. testaudiohotplug
  141. testmultiaudio
  142. testime
  143. testiconv
  144. testoverlay2
  145. teststreaming
  146. testviewport
  147. )
  148. if(NOT PSP)
  149. set(NEEDS_RESOURCES ${NEEDS_RESOURCES} testnative)
  150. endif()
  151. if(PSP)
  152. # Build EBOOT files if building for PSP
  153. set(BUILD_EBOOT
  154. ${NEEDS_RESOURCES}
  155. testoffscreen
  156. testvulkan
  157. testbounds
  158. testhotplug
  159. testgles2
  160. testhaptic
  161. testrelative
  162. testgl2
  163. testsem
  164. testdisplayinfo
  165. testgles
  166. teststreaming
  167. testgeometry
  168. testgesture
  169. testfile
  170. testdropfile
  171. testdraw2
  172. testviewport
  173. testhittesting
  174. checkkeys
  175. testoverlay2
  176. testver
  177. testdrawchessboard
  178. testsurround
  179. testintersections
  180. testmessage
  181. testaudiocapture
  182. testerror
  183. testatomic
  184. testjoystick
  185. testrumble
  186. testiconv
  187. testfilesystem
  188. testplatform
  189. testthread
  190. testkeys
  191. testloadso
  192. testmouse
  193. testqsort
  194. testime
  195. testaudioinfo
  196. testlock
  197. checkkeysthreads
  198. testtimer
  199. testpower
  200. testwm2
  201. torturethread
  202. )
  203. foreach(APP IN LISTS BUILD_EBOOT)
  204. create_pbp_file(
  205. TARGET ${APP}
  206. TITLE SDL-${APP}
  207. ICON_PATH NULL
  208. BACKGROUND_PATH NULL
  209. PREVIEW_PATH NULL
  210. )
  211. add_custom_command(
  212. TARGET ${APP} POST_BUILD
  213. COMMAND ${CMAKE_COMMAND} -E make_directory
  214. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
  215. )
  216. add_custom_command(
  217. TARGET ${APP} POST_BUILD
  218. COMMAND ${CMAKE_COMMAND} -E rename
  219. $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
  220. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
  221. )
  222. if(${BUILD_PRX})
  223. add_custom_command(
  224. TARGET ${APP} POST_BUILD
  225. COMMAND ${CMAKE_COMMAND} -E copy
  226. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
  227. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
  228. )
  229. add_custom_command(
  230. TARGET ${APP} POST_BUILD
  231. COMMAND ${CMAKE_COMMAND} -E rename
  232. $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
  233. $<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
  234. )
  235. endif()
  236. add_custom_command(
  237. TARGET ${APP} POST_BUILD
  238. COMMAND ${CMAKE_COMMAND} -E remove
  239. $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
  240. )
  241. endforeach()
  242. endif()
  243. foreach(APP IN LISTS NEEDS_RESOURCES)
  244. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  245. if(PSP)
  246. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
  247. else()
  248. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  249. endif()
  250. endforeach(RESOURCE_FILE)
  251. if(APPLE)
  252. # Make sure resource files get installed into macOS/iOS .app bundles.
  253. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  254. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  255. endif()
  256. endforeach()
  257. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  258. # platforms (iOS, for example).
  259. if(APPLE)
  260. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  261. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  262. # CMake 3.7 and above.
  263. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  264. else()
  265. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  266. foreach(CURRENT_TARGET IN LISTS TARGETS)
  267. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  268. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  269. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  270. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  271. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  272. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  273. )
  274. endif()
  275. endforeach()
  276. endif()
  277. endif()