homebrew-core/Formula/opencv@3.rb
2020-01-06 10:42:56 +01:00

116 lines
3.4 KiB
Ruby

class OpencvAT3 < Formula
desc "Open source computer vision library"
homepage "https://opencv.org/"
url "https://github.com/opencv/opencv/archive/3.4.9.tar.gz"
sha256 "b7ea364de7273cfb3b771a0d9c111b8b8dfb42ff2bcd2d84681902fb8f49892a"
revision 1
bottle do
sha256 "b9e5b2d37a4b1119cb2da96b784531828aef199ea0cdf4aefb78f3fbdefac240" => :catalina
sha256 "d25380e270576b4cff574a27e5942699c7817e9550c5866db3bdda4ca7641642" => :mojave
sha256 "6ddb7df678e7f5999d154ca1f132d3eda56f23f4b0908971ac2a6fc63b7708d8" => :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"
depends_on "tbb"
resource "contrib" do
url "https://github.com/opencv/opencv_contrib/archive/3.4.9.tar.gz"
sha256 "dc7d95be6aaccd72490243efcec31e2c7d3f21125f88286186862cf9edb14a57"
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")
py3_config = `python3-config --configdir`.chomp
py3_include = `python3 -c "import distutils.sysconfig as s; print(s.get_python_inc())"`.chomp
py3_version = Language::Python.major_minor_version "python3"
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=#{which "python3"}
-DPYTHON3_LIBRARY=#{py3_config}/libpython#{py3_version}.dylib
-DPYTHON3_INCLUDE_DIR=#{py3_include}
]
args << "-DENABLE_AVX=OFF" << "-DENABLE_AVX2=OFF"
unless MacOS.version.requires_sse42?
args << "-DENABLE_SSE41=OFF" << "-DENABLE_SSE42=OFF"
end
mkdir "build" do
system "cmake", "..", *args
system "make"
system "make", "install"
system "make", "clean"
system "cmake", "..", "-DBUILD_SHARED_LIBS=OFF", *args
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 "python3"
ENV["PYTHONPATH"] = lib/"python#{py3_version}/site-packages"
output = shell_output("python3 -c 'import cv2; print(cv2.__version__)'")
assert_equal version.to_s, output.chomp
end
end