-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opencv-maa: a minimal OpenCV build for MAA
- Loading branch information
Showing
4 changed files
with
114 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
class OpencvMaa < Formula | ||
desc "Minimal OpenCV build use by MAA" | ||
homepage "https://opencv.org/" | ||
url "https://github.com/opencv/opencv/archive/refs/tags/4.9.0.tar.gz" | ||
sha256 "ddf76f9dffd322c7c3cb1f721d0887f62d747b82059342213138dc190f28bc6c" | ||
license "Apache-2.0" | ||
|
||
livecheck do | ||
url :stable | ||
regex(/^v?(\d+(?:\.\d+)+)$/i) | ||
end | ||
|
||
depends_on "cmake" => :build | ||
depends_on "eigen" => :build | ||
|
||
depends_on "jpeg-turbo" | ||
depends_on "libpng" | ||
|
||
uses_from_macos "zlib" | ||
|
||
on_linux do | ||
depends_on "ffmpeg@6" | ||
end | ||
|
||
conflicts_with "opencv", { because: "this is a minimal build of OpenCV" } | ||
|
||
def install | ||
# Remove bundled libraries to make sure formula dependencies are used | ||
libdirs = %w[ffmpeg libjasper libjpeg libjpeg-turbo libpng libtiff libwebp openexr openjpeg protobuf tbb zlib] | ||
libdirs.each { |l| (buildpath/"3rdparty"/l).rmtree } | ||
|
||
cmake_args = %W[ | ||
-DCMAKE_CXX_STANDARD=17 | ||
|
||
-DBUILD_LIST=core,imgproc,imgcodecs,videoio | ||
|
||
-DBUILD_ZLIB=OFF | ||
|
||
-DWITH_EIGEN=ON | ||
|
||
-DWITH_PNG=ON | ||
-DBUILD_PNG=OFF | ||
-DWITH_JPEG=ON | ||
-DBUILD_JPEG=OFF | ||
-DWITH_TIFF=OFF | ||
-DWITH_WEBP=OFF | ||
-DWITH_OPENJPEG=OFF | ||
-DWITH_JASPER=OFF | ||
-DWITH_OPENEXR=OFF | ||
|
||
-DWITH_FFMPEG=#{OS.linux? ? "ON" : "OFF"} | ||
-DWITH_V4L=OFF | ||
-DWITH_GSTREAMER=OFF | ||
-DWITH_DSHOW=OFF | ||
-DWITH_1394=OFF | ||
|
||
-DWITH_CUDA=OFF | ||
|
||
-DWITH_PROTOBUF=OFF | ||
-DBUILD_opencv_python3=OFF | ||
] | ||
|
||
# HACK: avoid opencv install data | ||
cmake_args << "-DOPENCV_OTHER_INSTALL_PATH=#{buildpath}/tmp" | ||
|
||
if OS.linux? | ||
cmake_args += %W[ | ||
-DPNG_LIBRARY=#{Formula["libpng"].opt_lib}/libpng.so | ||
-DJPEG_LIBRARY=#{Formula["jpeg-turbo"].opt_lib}/libjpeg.so | ||
-DZLIB_LIBRARY=#{Formula["zlib"].opt_lib}/libz.so | ||
] | ||
end | ||
|
||
system "cmake", "-S", ".", "-B", "build", *cmake_args, *std_cmake_args | ||
inreplace "build/modules/core/version_string.inc", "#{Superenv.shims_path}/", "" | ||
system "cmake", "--build", "build" | ||
system "cmake", "--install", "build" | ||
end | ||
|
||
test do | ||
(testpath/"test.cpp").write <<~EOS | ||
#include <opencv2/opencv.hpp> | ||
#include <iostream> | ||
int main() { | ||
std::cout << CV_VERSION << std::endl; | ||
return 0; | ||
} | ||
EOS | ||
system ENV.cxx, "-std=c++17", "test.cpp", "-I#{include}/opencv4", "-o", "test" | ||
assert_equal shell_output("./test").strip, version.to_s | ||
end | ||
end |