Ask Your Question
0

OpenCV build for Mac Catalyst/iOS 13 iOS app on Mac support?

asked 2019-07-30 23:21:27 -0600

pgos gravatar image

I have been trying to build openCV libraries which would be compatible for mac catalyst (iOS app built for Mac which is a new feature on iOS 13/Mac 10.15 beta) without much success.

This is the command the python build script calls while building OpenCV framework for Mac...

xcodebuild MACOSX_DEPLOYMENT_TARGET=10.15 ARCHS=x86_64 -sdk macosx -configuration Release -parallelizeTargets -jobs 12 -target ALL_BUILD build

I am assuming I need to change this to something else as well as the xcode projects are to be created a little differently. But I am not sure what I need to change to make it work.

If I can get the .a files created for mac catalyst, I guess I can manually create the xcframeworks myself.

Has anyone been able to do it successfully?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-08-06 01:53:31 -0600

Carlo R. gravatar image

updated 2019-08-06 02:54:14 -0600

I have managed to generate a universal XCFramework that can be used for Catalyst. There are probably more efficient ways but this is what worked for me:

  1. Move to the working directory (where OpenCV has been cloned / downloaded).

  2. Run the opencv/platforms/ios/build_framework.py script as instructed by the OpenCV documentation (https://docs.opencv.org/4.1.1/d5/da3/tutorial_ios_install.html). The script must be run twice so that two different opencv2.framework files can be generated: one for real iOS devices, one for the simulator (this is required to generate a universal XCFramework later on). The different frameworks can be obtained by editing the build_framework.py script and commenting out the unwanted targets (at the end of the script):

    • To generate the opencv2.framework for the simulator:

      # (iphoneos_archs, "iPhoneOS"),

      (iphonesimulator_archs, "iPhoneSimulator")

    • To generate the opencv2.framework for real iOS devices:

      (iphoneos_archs, "iPhoneOS")

      # (iphonesimulator_archs, "iPhoneSimulator")

  3. Back up what has been generated, then delete the following build files:

    • <working_dir>/ios/build/build-x86_64-iphonesimulator/build/*
    • <working_dir>/ios/build/build-x86_64-iphonesimulator/lib/*
    • <working_dir>/ios/build/build-x86_64-iphonesimulator/3rdparty/lib/*
  4. Open the following project with Xcode 11 or later:

    • <working_dir>/ios/build/build-x86_64-iphonesimulator/OpenCV.xcodeproj
  5. Configure all targets for Catalyst:

    • Set "Target Device Family" to "Universal"
    • Set "Architectures" to "Standard"
    • Set "Build Active Architecture Only" to Yes
    • Set "Supports Mac Catalyst" to Yes
  6. Build the "ALL_BUILD" scheme ("Release" configuration).

  7. Locate the build products:

    • <working_dir>/ios/build/build-x86_64-iphonesimulator/lib/Release/*.a
    • <working_dir>/ios/build/build-x86_64-iphonesimulator/3rdparty/lib/Release/*.a
  8. Merge the products as a single static library:

    • libtool -static -o <working_dir>/libopencv_merged_catalyst.a <all paths to *.a files from previous step>
  9. Create the opencv2 framework binary:

    • lipo -create <working_dir>/libopencv_merged_catalyst.a -o <working_dir>/opencv2
  10. Duplicate the opencv2.framework for iOS and substitute its binary with the new one for Catalyst (generated in the previous step).

  11. Create a universal XCFramework:

    • xcodebuild -create-xcframework -framework path/to/ios/opencv2.framework -framework path/to/ios-simulator/opencv2.framework -framework path/to/catalyst/opencv2.framework -output <working_dir>/opencv.xcframework
edit flag offensive delete link more

Comments

Thanks Carlo! I have been trying to follow these steps but getting stuck at step 5. When I open the project with Xcode 11 and go to the targets, I do not see the "General" tab in Xcode. Only "Resource Tab", "Build Settings", "Build Phases" and "Build Rules" are available. So I am not able to set "Enable Mac Catalyst" and "Target Device Family". How do access those options?

Here is how my Xcode looks... https://ibb.co/G53Kd3x

pgos gravatar imagepgos ( 2019-08-06 22:25:23 -0600 )edit

You should set those constants under "Build Settings". It's likely that you won't see some of them, like "Supports Mac Catalyst", but you can still set them. To do this easily you can create a dummy target ex. an iOS framework and go to its settings, there you should see the "Supports Mac Catalyst" row which you can just copy to the other targets.

Carlo R. gravatar imageCarlo R. ( 2019-08-07 01:54:52 -0600 )edit

Worked like a charm!

pgos gravatar imagepgos ( 2019-08-07 09:12:23 -0600 )edit

Hi Carlo, this is a great tutorial. Everything seems to have worked up to the final step :( xcodebuild fails with this message: Both ios-x86_64-simulator and ios-i386_x86_64-simulator represent two equivalent library definitions. Any thoughts as to where I screwed up?

PeterCV gravatar imagePeterCV ( 2019-10-26 01:09:50 -0600 )edit

Would you mind providing downloadable link of Opencv2.framework file built for catalyst? I've tried everything I can do to build opencv framework for catalyst myself without any good luck.

ukjax gravatar imageukjax ( 2019-11-29 19:41:54 -0600 )edit

I have the same problem as PeterCV on the step 11 "xcodebuild fails with this message: Both ios-x86_64-simulator and ios-i386_x86_64-simulator represent two equivalent library definitions." Could you please tell us how to solve this problem?

tianye2856 gravatar imagetianye2856 ( 2019-12-26 00:20:36 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2019-07-30 23:21:27 -0600

Seen: 2,143 times

Last updated: Aug 06 '19