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