Skip to content

Instantly share code, notes, and snippets.

@mkassner
Last active December 31, 2015 17:38
Show Gist options
  • Save mkassner/8021192 to your computer and use it in GitHub Desktop.
Save mkassner/8021192 to your computer and use it in GitHub Desktop.
require 'formula'
class Opencv < Formula
homepage 'http://opencv.org/'
url 'https://github.com/mkassner/opencv/archive/2.4.8.2.tar.gz'
sha1 '5a23ad0c587d6a7fe00d79dfdea0199d7c584923'
option '32-bit'
option 'with-qt', 'Build the Qt4 backend to HighGUI'
option 'with-tbb', 'Enable parallel code in OpenCV using Intel TBB'
option 'without-opencl', 'Disable gpu code in OpenCV using OpenCL'
depends_on 'cmake' => :build
depends_on 'pkg-config' => :build
depends_on 'numpy' => :python
depends_on :python
depends_on 'eigen' => :optional
depends_on 'libtiff' => :optional
depends_on 'jasper' => :optional
depends_on 'tbb' => :optional
depends_on 'qt' => :optional
depends_on :libpng
# Can also depend on ffmpeg, but this pulls in a lot of extra stuff that
# you don't need unless you're doing video analysis, and some of it isn't
# in Homebrew anyway. Will depend on openexr if it's installed.
env :std
def patches
#fixes compilation errors if ffmpeg is installed
DATA
end
def install
args = std_cmake_args + %W[
-DCMAKE_OSX_DEPLOYMENT_TARGET=
-DWITH_CUDA=OFF
-DBUILD_ZLIB=OFF
-DBUILD_TIFF=OFF
-DBUILD_PNG=OFF
-DBUILD_JPEG=OFF
-DBUILD_JASPER=OFF
-DBUILD_TESTS=OFF
-DBUILD_PERF_TESTS=OFF
-DPYTHON_INCLUDE_DIR='#{python.incdir}'
-DPYTHON_LIBRARY='#{python.libdir}/lib#{python.xy}.dylib'
-DPYTHON_EXECUTABLE='#{python.binary}'
]
if build.build_32_bit?
args << "-DCMAKE_OSX_ARCHITECTURES=i386"
args << "-DOPENCV_EXTRA_C_FLAGS='-arch i386 -m32'"
args << "-DOPENCV_EXTRA_CXX_FLAGS='-arch i386 -m32 -Wunsequenced'"
else
args << "-DOPENCV_EXTRA_CXX_FLAGS='-Wunsequenced'"
end
args << '-DWITH_QT=ON' if build.with? 'qt'
args << '-DWITH_TBB=ON' if build.with? 'tbb'
# OpenCL 1.1 is required, but Snow Leopard and older come with 1.0
args << '-DWITH_OPENCL=OFF' if build.without? 'opencl' or MacOS.version < :lion
args << '..'
mkdir 'macbuild' do
system 'cmake', *args
system "make"
system "make install"
end
end
def caveats
python.standard_caveats if python
end
end
__END__
--- /modules/highgui/CMakeLists.txt
+++ /modules/highgui/CMakeLists.txt
@@ -191,7 +191,10 @@
list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})
endif()
if(APPLE)
- list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration" bz2)
+ EXEC_PROGRAM(pkg-config
+ ARGS "--libs --static 'libavcodec'"
+ OUTPUT_VARIABLE LIBAVCODEC_LIBS)
+ list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration" bz2 ${LIBAVCODEC_LIBS})
endif()
endif(HAVE_FFMPEG)
@sheharyarn
Copy link

BTW I'm getting this error, any fix?

==> Downloading https://github.com/Itseez/opencv/archive/2.4.7.1.tar.gz
######################################################################## 100.0%
==> Patching
patching file modules/highgui/CMakeLists.txt
Hunk #1 succeeded at 181 (offset -10 lines).
Warning: Formula#python is deprecated and will go away shortly.
Error: undefined method `incdir' for #<PythonDependency: "python" []>
Please report this bug:
    https://github.com/Homebrew/homebrew/wiki/troubleshooting
/Library/Caches/Homebrew/Formula/opencv.rb:47:in `install'
/usr/local/Library/Homebrew/build.rb:174:in `install'
/usr/local/Library/Homebrew/formula.rb:273:in `brew'
/usr/local/Library/Homebrew/formula.rb:624:in `stage'
/usr/local/Library/Homebrew/resource.rb:62:in `unpack'
/usr/local/Library/Homebrew/extend/fileutils.rb:21:in `mktemp'
/usr/local/Library/Homebrew/resource.rb:59:in `unpack'
/usr/local/Library/Homebrew/resource.rb:52:in `stage'
/usr/local/Library/Homebrew/formula.rb:622:in `stage'
/usr/local/Library/Homebrew/formula.rb:268:in `brew'
/usr/local/Library/Homebrew/build.rb:151:in `install'
/usr/local/Library/Homebrew/build.rb:45:in `main'
/usr/local/Library/Homebrew/build.rb:12
/Library/Caches/Homebrew/Formula/opencv.rb:73

@sheharyarn
Copy link

I was able to fix it by following the guide in this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment