英文:
Building OpenCV with rules_foreign_cc
问题
我想用Bazel在C++中开始一个新项目。为了构建OpenCV,我想使用foreign_rules_cc。
我已经按照一些教程进行了操作,但是我无法成功构建OpenCV。
这是我的WORKSPACE文件:
workspace(name = "rules_foreign_cc_usage_example")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Rule repository, note that it's recommended to use a pinned commit to a released version of the rules
http_archive(
name = "rules_foreign_cc",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
# This sets up some common toolchains for building targets. For more details, please see
# https://github.com/bazelbuild/rules_foreign_cc/tree/main/docs#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()
_OPENCV_CONTENT = """
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""
http_archive(
name = "opencv",
build_file_content = _OPENCV_CONTENT,
url = "https://github.com/opencv/opencv/archive/refs/tags/4.8.0.tar.gz",
strip_prefix = "opencv-4.8.0",
)
这是我在thirdparty
目录下的BUILD.bazel文件:
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cmake(
name = "libopencv",
generate_args = [
"-DBUILD_LIST=core,highgui,imgcodecs,imgproc",
"-DBUILD_ZLIB=OFF",
],
lib_source = "@opencv//:all_srcs",
)
filegroup(
name = "opencv",
srcs = [":libopencv"],
visibility = ["//visibility:public"],
)
我得到的错误是:
bazel build --explain=opencv.log --verbose_explanations //thirdparty:opencv
INFO: Analyzed target //thirdparty:opencv (49 packages loaded, 15164 targets configured).
INFO: Found 1 target...
INFO: Writing explanation of rebuilds to 'opencv.log'
ERROR: /Users/name/Code/Git/AimTracker/C/thirdparty/BUILD.bazel:2:6: output 'thirdparty/libopencv/lib/libopencv.a' was not created
ERROR: /Users/name/Code/Git/AimTracker/C/thirdparty/BUILD.bazel:2:6: Foreign Cc - CMake: Building libopencv failed: not all outputs were created or valid
Target //thirdparty:opencv failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 292.206s, Critical Path: 290.73s
INFO: 7 processes: 5 internal, 2 darwin-sandbox.
FAILED: Build did NOT complete successfully
如果我克隆OpenCV,运行以下命令:
cmake -DBUILD_ZLIB=OFF -DBUILD_LIST=core,highgui,imgcodecs,imgproc ..
make
它可以顺利编译。
更新
对于Mac,我按照下面的答案进行了一些更新:
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cc_library(
name = "opencv_deps",
linkopts = [
"-ldl",
"-lz",
"-lpthread",
"-lavutil",
"-lavformat",
"-lavcodec",
"-lswscale",
"-L/opt/homebrew/opt/ffmpeg/lib",
"-L/opt/homebrew/Cellar/libx11/1.8.6/lib",
"-framework Cocoa",
"-framework Accelerate",
],
)
cmake(
name = "opencv",
build_args = [
"-j16",
],
cache_entries = {
"OPENCV_FORCE_3RDPARTY_BUILD": "ON",
"BUILD_SHARED_LIBS": "OFF",
"BUILD_TESTS": "OFF",
"BUILD_PERF_TESTS": "OFF",
"BUILD_opencv_apps": "OFF",
"BUILD_opencv_calib3d": "OFF",
"BUILD_opencv_core": "ON",
"BUILD_opencv_dnn": "OFF",
"BUILD_opencv_features2d": "OFF",
"BUILD_opencv_flann": "OFF",
"BUILD_opencv_gapi": "OFF",
"BUILD_opencv_highgui": "ON",
"BUILD_opencv_imgcodecs": "ON",
"BUILD_opencv_imgproc": "ON",
"BUILD_opencv_java_bindings_generator": "OFF",
"BUILD_opencv_js": "OFF",
"BUILD_opencv_ml": "OFF",
"BUILD_opencv_objdetect": "OFF",
"BUILD_opencv_photo": "OFF",
"BUILD_opencv_python_bindings_generator": "OFF",
"BUILD_opencv_stitching": "OFF",
"BUILD_opencv_ts": "OFF",
"BUILD_opencv_video": "OFF",
"BUILD_opencv_videoio": "ON",
"BUILD_opencv_world": "ON",
"BUILD_IPP_IW": "ON",
"WITH_ADE": "OFF",
"WITH_CAROTENE": "OFF",
"WITH_IPP": "OFF",
"WITH_ITT": "ON",
"WITH_OPENEXR": "OFF",
"WITH_JASPER": "OFF",
"WITH_JPEG": "OFF",
"WITH_OPENJPEG": "ON",
"WITH_TIFF": "OFF",
"WITH_WEBP": "ON",
"WITH_QUIRC": "ON",
"WITH_GTK": "OFF",
"WITH_OPENBLAS": "ON",
"WITH_OPENCL": "OFF",
},
env = {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_BUILD_PARALLEL_LEVEL": "16",
},
lib_source = "@opencv//:all",
out_include_dir = "include/opencv4",
out_static_libs = [
"libopencv_world.a",
"opencv4/3rdparty/libittnotify.a",
"opencv4/3rdparty/liblibopenjp2.a",
"opencv4/3rdparty/liblibwebp.a",
"opencv4/3rdparty/liblibpng.a",
],
targets = [
"install",
],
visibility = ["//visibility:public"],
deps = [":opencv_deps"],
)
英文:
I want to start a new project in C++ with Bazel. To build OpenCV I want to use foreign_rules_cc.
I have followed some tutorials, but I have not been able to build opencv successfully.
This is my WORKSPACE:
workspace(name = "rules_foreign_cc_usage_example")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Rule repository, note that it's recommended to use a pinned commit to a released version of the rules
http_archive(
name = "rules_foreign_cc",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
# This sets up some common toolchains for building targets. For more details, please see
# https://github.com/bazelbuild/rules_foreign_cc/tree/main/docs#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()
_OPENCV_CONTENT = """\
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""
http_archive(
name = "opencv",
build_file_content = _OPENCV_CONTENT,
url = "https://github.com/opencv/opencv/archive/refs/tags/4.8.0.tar.gz",
strip_prefix = "opencv-4.8.0",
)
This is my BUILD.bazel in the directory thirdparty
:
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cmake(
name = "libopencv",
generate_args = [
"-DBUILD_LIST=core,highgui,imgcodecs,imgproc",
"-DBUILD_ZLIB=OFF",
],
lib_source = "@opencv//:all_srcs",
)
filegroup(
name = "opencv",
srcs = [":libopencv"],
visibility = ["//visibility:public"],
)
The error I get is
bazel build --explain=opencv.log --verbose_explanations //thirdparty:opencv
INFO: Analyzed target //thirdparty:opencv (49 packages loaded, 15164 targets configured).
INFO: Found 1 target...
INFO: Writing explanation of rebuilds to 'opencv.log'
ERROR: /Users/name/Code/Git/AimTracker/C/thirdparty/BUILD.bazel:2:6: output 'thirdparty/libopencv/lib/libopencv.a' was not created
ERROR: /Users/name/Code/Git/AimTracker/C/thirdparty/BUILD.bazel:2:6: Foreign Cc - CMake: Building libopencv failed: not all outputs were created or valid
Target //thirdparty:opencv failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 292.206s, Critical Path: 290.73s
INFO: 7 processes: 5 internal, 2 darwin-sandbox.
FAILED: Build did NOT complete successfully
If I clone OpenCV, run
cmake -DBUILD_ZLIB=OFF -DBUILD_LIST=core,highgui,imgcodecs,imgproc ..
make
it compiles without any problems.
UPDATE
For Mac I followed the accepted answer below with some updates:
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cc_library(
name = "opencv_deps",
linkopts = [
"-ldl",
"-lz",
"-lpthread",
"-lavutil",
"-lavformat",
"-lavcodec",
"-lswscale",
"-L/opt/homebrew/opt/ffmpeg/lib",
"-L/opt/homebrew/Cellar/libx11/1.8.6/lib",
"-framework Cocoa",
"-framework Accelerate",
],
)
cmake(
name = "opencv",
build_args = [
"-j16",
],
cache_entries = {
"OPENCV_FORCE_3RDPARTY_BUILD": "ON",
"BUILD_SHARED_LIBS": "OFF",
"BUILD_TESTS": "OFF",
"BUILD_PERF_TESTS": "OFF",
"BUILD_opencv_apps": "OFF",
"BUILD_opencv_calib3d": "OFF",
"BUILD_opencv_core": "ON",
"BUILD_opencv_dnn": "OFF",
"BUILD_opencv_features2d": "OFF",
"BUILD_opencv_flann": "OFF",
"BUILD_opencv_gapi": "OFF",
"BUILD_opencv_highgui": "ON",
"BUILD_opencv_imgcodecs": "ON",
"BUILD_opencv_imgproc": "ON",
"BUILD_opencv_java_bindings_generator": "OFF",
"BUILD_opencv_js": "OFF",
"BUILD_opencv_ml": "OFF",
"BUILD_opencv_objdetect": "OFF",
"BUILD_opencv_photo": "OFF",
"BUILD_opencv_python_bindings_generator": "OFF",
"BUILD_opencv_stitching": "OFF",
"BUILD_opencv_ts": "OFF",
"BUILD_opencv_video": "OFF",
"BUILD_opencv_videoio": "ON",
"BUILD_opencv_world": "ON",
"BUILD_IPP_IW": "ON",
"WITH_ADE": "OFF",
"WITH_CAROTENE": "OFF",
"WITH_IPP": "OFF",
"WITH_ITT": "ON",
"WITH_OPENEXR": "OFF",
"WITH_JASPER": "OFF",
"WITH_JPEG": "OFF",
"WITH_OPENJPEG": "ON",
"WITH_TIFF": "OFF",
"WITH_WEBP": "ON",
"WITH_QUIRC": "ON",
"WITH_GTK": "OFF",
"WITH_OPENBLAS": "ON",
"WITH_OPENCL": "OFF",
},
env = {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_BUILD_PARALLEL_LEVEL": "16",
},
lib_source = "@opencv//:all",
out_include_dir = "include/opencv4",
out_static_libs = [
"libopencv_world.a",
"opencv4/3rdparty/libittnotify.a",
"opencv4/3rdparty/liblibopenjp2.a",
"opencv4/3rdparty/liblibwebp.a",
"opencv4/3rdparty/liblibpng.a",
],
targets = [
"install",
],
visibility = ["//visibility:public"],
deps = [":opencv_deps"],
)
答案1
得分: 1
另一种方法是不使用rules_foreign_cc
。这在我以前使用Windows上的Visual Studio时对我有效:
WORKSPACE.bazel:
workspace(name = "OpenCVDemo")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# OpenCV
http_archive(
name = "opencv",
build_file = "//third_party:opencv.BUILD",
strip_prefix = "opencv/build",
# Debug
#url = "http://vertexwahn.de/artifacts/opencv-4.3.0-dldt-2020.2-vc16-avx2-debug.zip",
#sha256 = "9bcd2dda258e67ad2ddef7768f1c9b2afcc68cd4b9d9f5c9b841ea3ee47f9d4c",
# Release
url = "https://github.com/opencv/opencv/releases/download/4.3.0/opencv-4.3.0-dldt-2020.2-vc16-avx2.zip",
)
third_party/opencv.BUILD:
package(default_visibility = ["//visibility:public"])
MAIN_MODULES = [
"core",
"imgproc",
"imgcodecs",
"videoio",
"highgui",
"video",
"calib3d",
"features2d",
"objdetect",
"dnn",
"ml",
"flann",
"photo",
"stitching",
"gapi",
]
# https://stackoverflow.com/questions/56108940/how-to-specify-the-compiler-flags-to-be-used-in-opt-compilation-mode-by-my-own
config_setting(
name = "fastbuild_mode",
values = {"compilation_mode": "fastbuild"},
)
config_setting(
name = "dbg_mode",
values = {"compilation_mode": "dbg"},
)
cc_import(
name = "tbb",
shared_library = select({
":fastbuild_mode": "bin/tbb.dll",
":dbg_mode": "bin/tbb_debug.dll",
"//conditions:default": "bin/tbb.dll",
}),
)
[
(
cc_import(
name = module,
interface_library = select({
":fastbuild_mode": "lib/opencv_{}430.lib".format(module),
":dbg_mode": "lib/opencv_{}430d.lib".format(module),
"//conditions:default": "lib/opencv_{}430.lib".format(module),
}),
shared_library = select({
":fastbuild_mode": "bin/opencv_{}430.dll".format(module),
":dbg_mode": "bin/opencv_{}430d.dll".format(module),
"//conditions:default": "bin/opencv_{}430.dll".format(module),
}),
)
)
for module in MAIN_MODULES
]
cc_library(
name = "opencv",
hdrs = [
"include/opencv2/calib3d.hpp",
"include/opencv2/calib3d/calib3d.hpp",
"include/opencv2/calib3d/calib3d_c.h",
"include/opencv2/core.hpp",
"include/opencv2/core/hal/interface.h",
"include/opencv2/cvconfig.h",
"include/opencv2/dnn.hpp",
"include/opencv2/features2d.hpp",
"include/opencv2/flann.hpp",
"include/opencv2/flann/config.h",
"include/opencv2/flann/defines.h",
"include/opencv2/flann/miniflann.hpp",
"include/opencv2/highgui.hpp",
"include/opencv2/highgui/highgui.hpp",
"include/opencv2/highgui/highgui_c.h",
"include/opencv2/imgcodecs.hpp",
"include/opencv2/imgproc.hpp",
"include/opencv2/ml.hpp",
"include/opencv2/ml/ml.inl.hpp",
"include/opencv2/objdetect.hpp",
"include/opencv2/opencv.hpp",
"include/opencv2/opencv_modules.hpp",
"include/opencv2/photo.hpp",
"include/opencv2/stitching.hpp",
"include/opencv2/video.hpp",
"include/opencv2/video/background_segm.hpp",
"include/opencv2/video/tracking.hpp",
"include/opencv2/videoio.hpp",
"include/opencv2/videoio/videoio_c.h",
],
includes = ["include"],
deps = MAIN_MODULES + [
"tbb",
],
)
third_party/BUILD.bazel:
# empty by intend
BUILD.bazel:
cc_binary(
name = "OpenCVDemo",
srcs = ["main.cpp"],
deps = ["@opencv"],
)
英文:
One another approach is not to use rules_foreign_cc
. This worked for me in the past with Visual Studio on Windows:
WORKSPACE.bazel:
workspace(name = "OpenCVDemo")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# OpenCV
http_archive(
name = "opencv",
build_file = "//third_party:opencv.BUILD",
strip_prefix = "opencv/build",
# Debug
#url = "http://vertexwahn.de/artifacts/opencv-4.3.0-dldt-2020.2-vc16-avx2-debug.zip",
#sha256 = "9bcd2dda258e67ad2ddef7768f1c9b2afcc68cd4b9d9f5c9b841ea3ee47f9d4c",
# Release
url = "https://github.com/opencv/opencv/releases/download/4.3.0/opencv-4.3.0-dldt-2020.2-vc16-avx2.zip",
)
third_party/opencv.BUILD:
package(default_visibility = ["//visibility:public"])
MAIN_MODULES = [
"core",
"imgproc",
"imgcodecs",
"videoio",
"highgui",
"video",
"calib3d",
"features2d",
"objdetect",
"dnn",
"ml",
"flann",
"photo",
"stitching",
"gapi",
]
# https://stackoverflow.com/questions/56108940/how-to-specify-the-compiler-flags-to-be-used-in-opt-compilation-mode-by-my-own
config_setting(
name = "fastbuild_mode",
values = {"compilation_mode": "fastbuild"},
)
config_setting(
name = "dbg_mode",
values = {"compilation_mode": "dbg"},
)
cc_import(
name = "tbb",
shared_library = select({
":fastbuild_mode": "bin/tbb.dll",
":dbg_mode": "bin/tbb_debug.dll",
"//conditions:default": "bin/tbb.dll",
}),
)
[
(
cc_import(
name = module,
interface_library = select({
":fastbuild_mode": "lib/opencv_{}430.lib".format(module),
":dbg_mode": "lib/opencv_{}430d.lib".format(module),
"//conditions:default": "lib/opencv_{}430.lib".format(module),
}),
shared_library = select({
":fastbuild_mode": "bin/opencv_{}430.dll".format(module),
":dbg_mode": "bin/opencv_{}430d.dll".format(module),
"//conditions:default": "bin/opencv_{}430.dll".format(module),
}),
)
)
for module in MAIN_MODULES
]
cc_library(
name = "opencv",
hdrs = [
"include/opencv2/calib3d.hpp",
"include/opencv2/calib3d/calib3d.hpp",
"include/opencv2/calib3d/calib3d_c.h",
"include/opencv2/core.hpp",
"include/opencv2/core/hal/interface.h",
"include/opencv2/cvconfig.h",
"include/opencv2/dnn.hpp",
"include/opencv2/features2d.hpp",
"include/opencv2/flann.hpp",
"include/opencv2/flann/config.h",
"include/opencv2/flann/defines.h",
"include/opencv2/flann/miniflann.hpp",
"include/opencv2/highgui.hpp",
"include/opencv2/highgui/highgui.hpp",
"include/opencv2/highgui/highgui_c.h",
"include/opencv2/imgcodecs.hpp",
"include/opencv2/imgproc.hpp",
"include/opencv2/ml.hpp",
"include/opencv2/ml/ml.inl.hpp",
"include/opencv2/objdetect.hpp",
"include/opencv2/opencv.hpp",
"include/opencv2/opencv_modules.hpp",
"include/opencv2/photo.hpp",
"include/opencv2/stitching.hpp",
"include/opencv2/video.hpp",
"include/opencv2/video/background_segm.hpp",
"include/opencv2/video/tracking.hpp",
"include/opencv2/videoio.hpp",
"include/opencv2/videoio/videoio_c.h",
],
includes = ["include"],
deps = MAIN_MODULES + [
"tbb",
],
)
third_party/BUILD.bazel
# empty by intend
BUILD.bazel:
cc_binary(
name = "OpenCVDemo",
srcs = ["main.cpp"],
deps = ["@opencv"],
)
答案2
得分: 0
这是一个在Ubuntu 22.04上工作的BUILD文件示例(至少对我而言)。
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cc_library(
name = "opencv_deps",
linkopts = [
"-ldl",
"-lz",
"-lpthread",
"-ldc1394",
"-lavutil",
"-lavformat",
"-lavcodec",
"-lswscale",
],
)
cmake(
name = "opencv",
build_args = [
"-j16",
],
cache_entries = {
"OPENCV_FORCE_3RDPARTY_BUILD": "ON",
"BUILD_SHARED_LIBS": "OFF",
"BUILD_TESTS": "OFF",
"BUILD_PERF_TESTS": "OFF",
"BUILD_opencv_apps": "OFF",
"BUILD_opencv_calib3d": "OFF",
"BUILD_opencv_core": "ON",
"BUILD_opencv_dnn": "OFF",
"BUILD_opencv_features2d": "OFF",
"BUILD_opencv_flann": "OFF",
"BUILD_opencv_gapi": "OFF",
"BUILD_opencv_highgui": "ON",
"BUILD_opencv_imgcodecs": "ON",
"BUILD_opencv_imgproc": "ON",
"BUILD_opencv_java_bindings_generator": "OFF",
"BUILD_opencv_js": "OFF",
"BUILD_opencv_ml": "OFF",
"BUILD_opencv_objdetect": "OFF",
"BUILD_opencv_photo": "OFF",
"BUILD_opencv_python_bindings_generator": "OFF",
"BUILD_opencv_stitching": "OFF",
"BUILD_opencv_ts": "OFF",
"BUILD_opencv_video": "OFF",
"BUILD_opencv_videoio": "ON",
"BUILD_opencv_world": "ON",
"BUILD_IPP_IW": "ON",
"WITH_ADE": "OFF",
"WITH_CAROTENE": "OFF",
"WITH_IPP": "OFF",
"WITH_ITT": "ON",
"WITH_OPENEXR": "OFF",
"WITH_JASPER": "OFF",
"WITH_JPEG": "OFF",
"WITH_OPENJPEG": "ON",
"WITH_TIFF": "OFF",
"WITH_WEBP": "ON",
"WITH_QUIRC": "ON",
"WITH_GTK": "OFF",
},
env = {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_BUILD_PARALLEL_LEVEL": "16",
},
lib_source = "@opencv//:all",
out_include_dir = "include/opencv4",
out_static_libs = [
"libopencv_world.a",
"opencv4/3rdparty/libittnotify.a",
"opencv4/3rdparty/liblibopenjp2.a",
"opencv4/3rdparty/liblibwebp.a",
"opencv4/3rdparty/liblibpng.a",
],
targets = [
"install",
],
visibility = ["//visibility:public"],
deps = [":opencv_deps"],
)
WORKSPACE代码片段:
all_content = """filegroup(
name = "all",
srcs = glob(["**"]),
visibility = ["//visibility:public"]
)
"""
http_archive(
name = "rules_foreign_cc",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
http_archive(
name = "opencv",
build_file_content = all_content,
sha256 = "a61e7a4618d353140c857f25843f39b2abe5f451b018aab1604ef0bc34cd23d5",
strip_prefix = "opencv-4.5.3",
urls = [
"https://github.com/opencv/opencv/archive/4.5.3.zip",
],
)
希望对你有所帮助!
英文:
Here is my BUILD file that works (at least for me) with ubuntu 22.04.
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cc_library(
name = "opencv_deps",
linkopts = [
"-ldl",
"-lz",
"-lpthread",
"-ldc1394",
"-lavutil",
"-lavformat",
"-lavcodec",
"-lswscale",
],
)
cmake(
name = "opencv",
build_args = [
"-j16",
],
cache_entries = {
"OPENCV_FORCE_3RDPARTY_BUILD": "ON",
"BUILD_SHARED_LIBS": "OFF",
"BUILD_TESTS": "OFF",
"BUILD_PERF_TESTS": "OFF",
"BUILD_opencv_apps": "OFF",
"BUILD_opencv_calib3d": "OFF",
"BUILD_opencv_core": "ON",
"BUILD_opencv_dnn": "OFF",
"BUILD_opencv_features2d": "OFF",
"BUILD_opencv_flann": "OFF",
"BUILD_opencv_gapi": "OFF",
"BUILD_opencv_highgui": "ON",
"BUILD_opencv_imgcodecs": "ON",
"BUILD_opencv_imgproc": "ON",
"BUILD_opencv_java_bindings_generator": "OFF",
"BUILD_opencv_js": "OFF",
"BUILD_opencv_ml": "OFF",
"BUILD_opencv_objdetect": "OFF",
"BUILD_opencv_photo": "OFF",
"BUILD_opencv_python_bindings_generator": "OFF",
"BUILD_opencv_stitching": "OFF",
"BUILD_opencv_ts": "OFF",
"BUILD_opencv_video": "OFF",
"BUILD_opencv_videoio": "ON",
"BUILD_opencv_world": "ON",
"BUILD_IPP_IW": "ON",
"WITH_ADE": "OFF",
"WITH_CAROTENE": "OFF",
"WITH_IPP": "OFF",
"WITH_ITT": "ON",
"WITH_OPENEXR": "OFF",
"WITH_JASPER": "OFF",
"WITH_JPEG": "OFF",
"WITH_OPENJPEG": "ON",
"WITH_TIFF": "OFF",
"WITH_WEBP": "ON",
"WITH_QUIRC": "ON",
"WITH_GTK": "OFF",
},
env = {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_BUILD_PARALLEL_LEVEL": "16",
},
lib_source = "@opencv//:all",
out_include_dir = "include/opencv4",
out_static_libs = [
"libopencv_world.a",
"opencv4/3rdparty/libittnotify.a",
"opencv4/3rdparty/liblibopenjp2.a",
"opencv4/3rdparty/liblibwebp.a",
"opencv4/3rdparty/liblibpng.a",
],
targets = [
"install",
],
visibility = ["//visibility:public"],
deps = [":opencv_deps"],
)
WORKSPACE snippet:
all_content = """filegroup(
name = "all",
srcs = glob(["**"]),
visibility = ["//visibility:public"]
)
"""
http_archive(
name = "rules_foreign_cc",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
http_archive(
name = "opencv",
build_file_content = all_content,
sha256 = "a61e7a4618d353140c857f25843f39b2abe5f451b018aab1604ef0bc34cd23d5",
strip_prefix = "opencv-4.5.3",
urls = [
"https://github.com/opencv/opencv/archive/4.5.3.zip",
],
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论