CMakeLists.txt 14 KB

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