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