2010-05-18 23:09:29 +00:00
|
|
|
require 'formula'
|
|
|
|
|
2011-09-18 18:00:46 +00:00
|
|
|
def which_python
|
|
|
|
"python" + `python -c 'import sys;print(sys.version[:3])'`.strip
|
|
|
|
end
|
|
|
|
|
|
|
|
def site_package_dir
|
|
|
|
"lib/#{which_python}/site-packages"
|
|
|
|
end
|
|
|
|
|
2011-03-10 05:11:03 +00:00
|
|
|
class Opencv < Formula
|
2012-08-20 05:48:30 +00:00
|
|
|
homepage 'http://opencv.org/'
|
2012-11-15 10:57:39 +00:00
|
|
|
url 'http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.3/OpenCV-2.4.3.tar.bz2'
|
|
|
|
sha1 '982be2c3e52dfc3e9d14692c60bc856b2b766be2'
|
2010-08-15 18:28:43 +00:00
|
|
|
|
2012-08-21 21:46:32 +00:00
|
|
|
option '32-bit'
|
|
|
|
option 'with-qt', 'Build the Qt4 backend to HighGUI'
|
|
|
|
option 'with-tbb', 'Enable parallel code in OpenCV using Intel TBB'
|
2012-12-08 06:53:57 +00:00
|
|
|
option 'with-opencl', 'Enable gpu code in OpenCV using OpenCL'
|
2012-08-21 21:46:32 +00:00
|
|
|
|
2010-09-19 17:21:57 +00:00
|
|
|
depends_on 'cmake' => :build
|
|
|
|
depends_on 'pkg-config' => :build
|
2012-08-21 21:46:32 +00:00
|
|
|
depends_on 'numpy' => :python
|
2010-08-04 23:54:36 +00:00
|
|
|
|
2012-08-20 05:48:30 +00:00
|
|
|
depends_on 'eigen' => :optional
|
2010-04-07 05:58:35 +00:00
|
|
|
depends_on 'libtiff' => :optional
|
|
|
|
depends_on 'jasper' => :optional
|
|
|
|
depends_on 'tbb' => :optional
|
2013-02-01 00:21:13 +00:00
|
|
|
depends_on 'qt' => :optional
|
2012-09-07 20:37:26 +00:00
|
|
|
depends_on :libpng
|
2011-09-21 21:35:13 +00:00
|
|
|
|
2010-09-13 22:16:09 +00:00
|
|
|
# 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
|
2012-08-20 05:48:30 +00:00
|
|
|
# in Homebrew anyway. Will depend on openexr if it's installed.
|
2010-05-18 23:09:29 +00:00
|
|
|
|
|
|
|
def install
|
2012-08-20 05:48:30 +00:00
|
|
|
args = std_cmake_args + %w[
|
|
|
|
-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
|
|
|
|
]
|
2012-08-28 04:53:14 +00:00
|
|
|
if build.build_32_bit?
|
2012-08-20 05:48:30 +00:00
|
|
|
args << "-DCMAKE_OSX_ARCHITECTURES=i386"
|
|
|
|
args << "-DOPENCV_EXTRA_C_FLAGS='-arch i386 -m32'"
|
|
|
|
args << "-DOPENCV_EXTRA_CXX_FLAGS='-arch i386 -m32'"
|
|
|
|
end
|
2013-02-01 00:21:13 +00:00
|
|
|
args << '-DWITH_QT=ON' if build.with? 'qt'
|
|
|
|
args << '-DWITH_TBB=ON' if build.with? 'tbb'
|
|
|
|
args << '-DWITH_OPENCL=ON' if build.with? 'opencl'
|
2011-09-21 21:35:13 +00:00
|
|
|
|
|
|
|
# The CMake `FindPythonLibs` Module is dumber than a bag of hammers when
|
|
|
|
# more than one python installation is available---for example, it clings
|
|
|
|
# to the Header folder of the system Python Framework like a drowning
|
|
|
|
# sailor.
|
|
|
|
#
|
|
|
|
# This code was cribbed from the VTK formula and uses the output to
|
|
|
|
# `python-config` to do the job FindPythonLibs should be doing in the first
|
|
|
|
# place.
|
|
|
|
python_prefix = `python-config --prefix`.strip
|
|
|
|
# Python is actually a library. The libpythonX.Y.dylib points to this lib, too.
|
|
|
|
if File.exist? "#{python_prefix}/Python"
|
|
|
|
# Python was compiled with --framework:
|
|
|
|
args << "-DPYTHON_LIBRARY='#{python_prefix}/Python'"
|
2012-08-20 05:48:30 +00:00
|
|
|
if !MacOS::CLT.installed? and python_prefix.start_with? '/System/Library'
|
|
|
|
# For Xcode-only systems, the headers of system's python are inside of Xcode
|
|
|
|
args << "-DPYTHON_INCLUDE_DIR='#{MacOS.sdk_path}/System/Library/Frameworks/Python.framework/Versions/2.7/Headers'"
|
|
|
|
else
|
|
|
|
args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/Headers'"
|
|
|
|
end
|
2011-09-21 21:35:13 +00:00
|
|
|
else
|
|
|
|
python_lib = "#{python_prefix}/lib/lib#{which_python}"
|
|
|
|
if File.exists? "#{python_lib}.a"
|
|
|
|
args << "-DPYTHON_LIBRARY='#{python_lib}.a'"
|
|
|
|
else
|
|
|
|
args << "-DPYTHON_LIBRARY='#{python_lib}.dylib'"
|
|
|
|
end
|
|
|
|
args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/include/#{which_python}'"
|
|
|
|
end
|
2011-09-21 23:08:53 +00:00
|
|
|
args << "-DPYTHON_PACKAGES_PATH='#{lib}/#{which_python}/site-packages'"
|
2011-09-21 21:35:13 +00:00
|
|
|
|
2012-08-20 05:48:30 +00:00
|
|
|
args << '..'
|
|
|
|
mkdir 'macbuild' do
|
|
|
|
system 'cmake', *args
|
|
|
|
system "make"
|
|
|
|
system "make install"
|
|
|
|
end
|
2010-05-18 23:09:29 +00:00
|
|
|
end
|
2010-08-04 23:54:36 +00:00
|
|
|
|
2010-04-07 05:58:35 +00:00
|
|
|
def caveats; <<-EOS.undent
|
|
|
|
The OpenCV Python module will not work until you edit your PYTHONPATH like so:
|
2011-09-18 18:00:46 +00:00
|
|
|
export PYTHONPATH="#{HOMEBREW_PREFIX}/#{site_package_dir}:$PYTHONPATH"
|
2010-08-04 23:54:36 +00:00
|
|
|
|
2010-04-07 05:58:35 +00:00
|
|
|
To make this permanent, put it in your shell's profile (e.g. ~/.profile).
|
2010-05-18 23:09:29 +00:00
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|