Skip to content

Commit

Permalink
Guard metal backend + executable to apple platforms.
Browse files Browse the repository at this point in the history
Signed-off-by: furby™ <[email protected]>
  • Loading branch information
furby-tm committed Oct 28, 2024
1 parent a46f4d6 commit d2bc1e8
Showing 1 changed file with 62 additions and 36 deletions.
98 changes: 62 additions & 36 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ let package = Package(
name: "backend_glfw",
targets: ["backend_glfw"]
),
.library(
name: "backend_metal",
targets: ["backend_metal"]
),
.executable(
name: "example_glfw_metal",
targets: ["example_glfw_metal"]
),
],
] + Arch.addPlatformProducts(),
targets: [
.target(
name: "imgui_cxx",
Expand All @@ -60,11 +52,12 @@ let package = Package(
"src"
],
cxxSettings: [
.define("_GLFW_COCOA", to: "1", .when(platforms: [.macOS, .iOS, .visionOS, .tvOS, .watchOS])),
.define(
"_GLFW_COCOA", to: "1", .when(platforms: [.macOS, .iOS, .visionOS, .tvOS, .watchOS])),
.define("_GLFW_X11", to: "1", .when(platforms: [.linux, .android, .openbsd])),
.define("_GLFW_WIN32", to: "1", .when(platforms: [.windows])),
.define("GL_SILENCE_DEPRECATION", to: "1"),
.unsafeFlags(["-fno-objc-arc"]) // TODO: remove.
.unsafeFlags(["-fno-objc-arc"]), // TODO: remove.
],
linkerSettings: [
.linkedLibrary("opengl32", .when(platforms: [.windows])),
Expand All @@ -76,33 +69,23 @@ let package = Package(
.linkedLibrary("Xt", .when(platforms: [.linux, .android, .openbsd])),
.linkedFramework("Cocoa", .when(platforms: [.macOS])),
.linkedFramework("GLUT", .when(platforms: [.macOS])),
.linkedFramework("GameController", .when(platforms: [.macOS, .iOS, .visionOS, .tvOS, .watchOS])),
.linkedFramework(
"GameController", .when(platforms: [.macOS, .iOS, .visionOS, .tvOS, .watchOS])),
]
),

.target(
name: "backend_glfw",
dependencies: [
.target(name: "glfw"),
.target(name: "imgui_cxx")
.target(name: "imgui_cxx"),
],
path: "imgui-cxx/backends",
sources: [
"imgui_impl_glfw.cpp"
],
publicHeadersPath: "."
),
.target(
name: "backend_metal",
dependencies: [
.target(name: "imgui_cxx")
],
path: "imgui-cxx/backends",
sources: [
"imgui_impl_metal.mm"
],
publicHeadersPath: "."
),

.target(
name: "ImGui",
Expand All @@ -114,24 +97,14 @@ let package = Package(
]
),

.executableTarget(
name: "example_glfw_metal",
dependencies: [
.target(name: "imgui_cxx"),
.target(name: "backend_glfw"),
.target(name: "backend_metal", condition: .when(platforms: [.macOS, .iOS, .visionOS, .tvOS, .watchOS])),
],
path: "imgui-cxx/examples/example_glfw_metal"
),

.testTarget(
name: "ImGuiTests",
dependencies: ["ImGui"],
swiftSettings: [
.interoperabilityMode(.Cxx)
]
),
],
] + Arch.addPlatformExamples(),
cxxLanguageStandard: .cxx17
)

Expand All @@ -143,7 +116,7 @@ enum Arch {
"src/wl_monitor.c",
"src/glfw.rc.in",
"src/CMakeLists.txt",
"src/mappings.h.in"
"src/mappings.h.in",
]
#if !os(Windows)
excludes += [
Expand Down Expand Up @@ -185,4 +158,57 @@ enum Arch {

return excludes
}

static func addPlatformProducts() -> [Product] {
#if os(macOS)
[
.library(
name: "backend_metal",
targets: ["backend_metal"]
),
.executable(
name: "example_glfw_metal",
targets: ["example_glfw_metal"]
),
]
#else
[
// todo.
]
#endif
}

static func addPlatformExamples() -> [Target] {
#if os(macOS)
[
.target(
name: "backend_metal",
dependencies: [
.target(name: "imgui_cxx")
],
path: "imgui-cxx/backends",
sources: [
"imgui_impl_metal.mm"
],
publicHeadersPath: "."
),

.executableTarget(
name: "example_glfw_metal",
dependencies: [
.target(name: "imgui_cxx"),
.target(name: "backend_glfw"),
.target(
name: "backend_metal",
condition: .when(platforms: [.macOS, .iOS, .visionOS, .tvOS, .watchOS])),
],
path: "imgui-cxx/examples/example_glfw_metal"
),
]
#else
[
// todo.
]
#endif
}
}

0 comments on commit d2bc1e8

Please sign in to comment.