Ask Your Question

Revision history [back]

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).

  3. Delete the following build files:

  4. <working_dir>/ios/build/build-x86_64-iphonesimulator/build/*
  5. <working_dir>/ios/build/build-x86_64-iphonesimulator/lib/*
  6. <working_dir>/ios/build/build-x86_64-iphonesimulator/3rdparty/lib/*

  7. Open the following project with Xcode 11 or later:

  8. <working_dir>/ios/build/build-x86_64-iphonesimulator/OpenCV.xcodeproj

  9. 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
  10. Build the "ALL_BUILD" scheme ("Release" configuration).

  11. Locate the build products:

  12. <working_dir>/ios/build/build-x86_64-iphonesimulator/lib/Release/*.a
  13. <working_dir>/ios/build/build-x86_64-iphonesimulator/3rdparty/lib/Release/*.a

  14. Merge the products as a single static library:

  15. libtool -static -o <working_dir>/libopencv_merged_catalyst.a <all paths to *.a files from previous step>

  16. Create the opencv2 framework binary:

  17. lipo -create <working_dir>/libopencv_merged_catalyst.a -o <working_dir>/opencv2

  18. Duplicate the opencv2.framework for iOS and substitute its binary with the new one for Catalyst (generated in the previous step).

  19. Create a universal XCFramework:

  20. 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

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).

  3. Delete ). 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")

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

  5. <working_dir>/ios/build/build-x86_64-iphonesimulator/build/*
  6. <working_dir>/ios/build/build-x86_64-iphonesimulator/lib/*
  7. <working_dir>/ios/build/build-x86_64-iphonesimulator/3rdparty/lib/*

  8. Open the following project with Xcode 11 or later:

  9. <working_dir>/ios/build/build-x86_64-iphonesimulator/OpenCV.xcodeproj

  10. 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
  11. Build the "ALL_BUILD" scheme ("Release" configuration).

  12. Locate the build products:

  13. <working_dir>/ios/build/build-x86_64-iphonesimulator/lib/Release/*.a
  14. <working_dir>/ios/build/build-x86_64-iphonesimulator/3rdparty/lib/Release/*.a

  15. Merge the products as a single static library:

  16. libtool -static -o <working_dir>/libopencv_merged_catalyst.a <all paths to *.a files from previous step>

  17. Create the opencv2 framework binary:

  18. lipo -create <working_dir>/libopencv_merged_catalyst.a -o <working_dir>/opencv2

  19. Duplicate the opencv2.framework for iOS and substitute its binary with the new one for Catalyst (generated in the previous step).

  20. Create a universal XCFramework:

  21. 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

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