Skip to content

Commit

Permalink
Create DefaultBackend which adapts to match the current platform (wil…
Browse files Browse the repository at this point in the history
…l use for examples once AppKitBackend is ready)
  • Loading branch information
stackotter committed Apr 8, 2024
1 parent f9cf4a9 commit bcdca63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ var swift510Products: [Product] = []
]
#endif

let defaultBackend: String
if let backend = ProcessInfo.processInfo.environment["SCUI_DEFAULT_BACKEND"] {
defaultBackend = backend
} else {
#if os(macOS)
defaultBackend = "AppKitBackend"
#elseif os(Windows)
defaultBackend = "WinUIBackend"
#else
defaultBackend = "GtkBackend"
#endif
}

let package = Package(
name: "swift-cross-ui",
platforms: [.macOS(.v10_15)],
Expand Down Expand Up @@ -109,6 +122,12 @@ let package = Package(
name: "SwiftCrossUITests",
dependencies: ["SwiftCrossUI"]
),
.target(
name: "DefaultBackend",
dependencies: [
.target(name: defaultBackend)
]
),
.target(name: "AppKitBackend", dependencies: ["SwiftCrossUI"]),
.target(
name: "QtBackend",
Expand Down
21 changes: 21 additions & 0 deletions Sources/DefaultBackend/DefaultBackend.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#if canImport(AppKitBackend)
import AppKitBackend
public typealias DefaultBackend = AppKitBackend
#elseif canImport(GtkBackend)
import GtkBackend
public typealias DefaultBackend = GtkBackend
#elseif canImport(QtBackend)
import QtBackend
public typealias DefaultBackend = QtBackend
#elseif canImport(WinUIBackend)
import WinUIBackend
public typealias DefaultBackend = WinUIBackend
#elseif canImport(CursesBackend)
import CursesBackend
public typealias DefaultBackend = CursesBackend
#elseif canImport(LVGLBackend)
import LVGLBackend
public typealias DefaultBackend = LVGLBackend
#else
#error("Unknown backend selected")
#endif

0 comments on commit bcdca63

Please sign in to comment.