I have static libraries and headers of a C++ project that I believe are correctly built for iOS and iOS Simulator destinations. The C++ project is built via CMake with something like:
cmake dirName \
-G "Unix Makefiles" \
-B buildDir \
-DCMAKE_INSTALL_PREFIX=installDir \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_SYSTEM_PROCESSOR=arm64 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_OSX_SYSROOT=$(xcrun --sdk iphonesimulator --show-sdk-path) \
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0
...
cmake --build buildDir --config Release --target install
I believe those are all the important parameters. This gives me a static library (.a
) and headers that I believe should be compatible with arm64 iOS simulators, and I do this same thing for x86_64 architecture with simulators and for actual iOS non-simulator via the iphoneos
SDK path.
I'm pretty sure this gives me the correct static lib and headers. Let's assume it does because I'm not able actually create the XCFramework to know if they're right. This does work with a macOS lib and headers, but I need iOS for this library. How do I package this into an XCFramework now?
This Apple developer articles says I should be a able to create an xcframework via xcodebuild -create-xcframework -library libName.a -headers include
but when I try to do this with my my iOS arm64 simulator static lib I get:
error: binaries with multiple platforms are not supported '/Users/.../install/ios-arm64-simulator/libName.a
But, when I run: lips -info libName.a
I get Non-fat file libName.a is architecture arm64
, so, I'm not sure what to do here. Trying to extract arm64 from that static library also produces an error as it it is just an arm64 lib.
I'm not really sure what's going on, but from reading online this specific command, xcodebuild -create-xcframework
is a consistent pain point in the process of trying to get an XCFramework, and the seemingly only workaround is to archive a framework project and then create the xcframework via xcodebuild -create-xcframework -archive MyFramework.xcarchive -framework[or -library]
.
However, how am I supposed to get this static lib and headers into a suitable xcodeproj so that I can archive it correctly? Everytime I try to copy the headers and static lib into the Framework xcodeproj and set what I believe are all the correct settings, my .xcarchive is always empty.
Does anyone have any advice here on how to get this to work?
The main impetus for trying to get this C++ static lib and headers into an XCFramework as that seems like the only valid way to link a 3rd party C++ lib to an SPM package and have the C++ package be interfaceable with Swift.