From 50f4f02f8545f641bb21efd42d5a15a770f7dca3 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Sat, 3 Aug 2024 23:28:29 -0700 Subject: [PATCH] SDL3 support --- CMakeLists.txt | 2 ++ Sources/CMakeLists.txt | 1 + Sources/SDL3/CMakeLists.txt | 7 +++++++ Sources/SDL3/SDL3.cpp | 1 + Sources/SDL3/SDL3.h | 3 +++ Sources/SDL3/module.modulemap | 3 +++ Sources/SwiftFrontend/CMakeLists.txt | 2 +- Sources/SwiftFrontend/main.swift | 11 ++++++++--- 8 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 Sources/SDL3/CMakeLists.txt create mode 100644 Sources/SDL3/SDL3.cpp create mode 100644 Sources/SDL3/SDL3.h create mode 100644 Sources/SDL3/module.modulemap diff --git a/CMakeLists.txt b/CMakeLists.txt index 32ac31e..38ca47c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,4 +5,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") include(InitializeSwift) include(AddSwift) +find_package(SDL3 CONFIG REQUIRED) + add_subdirectory(Sources) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 5c44d74..e8a2145 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(SwiftFrontend) +add_subdirectory(SDL3) add_subdirectory(CppBackend) diff --git a/Sources/SDL3/CMakeLists.txt b/Sources/SDL3/CMakeLists.txt new file mode 100644 index 0000000..3fc394a --- /dev/null +++ b/Sources/SDL3/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(SDL3 STATIC SDL3.h SDL3.cpp) +set_property(TARGET SDL3 PROPERTY Swift_MODULE_NAME "SDL3") +set_property(TARGET SDL3 PROPERTY CXX_STANDARD 20) + +target_compile_options(SDL3 PUBLIC "$<$:-cxx-interoperability-mode=default>") +target_include_directories(SDL3 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(SDL3 PUBLIC SDL3::SDL3) diff --git a/Sources/SDL3/SDL3.cpp b/Sources/SDL3/SDL3.cpp new file mode 100644 index 0000000..cf04475 --- /dev/null +++ b/Sources/SDL3/SDL3.cpp @@ -0,0 +1 @@ +#include "SDL3.h" diff --git a/Sources/SDL3/SDL3.h b/Sources/SDL3/SDL3.h new file mode 100644 index 0000000..3771e11 --- /dev/null +++ b/Sources/SDL3/SDL3.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/Sources/SDL3/module.modulemap b/Sources/SDL3/module.modulemap new file mode 100644 index 0000000..1091db3 --- /dev/null +++ b/Sources/SDL3/module.modulemap @@ -0,0 +1,3 @@ +module SDL3 { + header "SDL3.h" +} diff --git a/Sources/SwiftFrontend/CMakeLists.txt b/Sources/SwiftFrontend/CMakeLists.txt index ebaff1b..6ecc7bb 100644 --- a/Sources/SwiftFrontend/CMakeLists.txt +++ b/Sources/SwiftFrontend/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(SwiftFrontend main.swift) -target_link_libraries(SwiftFrontend PRIVATE CppBackend) +target_link_libraries(SwiftFrontend PRIVATE CppBackend SDL3) diff --git a/Sources/SwiftFrontend/main.swift b/Sources/SwiftFrontend/main.swift index 9d3c0b7..520f343 100644 --- a/Sources/SwiftFrontend/main.swift +++ b/Sources/SwiftFrontend/main.swift @@ -1,4 +1,9 @@ -import CppBackend +import Foundation +import SDL3 -backend_init() -print("Hello World") +guard SDL_Init(SDL_INIT_VIDEO) >= 0 else { + print("SDL init failed.") + exit(0) +} +print("SDL init success.") +SDL_Quit()