cmake: add swift test

This commit is contained in:
Anonymous Maarten 2024-07-26 21:00:33 +02:00
parent 37881b3150
commit 8a5d1fc196
4 changed files with 45 additions and 0 deletions

View File

@ -3,6 +3,19 @@
cmake_minimum_required(VERSION 3.12)
project(sdl_test LANGUAGES C)
include(CheckLanguage)
if(APPLE)
# multiple values for CMAKE_OSX_ARCHITECTURES not supported with Swift
list(LENGTH CMAKE_OSX_ARCHITECTURES count_osx_archs)
if(count_osx_archs LESS_EQUAL 1)
check_language(Swift)
if(CMAKE_Swift_COMPILER)
enable_language(Swift)
endif()
endif()
endif()
message(STATUS "CMAKE_SYSTEM_NAME= ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_SYSTEM_PROCESSOR= ${CMAKE_SYSTEM_PROCESSOR}")
@ -74,6 +87,12 @@ if(TEST_SHARED)
add_executable(sdltest-shared sdltest.c)
target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared)
endif()
if(CMAKE_Swift_COMPILER)
add_executable(swift-shared main.swift)
target_include_directories(swift-shared PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift")
target_link_libraries(swift-shared PRIVATE SDL3::SDL3-shared)
endif()
endif()
if(TEST_STATIC)
@ -92,6 +111,12 @@ if(TEST_STATIC)
add_executable(sdltest-static sdltest.c)
target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static)
endif()
if(CMAKE_Swift_COMPILER)
add_executable(swift-static main.swift)
target_include_directories(swift-static PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/swift")
target_link_libraries(swift-static PRIVATE SDL3::SDL3-static)
endif()
endif()
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3)

13
cmake/test/main.swift Normal file
View File

@ -0,0 +1,13 @@
/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */
import SDL3
guard SDL_Init(Uint32(SDL_INIT_VIDEO)) == 0 else {
fatalError("SDL_Init error: \(String(cString: SDL_GetError()))")
}
var sdlVersion = SDL_GetVersion()
print("SDL version: \(sdlVersion)")
SDL_Quit()

View File

@ -0,0 +1,4 @@
module SDL3 [extern_c] {
header "shim.h"
export *
}

3
cmake/test/swift/shim.h Normal file
View File

@ -0,0 +1,3 @@
/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */
#include <SDL3/SDL.h>