diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/cmake/test/CMakeLists.txt | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/cmake/test/CMakeLists.txt')
| -rw-r--r-- | contrib/SDL-3.2.8/cmake/test/CMakeLists.txt | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/cmake/test/CMakeLists.txt b/contrib/SDL-3.2.8/cmake/test/CMakeLists.txt new file mode 100644 index 0000000..e3766f0 --- /dev/null +++ b/contrib/SDL-3.2.8/cmake/test/CMakeLists.txt | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | # This cmake build script is meant for verifying the various CMake configuration scripts. | ||
| 2 | |||
| 3 | cmake_minimum_required(VERSION 3.12) | ||
| 4 | project(SDL_cmake_selftest LANGUAGES C) | ||
| 5 | |||
| 6 | include(CheckLanguage) | ||
| 7 | |||
| 8 | # FIXME: how to target ios/tvos with Swift? | ||
| 9 | # https://gitlab.kitware.com/cmake/cmake/-/issues/20104 | ||
| 10 | if(APPLE AND CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*") | ||
| 11 | # multiple values for CMAKE_OSX_ARCHITECTURES not supported with Swift | ||
| 12 | list(LENGTH CMAKE_OSX_ARCHITECTURES count_osx_archs) | ||
| 13 | if(count_osx_archs LESS_EQUAL 1) | ||
| 14 | check_language(Swift) | ||
| 15 | if(CMAKE_Swift_COMPILER) | ||
| 16 | enable_language(Swift) | ||
| 17 | endif() | ||
| 18 | endif() | ||
| 19 | endif() | ||
| 20 | |||
| 21 | message(STATUS "CMAKE_SYSTEM_NAME= ${CMAKE_SYSTEM_NAME}") | ||
| 22 | message(STATUS "CMAKE_SYSTEM_PROCESSOR= ${CMAKE_SYSTEM_PROCESSOR}") | ||
| 23 | |||
| 24 | include(GenerateExportHeader) | ||
| 25 | |||
| 26 | if(ANDROID) | ||
| 27 | macro(add_executable NAME) | ||
| 28 | set(args ${ARGN}) | ||
| 29 | list(REMOVE_ITEM args WIN32) | ||
| 30 | add_library(${NAME} SHARED ${args}) | ||
| 31 | unset(args) | ||
| 32 | endmacro() | ||
| 33 | endif() | ||
| 34 | |||
| 35 | cmake_policy(SET CMP0074 NEW) | ||
| 36 | |||
| 37 | # Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3 outside of sysroot | ||
| 38 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) | ||
| 39 | |||
| 40 | include(FeatureSummary) | ||
| 41 | |||
| 42 | option(TEST_SHARED "Test linking to shared SDL3 library" ON) | ||
| 43 | add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") | ||
| 44 | |||
| 45 | option(TEST_STATIC "Test linking to static SDL3 library" ON) | ||
| 46 | add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") | ||
| 47 | |||
| 48 | option(TEST_TEST "Test linking to SDL3_test library" ON) | ||
| 49 | add_feature_info("TEST_TEST" TEST_STATIC "Test linking to SDL test library") | ||
| 50 | |||
| 51 | option(TEST_FULL "Run complete SDL test suite" OFF) | ||
| 52 | add_feature_info("TEST_FULL" TEST_FULL "Build full SDL testsuite") | ||
| 53 | |||
| 54 | find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers) | ||
| 55 | add_library(headers_test_slash OBJECT inc_sdl_slash.c) | ||
| 56 | target_link_libraries(headers_test_slash PRIVATE SDL3::Headers) | ||
| 57 | |||
| 58 | if(TEST_SHARED) | ||
| 59 | find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-shared) | ||
| 60 | add_executable(gui-shared WIN32 main_gui.c) | ||
| 61 | target_link_libraries(gui-shared PRIVATE SDL3::SDL3-shared) | ||
| 62 | if(WIN32) | ||
| 63 | add_custom_command(TARGET gui-shared POST_BUILD | ||
| 64 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:gui-shared>" | ||
| 65 | ) | ||
| 66 | endif() | ||
| 67 | |||
| 68 | add_library(sharedlib-shared SHARED main_lib.c) | ||
| 69 | target_link_libraries(sharedlib-shared PRIVATE SDL3::SDL3-shared) | ||
| 70 | generate_export_header(sharedlib-shared EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
| 71 | target_compile_definitions(sharedlib-shared PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared_export.h\"") | ||
| 72 | set_target_properties(sharedlib-shared PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
| 73 | |||
| 74 | add_executable(cli-shared main_cli.c) | ||
| 75 | target_link_libraries(cli-shared PRIVATE SDL3::SDL3-shared) | ||
| 76 | if(WIN32) | ||
| 77 | add_custom_command(TARGET cli-shared POST_BUILD | ||
| 78 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:cli-shared>" | ||
| 79 | ) | ||
| 80 | endif() | ||
| 81 | |||
| 82 | if(TEST_TEST) | ||
| 83 | add_executable(sdltest-shared sdltest.c) | ||
| 84 | target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared) | ||
| 85 | endif() | ||
| 86 | |||
| 87 | if(CMAKE_Swift_COMPILER) | ||
| 88 | add_executable(swift-shared main.swift) | ||
| 89 | target_include_directories(swift-shared PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift") | ||
| 90 | target_link_libraries(swift-shared PRIVATE SDL3::SDL3-shared) | ||
| 91 | endif() | ||
| 92 | endif() | ||
| 93 | |||
| 94 | if(TEST_STATIC) | ||
| 95 | find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-static) | ||
| 96 | add_executable(gui-static WIN32 main_gui.c) | ||
| 97 | target_link_libraries(gui-static PRIVATE SDL3::SDL3-static) | ||
| 98 | |||
| 99 | # Assume SDL library has been built with `set(CMAKE_POSITION_INDEPENDENT_CODE ON)` | ||
| 100 | add_library(sharedlib-static SHARED main_lib.c) | ||
| 101 | target_link_libraries(sharedlib-static PRIVATE SDL3::SDL3-static) | ||
| 102 | generate_export_header(sharedlib-static EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
| 103 | target_compile_definitions(sharedlib-static PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-static_export.h\"") | ||
| 104 | set_target_properties(sharedlib-static PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
| 105 | |||
| 106 | if(TEST_TEST) | ||
| 107 | add_executable(sdltest-static sdltest.c) | ||
| 108 | target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static) | ||
| 109 | endif() | ||
| 110 | |||
| 111 | if(CMAKE_Swift_COMPILER) | ||
| 112 | add_executable(swift-static main.swift) | ||
| 113 | target_include_directories(swift-static PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift") | ||
| 114 | target_link_libraries(swift-static PRIVATE SDL3::SDL3-static) | ||
| 115 | endif() | ||
| 116 | endif() | ||
| 117 | |||
| 118 | find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3) | ||
| 119 | add_executable(gui-whatever WIN32 main_gui.c) | ||
| 120 | target_link_libraries(gui-whatever PRIVATE SDL3::SDL3) | ||
| 121 | |||
| 122 | if(TEST_FULL) | ||
| 123 | enable_testing() | ||
| 124 | set(SDL_TESTS_TIMEOUT_MULTIPLIER "1" CACHE STRING "Test timeout multiplier") | ||
| 125 | set(SDL_TESTS_LINK_SHARED ${TEST_SHARED}) | ||
| 126 | |||
| 127 | add_definitions(-DNO_BUILD_CONFIG) | ||
| 128 | add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../test" SDL_test) | ||
| 129 | endif() | ||
| 130 | |||
| 131 | if(ANDROID) | ||
| 132 | find_package(SDL3 REQUIRED CONFIG COMPONENTS Jar) | ||
| 133 | endif() | ||
| 134 | |||
| 135 | feature_summary(WHAT ALL) | ||
