2

I'm working on a Swift package that should depend on GLFW only on desktop (MacOS or Linux), but not for iOS, since GLFW does not build for iOS.

How would I go about this?

I have a system library defined like so:

import PackageDescription

let package = Package(
    name: "GLFWSystemLibrary",
    products: [
        .library(name: "CGLFW3", targets: ["CGLFW3"]),
    ],
    dependencies: [],
    targets: [
        .systemLibrary(
            name: "CGLFW3",
            pkgConfig: "glfw3",
            providers: [
                .brew(["glfw"]),
                .apt(["libglfw3"])
            ]
        )
    ]
)

And my build fails when I try to include this in an iOS project.

Is it enough to just conditionally include CGLFW in the libraries which depend on this, or else how would I make a dependency conditional in Swift Package Manager?

I.e. can I do something like this?

#if !os(iOS)
import CGLFW
#endif

Or else how would I achieve this?

1 Answer 1

2

Your code totally works! Additionally, you can also use:

#if canImport(AppKit)
#endif

Or even:

#if canImport(CGLFW)
#endif

It depends on what you prefer!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.