Generate-xcodeproj and System Library targets

Something I've been encountering when trying to get SwiftPM packages that use systemLibrary targets is that they will not be created as a target in the xcode project, and that you need to add the module path to "Import Paths" in Xcode.

So for example if I have a package for my project MyProject and it has PackageDependencyA and PackageDependencyA has a system library dependency CFreetype, I need to manually go in and add an Import Path to the CFreetype module location in the PackageDependencyA target that is created in the xcode project.

This is something that's not really that easy to figure out for people, and I find if I haven't done it for a couple weeks I completely forget what I have to do and end up searching through old projects to figure it out again.

Is there a way to get generate-xcodeproj to fill that field out properly, or is this something that's going to be changed in the future?

It sounds like a bug to me. Report it here: bugs.swift.org.

I can confirm above. My Package.swift:

import PackageDescription

let package = Package(
    name: "App",
    targets: [
        .systemLibrary(name: "CGLFW", pkgConfig: "libglfw", providers: [.apt(["libglfw3-dev"]), .brew(["glfw"])]),
        .systemLibrary(name: "CVulkan", pkgConfig: "libvulkan", providers: [.apt(["libvulkan-dev"])]),
        .target(
            name: "App",
            dependencies: ["CGLFW", "CVulkan"],
            linkerSettings: [
                .unsafeFlags([
                    "-L/usr/local/lib/"
                ])
            ]
        ),
        .testTarget(
            name: "AppTests",
            dependencies: ["App"]),
    ]
)

My Sources folder:

Sources
├── App
│   └── main.swift
├── CGLFW
│   ├── cglfw.h
│   └── module.modulemap
└── CVulkan
    ├── cvulkan.h
    └── module.modulemap

The project compiles and runs with swift build/run but when I generate xcode project via swift package generate-xcodeproj and open it in xcode the project fails to compile. To fix it I manually add /usr/local/lib/ to Library Serarch Path and /usr/local/include to Header Search Paths in xcode, then all work fine.

This sounds like a bug, but since generate-xcodeproj has been deprecated now, it is unlikely that it would get prioritized by the team. PRs would still be welcome, of course.

Terms of Service

Privacy Policy

Cookie Policy