I have a Swift package that contains a C target called mylib. I'm getting a warning in Xcode that Source files for target mylib should be located under /path/to/SomeSwiftPackage/Sources/mylib . The issue is, that's exactly where my source files are located. My Package.swift file looks something like this:
// swift-tools-version:5.5
import PackageDescription
let package = Package(
name: "SomeSwiftPackage",
products: [
.library(
name: "SomeSwiftPackage",
targets: ["SomeSwiftPackage"]),
],
dependencies: [],
targets: [
.target(
name: "mylib",
dependencies: []
),
.target(
name: "SomeSwiftPackage",
dependencies: [
.target(name: "mylib"),
]
)
]
)
My folder structure looks something like this:
SomeSwiftPackage/
Package.swift
Sources/
SomeSwiftPackage/
SomeSwiftPackage.swift
mylib/
include/
mylib.h
mylib.c
helper.h
helper.c
The only file for mylib not directly under /path/to/SomeSwiftPackage/Sources/mylib is the required header in the include directory. How can I remove this warning?
When SwiftPM sees a "C-family" target (a C/Obj-C/C++ target), it expects you to find all the source files and public headers in a particular layout. In particular, when you have a separate "#include/" folder inside of Sources/mylib, you need to tell SwiftPM where you've put all your public headers.
Easiest way to clear the warning is to specify both the target's path and its publicHeadersPath explicitly in Package.swift, for example:
.target(
name: "mylib",
// Tell SwiftPM exactly where “mylib” is
path: "Sources/mylib",
// Tell SwiftPM that public headers live in the “include/” subdirectory
publicHeadersPath: "include"
)
This way, SwiftPM and Xcode know your .c/.h files are meant to live in Sources/mylib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With