CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. link_libraries(SDL2_test SDL2-static)
  7. if(WINDOWS)
  8. # mingw32 must come before SDL2main to link successfully
  9. if(MINGW OR CYGWIN)
  10. link_libraries(mingw32)
  11. endif()
  12. # FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
  13. # but we need them for VS as well.
  14. link_libraries(SDL2main)
  15. add_definitions(-Dmain=SDL_main)
  16. endif()
  17. # CMake incorrectly detects opengl32.lib being present on MSVC ARM64
  18. if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
  19. find_package(OpenGL)
  20. endif()
  21. if (OPENGL_FOUND)
  22. add_definitions(-DHAVE_OPENGL)
  23. endif()
  24. add_executable(checkkeys checkkeys.c)
  25. add_executable(checkkeysthreads checkkeysthreads.c)
  26. add_executable(loopwave loopwave.c)
  27. add_executable(loopwavequeue loopwavequeue.c)
  28. add_executable(testsurround testsurround.c)
  29. add_executable(testresample testresample.c)
  30. add_executable(testaudioinfo testaudioinfo.c)
  31. file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
  32. add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
  33. add_executable(testmultiaudio testmultiaudio.c)
  34. add_executable(testaudiohotplug testaudiohotplug.c)
  35. add_executable(testaudiocapture testaudiocapture.c)
  36. add_executable(testatomic testatomic.c)
  37. add_executable(testintersections testintersections.c)
  38. add_executable(testrelative testrelative.c)
  39. add_executable(testhittesting testhittesting.c)
  40. add_executable(testdraw2 testdraw2.c)
  41. add_executable(testdrawchessboard testdrawchessboard.c)
  42. add_executable(testdropfile testdropfile.c)
  43. add_executable(testerror testerror.c)
  44. add_executable(testfile testfile.c)
  45. add_executable(testgamecontroller testgamecontroller.c)
  46. add_executable(testgeometry testgeometry.c)
  47. add_executable(testgesture testgesture.c)
  48. add_executable(testgl2 testgl2.c)
  49. add_executable(testgles testgles.c)
  50. add_executable(testgles2 testgles2.c)
  51. add_executable(testhaptic testhaptic.c)
  52. add_executable(testhotplug testhotplug.c)
  53. add_executable(testrumble testrumble.c)
  54. add_executable(testthread testthread.c)
  55. add_executable(testiconv testiconv.c)
  56. add_executable(testime testime.c)
  57. add_executable(testjoystick testjoystick.c)
  58. add_executable(testkeys testkeys.c)
  59. add_executable(testloadso testloadso.c)
  60. add_executable(testlock testlock.c)
  61. add_executable(testmouse testmouse.c)
  62. if(APPLE)
  63. add_executable(testnative testnative.c
  64. testnativecocoa.m
  65. testnativex11.c)
  66. elseif(WINDOWS)
  67. add_executable(testnative testnative.c testnativew32.c)
  68. elseif(UNIX)
  69. add_executable(testnative testnative.c testnativex11.c)
  70. endif()
  71. add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c)
  72. add_executable(testplatform testplatform.c)
  73. add_executable(testpower testpower.c)
  74. add_executable(testfilesystem testfilesystem.c)
  75. add_executable(testrendertarget testrendertarget.c)
  76. add_executable(testscale testscale.c)
  77. add_executable(testsem testsem.c)
  78. add_executable(testshader testshader.c)
  79. add_executable(testshape testshape.c)
  80. add_executable(testsprite2 testsprite2.c)
  81. add_executable(testspriteminimal testspriteminimal.c)
  82. add_executable(teststreaming teststreaming.c)
  83. add_executable(testtimer testtimer.c)
  84. add_executable(testver testver.c)
  85. add_executable(testviewport testviewport.c)
  86. add_executable(testwm2 testwm2.c)
  87. add_executable(testyuv testyuv.c testyuv_cvt.c)
  88. add_executable(torturethread torturethread.c)
  89. add_executable(testrendercopyex testrendercopyex.c)
  90. add_executable(testmessage testmessage.c)
  91. add_executable(testdisplayinfo testdisplayinfo.c)
  92. add_executable(testqsort testqsort.c)
  93. add_executable(testbounds testbounds.c)
  94. add_executable(testcustomcursor testcustomcursor.c)
  95. add_executable(controllermap controllermap.c)
  96. add_executable(testvulkan testvulkan.c)
  97. add_executable(testoffscreen testoffscreen.c)
  98. if(OPENGL_FOUND)
  99. add_dependencies(testshader OpenGL::GL)
  100. add_dependencies(testgl2 OpenGL::GL)
  101. target_link_libraries(testshader OpenGL::GL)
  102. target_link_libraries(testgl2 OpenGL::GL)
  103. endif()
  104. file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
  105. file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  106. set(NEEDS_RESOURCES
  107. testscale
  108. testrendercopyex
  109. controllermap
  110. testyuv
  111. testgamecontroller
  112. testshape
  113. testshader
  114. testnative
  115. testspriteminimal
  116. testautomation
  117. testcustomcursor
  118. testrendertarget
  119. testsprite2
  120. loopwave
  121. loopwavequeue
  122. testresample
  123. testaudiohotplug
  124. testmultiaudio
  125. )
  126. foreach(APP IN LISTS NEEDS_RESOURCES)
  127. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  128. add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
  129. endforeach(RESOURCE_FILE)
  130. if(APPLE)
  131. # Make sure resource files get installed into macOS/iOS .app bundles.
  132. target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
  133. set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
  134. endif()
  135. endforeach()
  136. # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
  137. # platforms (iOS, for example).
  138. if(APPLE)
  139. if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
  140. # CMake's 'BUILDSYSTEM_TARGETS' property is only available in
  141. # CMake 3.7 and above.
  142. message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).")
  143. else()
  144. get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY BUILDSYSTEM_TARGETS)
  145. foreach(CURRENT_TARGET IN LISTS TARGETS)
  146. get_property(TARGET_TYPE TARGET ${CURRENT_TARGET} PROPERTY TYPE)
  147. if(TARGET_TYPE STREQUAL "EXECUTABLE")
  148. set_target_properties("${CURRENT_TARGET}" PROPERTIES
  149. MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
  150. MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}"
  151. MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}"
  152. )
  153. endif()
  154. endforeach()
  155. endif()
  156. endif()