Skip to content

Mac Catalyst - xcframework support #17929

@BrainFeverMedia

Description

@BrainFeverMedia
System information

OpenCV => 4.4.0
Operating System / Platform => macOS Catalina 10.15.5
Compiler => Xcode 11.5 and Xcode 12 beta3

Detailed description

I'm trying to build a Mac Catalyst app using OpenCV. Xcode builds a Mac Catalyst app using the iOS SDK for architecture x86. A Catalyst app looks like an iPad app running on a Mac.
Catalyst requires frameworks to be an xcframework. Apple presented XCFramework as a new binary format of packing libraries.

Steps to reproduce

Here is the commands to create an xcframework, as created by @chrisballinger in #17291

d path/to/opencv
python2 platforms/ios/build_framework.py --iphonesimulator_archs x86_64 --iphoneos_archs arm64 .

mkdir -p build/xcframework
cp build/build-arm64-iphoneos/lib/Release/libopencv_merged.a build/xcframework/libopencv-arm64-iphoneos.a
cp build/build-x86_64-iphonesimulator/lib/Release/libopencv_merged.a build/xcframework/libopencv-x86_64-iphonesimulator.a

# Set project level "Base SDK" to "iOS".
open build/build-x86_64-iphonesimulator/OpenCV.xcodeproj

xcodebuild build -configuration Release -project build/build-x86_64-iphonesimulator/OpenCV.xcodeproj -scheme "ALL_BUILD" -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -UseModernBuildSystem=YES SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES TARGETED_DEVICE_FAMILY="1,2" SDKROOT=iphoneos SUPPORTS_MAC_CATALYST=YES

libtool -static -o build/xcframework/libopencv-x86_64-maccatalyst.a build/build-x86_64-iphonesimulator/lib/Release/*.a build/build-x86_64-iphonesimulator/3rdparty/lib/Release/*.a

xcodebuild -create-xcframework -library build/xcframework/libopencv-arm64-iphoneos.a -headers build/build-arm64-iphoneos/install/include/opencv2 -library build/xcframework/libopencv-x86_64-iphonesimulator.a -headers build/build-x86_64-iphonesimulator/install/include/opencv2 -library build/xcframework/libopencv-x86_64-maccatalyst.a -headers build/build-x86_64-iphonesimulator/install/include/opencv2 -output build/xcframework/opencv2.xcframework

The last step fails with this errror:

-error: binaries with multiple platforms are not supported 'build/xcframework/libopencv-x86_64-maccatalyst.a'

I was able to create an xcframework manually by doing the following:
1 - Create and xcframework with libopencv-arm64-iphoneos.a and libopencv-x86_64-iphonesimulator.a
2 - opencv2.xcframework is created, which is a folder
3 - Manually add libopencv-x86_64-maccatalyst.a to folder, copy Headers folder, and update plist file in folder.

When adding this to an xcode project, xcode gives this build error:

-Both ios-arm64 and os-x86_64-maccatalyst represent two equivalent library definitions.

I tried both Xcode 11.5 and 12 beta3 with same errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions