Skip to content

Commit

Permalink
cmake: add swift test
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Jul 26, 2024
1 parent d4c7843 commit 05ce748
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmake/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down Expand Up @@ -74,6 +87,11 @@ 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 swift/main.swift)
target_link_libraries(swift-shared PRIVATE SDL3::SDL3-shared)
endif()
endif()

if(TEST_STATIC)
Expand All @@ -92,6 +110,11 @@ 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 swift/main.swift)
target_link_libraries(swift-static PRIVATE SDL3::SDL3-static)
endif()
endif()

find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3)
Expand Down
13 changes: 13 additions & 0 deletions cmake/test/swift/main.swift
Original file line number Diff line number Diff line change
@@ -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: \(SDL_VERSIONNUM_MAJOR(sdlVersion)).\(SDL_VERSIONNUM_MINOR(sdlVersion)).\(SDL_VERSIONNUM_MICRO(sdlVersion))")

SDL_Quit()
4 changes: 4 additions & 0 deletions cmake/test/swift/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module SDL3 [extern_c] {
header "shim.h"
export *
}
3 changes: 3 additions & 0 deletions cmake/test/swift/shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */

#include <SDL3/SDL.h>

0 comments on commit 05ce748

Please sign in to comment.