121 lines
3.7 KiB
Ruby
121 lines
3.7 KiB
Ruby
class Opencv < Formula
|
|
desc "Open source computer vision library"
|
|
homepage "https://opencv.org/"
|
|
url "https://github.com/opencv/opencv/archive/4.1.2.tar.gz"
|
|
sha256 "385dd0a9c25e67ef0dd60e022d2a2d7b17e2f36819cf3cb46aa8cdff5c5282c9"
|
|
|
|
bottle do
|
|
sha256 "d892df18b3be262f8f962877a76220ebcdf21adf1b21dbe64a670e1b1f98d271" => :catalina
|
|
sha256 "01f952520f550540a56a7a40d9bbc1e66cfd56c7a879d4feb89b8d146cea3b83" => :mojave
|
|
sha256 "8b549dba222f61f7893a6aedae9ecfde78aa654479023ba600eebd72567076c2" => :high_sierra
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "pkg-config" => :build
|
|
depends_on "ceres-solver"
|
|
depends_on "eigen"
|
|
depends_on "ffmpeg"
|
|
depends_on "glog"
|
|
depends_on "harfbuzz"
|
|
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/4.1.1.tar.gz"
|
|
sha256 "9f85d380758498d800fec26307e389620cde8b1a2e86ab51cddc5200fbe37102"
|
|
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=ON
|
|
-DOPENCV_ENABLE_NONFREE=ON
|
|
-DOPENCV_EXTRA_MODULES_PATH=#{buildpath}/opencv_contrib/modules
|
|
-DOPENCV_GENERATE_PKGCONFIG=ON
|
|
-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}
|
|
]
|
|
|
|
# The compiler on older Mac OS cannot build some OpenCV files using AVX2
|
|
# extensions, failing with errors such as
|
|
# "error: use of undeclared identifier '_mm256_cvtps_ph'"
|
|
# Work around this by not trying to build AVX2 code.
|
|
if MacOS.version <= :yosemite
|
|
args << "-DCPU_DISPATCH=SSE4_1,SSE4_2,AVX"
|
|
end
|
|
|
|
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 <opencv2/opencv.hpp>
|
|
#include <iostream>
|
|
int main() {
|
|
std::cout << CV_VERSION << std::endl;
|
|
return 0;
|
|
}
|
|
EOS
|
|
system ENV.cxx, "-std=c++11", "test.cpp", "-I#{include}/opencv4",
|
|
"-o", "test"
|
|
assert_equal `./test`.strip, version.to_s
|
|
|
|
output = shell_output("python3 -c 'import cv2; print(cv2.__version__)'")
|
|
assert_equal version.to_s, output.chomp
|
|
end
|
|
end
|