Simple Directmedia Layer

cmake: add swift test

+45
+25
cmake/test/CMakeLists.txt
··· 3 3 cmake_minimum_required(VERSION 3.12) 4 4 project(sdl_test LANGUAGES C) 5 5 6 + include(CheckLanguage) 7 + 8 + if(APPLE) 9 + # multiple values for CMAKE_OSX_ARCHITECTURES not supported with Swift 10 + list(LENGTH CMAKE_OSX_ARCHITECTURES count_osx_archs) 11 + if(count_osx_archs LESS_EQUAL 1) 12 + check_language(Swift) 13 + if(CMAKE_Swift_COMPILER) 14 + enable_language(Swift) 15 + endif() 16 + endif() 17 + endif() 18 + 6 19 message(STATUS "CMAKE_SYSTEM_NAME= ${CMAKE_SYSTEM_NAME}") 7 20 message(STATUS "CMAKE_SYSTEM_PROCESSOR= ${CMAKE_SYSTEM_PROCESSOR}") 8 21 ··· 74 87 add_executable(sdltest-shared sdltest.c) 75 88 target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared) 76 89 endif() 90 + 91 + if(CMAKE_Swift_COMPILER) 92 + add_executable(swift-shared main.swift) 93 + target_include_directories(swift-shared PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift") 94 + target_link_libraries(swift-shared PRIVATE SDL3::SDL3-shared) 95 + endif() 77 96 endif() 78 97 79 98 if(TEST_STATIC) ··· 91 110 if(TEST_TEST) 92 111 add_executable(sdltest-static sdltest.c) 93 112 target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static) 113 + endif() 114 + 115 + if(CMAKE_Swift_COMPILER) 116 + add_executable(swift-static main.swift) 117 + target_include_directories(swift-static PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift") 118 + target_link_libraries(swift-static PRIVATE SDL3::SDL3-static) 94 119 endif() 95 120 endif() 96 121
+13
cmake/test/main.swift
··· 1 + /* Contributed by Piotr Usewicz (https://github.com/pusewicz) */ 2 + 3 + import SDL3 4 + 5 + guard SDL_Init(Uint32(SDL_INIT_VIDEO)) == 0 else { 6 + fatalError("SDL_Init error: \(String(cString: SDL_GetError()))") 7 + } 8 + 9 + var sdlVersion = SDL_GetVersion() 10 + 11 + print("SDL version: \(sdlVersion)") 12 + 13 + SDL_Quit()
+4
cmake/test/swift/module.modulemap
··· 1 + module SDL3 [extern_c] { 2 + header "shim.h" 3 + export * 4 + }
+3
cmake/test/swift/shim.h
··· 1 + /* Contributed by Piotr Usewicz (https://github.com/pusewicz) */ 2 + 3 + #include <SDL3/SDL.h>