homebrew-core/Formula/opencv@3.rb

113 lines
3.5 KiB
Ruby

class OpencvAT3 < Formula
desc "Open source computer vision library"
homepage "https://opencv.org/"
url "https://github.com/opencv/opencv/archive/3.4.12.tar.gz"
sha256 "c8919dfb5ead6be67534bf794cb0925534311f1cd5c6680f8164ad1813c88d13"
license "BSD-3-Clause"
revision 3
bottle do
sha256 "640ea516919445ee6d370678986093de9b7f3b27b756d76a0904687f94cec8c5" => :big_sur
sha256 "00b159415bc4ec16ed27f06f88fe5cb1db66f8a870d6564a7782d1ec56a6e672" => :catalina
sha256 "ffe594a6c6dfef0cc14dd61b21e3160e230b779abc45007d1e41a0ff4fe33861" => :mojave
sha256 "5be7afd889d93bc4c326d39701a8edd864d847a01528d0222868896efd2d1101" => :high_sierra
end
keg_only :versioned_formula
depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on "ceres-solver"
depends_on "eigen"
depends_on "ffmpeg"
depends_on "gflags"
depends_on "glog"
depends_on "jpeg"
depends_on "libpng"
depends_on "libtiff"
depends_on "numpy"
depends_on "openexr"
depends_on "python@3.9"
depends_on "tbb"
resource "contrib" do
url "https://github.com/opencv/opencv_contrib/archive/3.4.12.tar.gz"
sha256 "b207024589674dd2efc7c25740ef192ee4f3e0783e773e2d49a198c37e3e7570"
end
def install
ENV.cxx11
resource("contrib").stage buildpath/"opencv_contrib"
# Reset PYTHONPATH, workaround for https://github.com/Homebrew/homebrew-science/pull/4885
ENV.delete("PYTHONPATH")
args = std_cmake_args + %W[
-DCMAKE_OSX_DEPLOYMENT_TARGET=
-DBUILD_JASPER=OFF
-DBUILD_JPEG=ON
-DBUILD_OPENEXR=OFF
-DBUILD_PERF_TESTS=OFF
-DBUILD_PNG=OFF
-DBUILD_TESTS=OFF
-DBUILD_TIFF=OFF
-DBUILD_ZLIB=OFF
-DBUILD_opencv_hdf=OFF
-DBUILD_opencv_java=OFF
-DBUILD_opencv_text=OFF
-DOPENCV_ENABLE_NONFREE=ON
-DOPENCV_EXTRA_MODULES_PATH=#{buildpath}/opencv_contrib/modules
-DWITH_1394=OFF
-DWITH_CUDA=OFF
-DWITH_EIGEN=ON
-DWITH_FFMPEG=ON
-DWITH_GPHOTO2=OFF
-DWITH_GSTREAMER=OFF
-DWITH_JASPER=OFF
-DWITH_OPENEXR=ON
-DWITH_OPENGL=OFF
-DWITH_QT=OFF
-DWITH_TBB=ON
-DWITH_VTK=OFF
-DBUILD_opencv_python2=OFF
-DBUILD_opencv_python3=ON
-DPYTHON3_EXECUTABLE=#{Formula["python@3.9"].opt_bin}/python3
]
args << "-DENABLE_AVX=OFF" << "-DENABLE_AVX2=OFF"
args << "-DENABLE_SSE41=OFF" << "-DENABLE_SSE42=OFF" unless MacOS.version.requires_sse42?
mkdir "build" do
system "cmake", "..", *args
inreplace "modules/core/version_string.inc", "#{HOMEBREW_SHIMS_PATH}/mac/super/", ""
system "make"
system "make", "install"
system "make", "clean"
system "cmake", "..", "-DBUILD_SHARED_LIBS=OFF", *args
inreplace "modules/core/version_string.inc", "#{HOMEBREW_SHIMS_PATH}/mac/super/", ""
system "make"
lib.install Dir["lib/*.a"]
lib.install Dir["3rdparty/**/*.a"]
end
end
test do
(testpath/"test.cpp").write <<~EOS
#include <opencv/cv.h>
#include <iostream>
int main() {
std::cout << CV_VERSION << std::endl;
return 0;
}
EOS
system ENV.cxx, "test.cpp", "-I#{include}", "-L#{lib}", "-o", "test"
assert_equal `./test`.strip, version.to_s
py3_version = Language::Python.major_minor_version Formula["python@3.9"].opt_bin/"python3"
ENV["PYTHONPATH"] = lib/"python#{py3_version}/site-packages"
output = shell_output(Formula["python@3.9"].opt_bin/"python3 -c 'import cv2; print(cv2.__version__)'")
assert_equal version.to_s, output.chomp
end
end