mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-22 04:38:30 +00:00
cmake: add swift test
This commit is contained in:
parent
37881b3150
commit
8a5d1fc196
4 changed files with 45 additions and 0 deletions
|
@ -3,6 +3,19 @@
|
||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
project(sdl_test LANGUAGES C)
|
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_NAME= ${CMAKE_SYSTEM_NAME}")
|
||||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR= ${CMAKE_SYSTEM_PROCESSOR}")
|
message(STATUS "CMAKE_SYSTEM_PROCESSOR= ${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
|
||||||
|
@ -74,6 +87,12 @@ if(TEST_SHARED)
|
||||||
add_executable(sdltest-shared sdltest.c)
|
add_executable(sdltest-shared sdltest.c)
|
||||||
target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared)
|
target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared)
|
||||||
endif()
|
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()
|
endif()
|
||||||
|
|
||||||
if(TEST_STATIC)
|
if(TEST_STATIC)
|
||||||
|
@ -92,6 +111,12 @@ if(TEST_STATIC)
|
||||||
add_executable(sdltest-static sdltest.c)
|
add_executable(sdltest-static sdltest.c)
|
||||||
target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static)
|
target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static)
|
||||||
endif()
|
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()
|
endif()
|
||||||
|
|
||||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3)
|
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3)
|
||||||
|
|
13
cmake/test/main.swift
Normal file
13
cmake/test/main.swift
Normal 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()
|
4
cmake/test/swift/module.modulemap
Normal file
4
cmake/test/swift/module.modulemap
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module SDL3 [extern_c] {
|
||||||
|
header "shim.h"
|
||||||
|
export *
|
||||||
|
}
|
3
cmake/test/swift/shim.h
Normal file
3
cmake/test/swift/shim.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/* Contributed by Piotr Usewicz (https://github.com/pusewicz) */
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
Loading…
Add table
Add a link
Reference in a new issue