-
-
Save jacobo/f0211e5684e65d2db9957ca04dc20086 to your computer and use it in GitHub Desktop.
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
class Opencv < Formula | |
desc "Open source computer vision library" | |
homepage "http://opencv.org/" | |
url "https://github.com/opencv/opencv/archive/2.4.13.2.tar.gz" | |
sha256 "4b00c110e6c54943cbbb7cf0d35c5bc148133ab2095ee4aaa0ac0a4f67c58080" | |
revision 2 | |
bottle do | |
sha256 "db402b1fbfc0ae68dd024fc78f63ad4232a64300a8c40b32cb39668d1c8637b2" => :high_sierra | |
sha256 "53cfcc3c43d671f32a7723e369c3501d65218f4084d9d2fa633671cf14c8381b" => :sierra | |
sha256 "2e52fa5d66acd5ab9c676d9444d9939659fdd9e2e15d7d196a842f2b6102e9c6" => :el_capitan | |
sha256 "c51746b88173a1ca76d231e5679675bf40f26b5fe89ec1d15ce9d302c460b26f" => :yosemite | |
end | |
keg_only :versioned_formula | |
option "without-python", "Build without python2 support" | |
depends_on "cmake" => :build | |
depends_on "pkg-config" => :build | |
depends_on "eigen" | |
depends_on "jpeg" | |
depends_on "libpng" | |
depends_on "libtiff" | |
depends_on "openexr" | |
depends_on :python => :recommended if MacOS.version <= :snow_leopard | |
depends_on "numpy" if build.with? "python" | |
def install | |
jpeg = Formula["jpeg"] | |
args = std_cmake_args + %W[ | |
-DCMAKE_OSX_DEPLOYMENT_TARGET= | |
-DBUILD_JASPER=OFF | |
-DBUILD_JPEG=OFF | |
-DBUILD_OPENEXR=OFF | |
-DBUILD_PERF_TESTS=OFF | |
-DBUILD_PNG=OFF | |
-DBUILD_TESTS=OFF | |
-DBUILD_TIFF=OFF | |
-DBUILD_ZLIB=OFF | |
-DBUILD_opencv_java=OFF | |
-DWITH_CUDA=OFF | |
-DWITH_EIGEN=ON | |
-DWITH_FFMPEG=ON | |
-DWITH_GSTREAMER=OFF | |
-DWITH_JASPER=OFF | |
-DWITH_OPENEXR=ON | |
-DWITH_OPENGL=ON | |
-DWITH_TBB=OFF | |
-DJPEG_INCLUDE_DIR=#{jpeg.opt_include} | |
-DJPEG_LIBRARY=#{jpeg.opt_lib}/libjpeg.dylib | |
] | |
args << "-DBUILD_opencv_python=" + (build.with?("python") ? "ON" : "OFF") | |
if build.with? "python" | |
py_prefix = `python-config --prefix`.chomp | |
py_lib = "#{py_prefix}/lib" | |
args << "-DPYTHON_LIBRARY=#{py_lib}/libpython2.7.dylib" | |
args << "-DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7" | |
# Make sure find_program locates system Python | |
# https://github.com/Homebrew/homebrew-science/issues/2302 | |
args << "-DCMAKE_PREFIX_PATH=#{py_prefix}" | |
end | |
if ENV.compiler == :clang && !build.bottle? | |
args << "-DENABLE_SSSE3=ON" if Hardware::CPU.ssse3? | |
args << "-DENABLE_SSE41=ON" if Hardware::CPU.sse4? | |
args << "-DENABLE_SSE42=ON" if Hardware::CPU.sse4_2? | |
args << "-DENABLE_AVX=ON" if Hardware::CPU.avx? | |
end | |
mkdir "build" do | |
system "cmake", "..", *args | |
system "make" | |
system "make", "install" | |
end | |
end | |
test do | |
(testpath/"test.cpp").write <<-EOS.undent | |
#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 version.to_s, shell_output("./test").strip | |
ENV["PYTHONPATH"] = lib/"python2.7/site-packages" | |
assert_match version.to_s, | |
shell_output("python -c 'import cv2; print(cv2.__version__)'") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment