2023-04-27 23:46:08 +02:00
|
|
|
# Description:
|
|
|
|
# OpenCV xcframework for video/image processing on iOS.
|
|
|
|
|
|
|
|
licenses(["notice"]) # BSD license
|
|
|
|
|
|
|
|
exports_files(["LICENSE"])
|
|
|
|
|
|
|
|
load(
|
|
|
|
"@build_bazel_rules_apple//apple:apple.bzl",
|
|
|
|
"apple_static_xcframework_import",
|
|
|
|
)
|
|
|
|
load(
|
|
|
|
"@//third_party:opencv_ios_source.bzl",
|
|
|
|
"select_headers",
|
|
|
|
"unzip_opencv_xcframework",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Build opencv2.xcframework from source using a convenience script provided in
|
|
|
|
# OPENCV sources and zip the xcframework. We only build the modules required by MediaPipe by specifying
|
2023-05-05 22:34:46 +02:00
|
|
|
# the modules to be ignored as command line arguments.
|
2023-04-27 23:46:08 +02:00
|
|
|
# We also specify the simulator and device architectures we are building for.
|
|
|
|
# Currently we only support iOS arm64 (M1 Macs) and x86_64(Intel Macs) simulators
|
|
|
|
# and arm64 iOS devices.
|
|
|
|
# Bitcode and Swift support. Swift support will be added in when the final binary
|
|
|
|
# for MediaPipe iOS Task libraries are built. Shipping with OPENCV built with
|
|
|
|
# Swift support throws linker errors when the MediaPipe framework is used from
|
|
|
|
# an iOS project.
|
2023-05-06 01:09:09 +02:00
|
|
|
# When building on M1 Macs, cmake version cannot be higher than 3.24.0. This is
|
|
|
|
# is mentioned in an open issue in the opencv github repo.
|
2023-04-27 23:46:08 +02:00
|
|
|
genrule(
|
|
|
|
name = "build_opencv_xcframework",
|
2023-05-06 01:09:09 +02:00
|
|
|
srcs = glob(["opencv-4.5.3/**"]),
|
2023-04-27 23:46:08 +02:00
|
|
|
outs = ["opencv2.xcframework.zip"],
|
|
|
|
cmd = "&&".join([
|
2023-05-06 01:09:09 +02:00
|
|
|
"$(location opencv-4.5.3/platforms/apple/build_xcframework.py) \
|
2023-04-27 23:46:08 +02:00
|
|
|
--iphonesimulator_archs arm64,x86_64 \
|
|
|
|
--iphoneos_archs arm64 \
|
|
|
|
--without dnn \
|
|
|
|
--without ml \
|
|
|
|
--without stitching \
|
|
|
|
--without photo \
|
|
|
|
--without objdetect \
|
|
|
|
--without gapi \
|
|
|
|
--without flann \
|
|
|
|
--disable PROTOBUF \
|
|
|
|
--disable-bitcode \
|
|
|
|
--disable-swift \
|
|
|
|
--build_only_specified_archs \
|
|
|
|
--out $(@D)",
|
|
|
|
"cd $(@D)",
|
|
|
|
"zip --symlinks -r opencv2.xcframework.zip opencv2.xcframework",
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Unzips `opencv2.xcframework.zip` built from source by `build_opencv_xcframework`
|
|
|
|
# genrule and returns an exhaustive list of all its files including symlinks.
|
2023-05-05 22:34:46 +02:00
|
|
|
unzip_opencv_xcframework(
|
2023-04-27 23:46:08 +02:00
|
|
|
name = "opencv2_unzipped_xcframework_files",
|
|
|
|
zip_file = "opencv2.xcframework.zip",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Imports the files of the unzipped `opencv2.xcframework` as an apple static
|
|
|
|
# framework which can be linked to iOS targets.
|
|
|
|
apple_static_xcframework_import(
|
|
|
|
name = "opencv_xcframework",
|
|
|
|
visibility = ["//visibility:public"],
|
2023-05-05 22:34:46 +02:00
|
|
|
xcframework_imports = [":opencv2_unzipped_xcframework_files"],
|
2023-04-27 23:46:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Filters the headers for each platform in `opencv2.xcframework` which will be
|
|
|
|
# used as headers in a `cc_library` that can be linked to C++ targets.
|
|
|
|
select_headers(
|
|
|
|
name = "opencv_xcframework_device_headers",
|
|
|
|
srcs = [":opencv_xcframework"],
|
|
|
|
platform = "ios-arm64",
|
|
|
|
)
|
|
|
|
|
|
|
|
select_headers(
|
|
|
|
name = "opencv_xcframework_simulator_headers",
|
|
|
|
srcs = [":opencv_xcframework"],
|
|
|
|
platform = "ios-arm64_x86_64-simulator",
|
|
|
|
)
|
|
|
|
|
|
|
|
# `cc_library` that can be linked to C++ targets to import opencv headers.
|
|
|
|
cc_library(
|
|
|
|
name = "opencv",
|
|
|
|
hdrs = select({
|
2023-05-05 22:34:46 +02:00
|
|
|
"@//mediapipe:ios_x86_64": [
|
|
|
|
":opencv_xcframework_simulator_headers",
|
2023-04-27 23:46:08 +02:00
|
|
|
],
|
2023-05-05 22:34:46 +02:00
|
|
|
"@//mediapipe:ios_sim_arm64": [
|
|
|
|
":opencv_xcframework_simulator_headers",
|
2023-04-27 23:46:08 +02:00
|
|
|
],
|
2023-05-06 01:09:09 +02:00
|
|
|
"@//mediapipe:ios_arm64" : [
|
|
|
|
":opencv_xcframework_device_headers"
|
2023-04-27 23:46:08 +02:00
|
|
|
],
|
|
|
|
# A value from above is chosen arbitarily.
|
|
|
|
"//conditions:default": [
|
2023-05-05 22:34:46 +02:00
|
|
|
":opencv_xcframework_simulator_headers",
|
2023-04-27 23:46:08 +02:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
copts = [
|
|
|
|
"-std=c++11",
|
|
|
|
"-x objective-c++",
|
|
|
|
],
|
|
|
|
include_prefix = "opencv2",
|
|
|
|
linkopts = [
|
|
|
|
"-framework AssetsLibrary",
|
|
|
|
"-framework CoreFoundation",
|
|
|
|
"-framework CoreGraphics",
|
|
|
|
"-framework CoreMedia",
|
|
|
|
"-framework Accelerate",
|
|
|
|
"-framework CoreImage",
|
|
|
|
"-framework AVFoundation",
|
|
|
|
"-framework CoreVideo",
|
|
|
|
"-framework QuartzCore",
|
|
|
|
],
|
|
|
|
strip_include_prefix = select({
|
2023-05-05 22:34:46 +02:00
|
|
|
"@//mediapipe:ios_x86_64": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers",
|
|
|
|
"@//mediapipe:ios_sim_arm64": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers",
|
|
|
|
"@//mediapipe:ios_arm64": "opencv2.xcframework/ios-arm64/opencv2.framework/Versions/A/Headers",
|
2023-04-27 23:46:08 +02:00
|
|
|
# Random value is selected for default cases.
|
|
|
|
"//conditions:default": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers",
|
|
|
|
}),
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
deps = [":opencv_xcframework"],
|
2023-04-28 00:00:21 +02:00
|
|
|
)
|