From d2bc1e88d7ed684d1e4a1c9a5d7fdd001b8b2737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?furby=E2=84=A2?= Date: Mon, 28 Oct 2024 02:38:41 -0600 Subject: [PATCH] Guard metal backend + executable to apple platforms. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: furby™ --- Package.swift | 98 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/Package.swift b/Package.swift index 10b2875..fe34d8c 100644 --- a/Package.swift +++ b/Package.swift @@ -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", @@ -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])), @@ -76,7 +69,8 @@ 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])), ] ), @@ -84,7 +78,7 @@ let package = Package( name: "backend_glfw", dependencies: [ .target(name: "glfw"), - .target(name: "imgui_cxx") + .target(name: "imgui_cxx"), ], path: "imgui-cxx/backends", sources: [ @@ -92,17 +86,6 @@ let package = Package( ], publicHeadersPath: "." ), - .target( - name: "backend_metal", - dependencies: [ - .target(name: "imgui_cxx") - ], - path: "imgui-cxx/backends", - sources: [ - "imgui_impl_metal.mm" - ], - publicHeadersPath: "." - ), .target( name: "ImGui", @@ -114,16 +97,6 @@ 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"], @@ -131,7 +104,7 @@ let package = Package( .interoperabilityMode(.Cxx) ] ), - ], + ] + Arch.addPlatformExamples(), cxxLanguageStandard: .cxx17 ) @@ -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 += [ @@ -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 + } }