I'm trying to wrap an XCFramework as a swift package. Following the documentation, I have created a package with the following directory structure:
/MyXCFPackage
/Package.swift
/MyXCFPackage.xcframework
/include <- some additional headers here
And my Package.swift
looks like so:
// swift-tools-version:5.6
import PackageDescription
let package = Package(
name: "MyXCFPackage",
products: [
.library(
name: "MyXCFPackage",
targets: ["MyXCFPackage"])
],
targets: [
.binaryTarget(
name: "MyXCFPackage",
path: "./MyXCFPackage.xcframework"
)
]
)
The thing is, this framework was not structured originally for Swift Package Manager, and the XCFramework does not contain the headers, just the .a
files for the library. As a result, when I include this package in a client project, the headers are not available.
In the instructions for the framework, it says that the /include
directory should be added to the Xcode build settings under HEADER_SEARCH_PATHS
.
How can I get these headers into the HEADER_SEARCH_PATHS
through Swift Package Manager?
The headers need to be bundled within the XCFramework. You can specify the headers when you create it. Check out the info in xcodebuild -h
:
xcodebuild -create-xcframework [-help] [-framework <path>] [-library <path> [-headers <path>]] -output <path>
So, to create an XCFramework from a static library and include headers, the command would be:
xcodebuild -create-xcframework \
-library MyXCFPackage \
-headers ./include \
-output MyXCFPackage.xcframework
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.