CMakeLists.txt 15 KB

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