2010-07-01 09:30:46 +00:00
|
|
|
require 'formula'
|
|
|
|
|
2011-03-10 05:11:03 +00:00
|
|
|
class Vtk < Formula
|
2010-07-01 09:30:46 +00:00
|
|
|
homepage 'http://www.vtk.org'
|
2012-06-13 12:53:24 +00:00
|
|
|
url 'http://www.vtk.org/files/release/5.10/vtk-5.10.0.tar.gz'
|
|
|
|
sha1 '0c9a17e2f446dc78b0500dc5bbd1c6a2864a0191'
|
2010-07-01 09:30:46 +00:00
|
|
|
|
|
|
|
depends_on 'cmake' => :build
|
2012-06-13 12:53:24 +00:00
|
|
|
depends_on :x11 if ARGV.include? '--x11'
|
2010-07-01 09:30:46 +00:00
|
|
|
depends_on 'qt' if ARGV.include? '--qt'
|
2012-06-13 12:53:24 +00:00
|
|
|
depends_on 'sip' if ARGV.include? '--pyqt' and ARGV.include? '--python'
|
|
|
|
depends_on 'pyqt' if ARGV.include? '--pyqt' and ARGV.include? '--python'
|
|
|
|
|
|
|
|
skip_clean :all # Otherwise vtkpython complains can't find symbol _environ
|
2010-07-01 09:30:46 +00:00
|
|
|
|
|
|
|
def options
|
|
|
|
[
|
2012-06-13 12:53:24 +00:00
|
|
|
['--examples', 'Compile and install various examples.'],
|
|
|
|
['--python', 'Enable python wrapping of VTK classes.'],
|
|
|
|
['--pyqt', 'Make python wrapped classes available to SIP/PyQt.'],
|
|
|
|
['--qt', 'Enable Qt4 extension via the Homebrew qt formula.'],
|
|
|
|
['--qt-extern', 'Enable Qt4 extension via non-Homebrew external Qt4.'],
|
|
|
|
['--tcl', 'Enable Tcl wrapping of VTK classes.'],
|
|
|
|
['--x11', 'Enable X11 extension rather than OSX native Aqua.']
|
2010-07-01 09:30:46 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def install
|
2012-06-13 12:53:24 +00:00
|
|
|
args = std_cmake_args + %W[
|
|
|
|
-DVTK_REQUIRED_OBJCXX_FLAGS=''
|
|
|
|
-DVTK_USE_CARBON=OFF
|
|
|
|
-DBUILD_TESTING=OFF
|
|
|
|
-DBUILD_SHARED_LIBS=ON
|
|
|
|
-DCMAKE_INSTALL_RPATH:STRING='#{lib}/vtk-5.10'
|
|
|
|
-DCMAKE_INSTALL_NAME_DIR:STRING='#{lib}/vtk-5.10'
|
|
|
|
]
|
|
|
|
|
|
|
|
args << '-DBUILD_EXAMPLES=' + ((ARGV.include? '--examples') ? 'ON' : 'OFF')
|
2010-07-01 09:30:46 +00:00
|
|
|
|
|
|
|
if ARGV.include? '--python'
|
2011-04-14 17:45:06 +00:00
|
|
|
python_prefix = `python-config --prefix`.strip
|
2012-06-13 12:53:24 +00:00
|
|
|
# Install to lib and let installer symlink to global python site-packages.
|
|
|
|
# The path in lib needs to exist first and be listed in PYTHONPATH.
|
|
|
|
pydir = lib/which_python/'site-packages'
|
|
|
|
pydir.mkpath
|
|
|
|
ENV.prepend 'PYTHONPATH', pydir, ':'
|
|
|
|
args << "-DVTK_PYTHON_SETUP_ARGS='--prefix=#{prefix}'"
|
2011-04-14 17:45:06 +00:00
|
|
|
# Python is actually a library. The libpythonX.Y.dylib points to this lib, too.
|
2011-05-28 09:01:44 +00:00
|
|
|
if File.exist? "#{python_prefix}/Python"
|
|
|
|
# Python was compiled with --framework:
|
|
|
|
args << "-DPYTHON_LIBRARY='#{python_prefix}/Python'"
|
2012-06-13 12:53:24 +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-05-28 09:01:44 +00:00
|
|
|
else
|
|
|
|
python_version = `python-config --libs`.match('-lpython(\d+\.\d+)').captures.at(0)
|
|
|
|
python_lib = "#{python_prefix}/lib/libpython#{python_version}"
|
|
|
|
if File.exists? "#{python_lib}.a"
|
|
|
|
args << "-DPYTHON_LIBRARY='#{python_lib}.a'"
|
|
|
|
else
|
|
|
|
args << "-DPYTHON_LIBRARY='#{python_lib}.dylib'"
|
|
|
|
end
|
2012-06-13 12:53:24 +00:00
|
|
|
args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/include/#{which_python}'"
|
|
|
|
end
|
|
|
|
args << '-DVTK_WRAP_PYTHON=ON'
|
|
|
|
if ARGV.include? '--pyqt'
|
|
|
|
args << '-DVTK_WRAP_PYTHON_SIP=ON'
|
|
|
|
args << "-DSIP_PYQT_DIR='#{HOMEBREW_PREFIX}/share/sip'"
|
2011-05-28 09:01:44 +00:00
|
|
|
end
|
2010-07-01 09:30:46 +00:00
|
|
|
end
|
|
|
|
|
2011-04-14 17:45:06 +00:00
|
|
|
if ARGV.include? '--qt' or ARGV.include? '--qt-extern'
|
2012-06-13 12:53:24 +00:00
|
|
|
args << '-DVTK_USE_GUISUPPORT=ON'
|
|
|
|
args << '-DVTK_USE_QT=ON'
|
|
|
|
args << '-DVTK_USE_QVTK=ON'
|
2010-07-01 09:30:46 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 12:53:24 +00:00
|
|
|
args << '-DVTK_WRAP_TCL=ON' if ARGV.include? '--tcl'
|
2010-07-01 09:30:46 +00:00
|
|
|
|
2011-09-04 23:31:55 +00:00
|
|
|
# default to cocoa for everything except x11
|
|
|
|
if ARGV.include? '--x11'
|
2012-06-13 12:53:24 +00:00
|
|
|
args << '-DVTK_USE_COCOA=OFF'
|
|
|
|
args << '-DVTK_USE_X=ON'
|
|
|
|
else
|
|
|
|
args << '-DVTK_USE_COCOA=ON'
|
2011-09-04 23:31:55 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 12:53:24 +00:00
|
|
|
unless MacOS::CLT.installed?
|
|
|
|
# We are facing an Xcode-only installation, and we have to keep
|
|
|
|
# vtk from using its internal Tk headers (that differ from OSX's).
|
|
|
|
args << "-DTK_INCLUDE_PATH:PATH=#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Headers"
|
|
|
|
args << "-DTK_INTERNAL_PATH:PATH=#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Headers/tk-private"
|
|
|
|
end
|
2010-07-01 09:30:46 +00:00
|
|
|
|
|
|
|
args << ".."
|
2012-02-22 04:48:36 +00:00
|
|
|
|
|
|
|
mkdir 'build' do
|
2012-06-13 12:53:24 +00:00
|
|
|
system 'cmake', *args
|
|
|
|
system 'make'
|
|
|
|
system 'make install'
|
|
|
|
end
|
|
|
|
|
|
|
|
(share+'vtk').install 'Examples' if ARGV.include? '--examples'
|
|
|
|
|
|
|
|
# Finalize a couple of Python issues due to our installing into the cellar.
|
|
|
|
if ARGV.include? '--python'
|
|
|
|
# Avoid the .egg and use the python module right away, because
|
|
|
|
# system python does not read .pth files from our site-packages.
|
|
|
|
mv pydir/'VTK-5.10.0-py2.7.egg/vtk', pydir/'vtk'
|
|
|
|
|
|
|
|
# Remove files with duplicates in /usr/local/lib/python2.7/site-packages
|
|
|
|
%w(site.py site.pyc easy-install.pth VTK-5.10.0-py2.7.egg).each do |f|
|
|
|
|
rmtree pydir/f
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def caveats
|
|
|
|
s = ''
|
|
|
|
vtk = Tab.for_formula 'vtk'
|
|
|
|
if ARGV.include? '--python' or vtk.installed_with? '--python'
|
|
|
|
s += <<-EOS.undent
|
|
|
|
For non-homebrew Python, you need to amend your PYTHONPATH like so:
|
|
|
|
export PYTHONPATH=#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages:$PYTHONPATH
|
|
|
|
|
|
|
|
Even without the --pyqt option, you can display native VTK render windows
|
|
|
|
from python. Alternatively, you can integrate the RenderWindowInteractor
|
|
|
|
in PyQt, PySide, Tk or Wx at runtime. Look at
|
|
|
|
import vtk.qt4; help(vtk.qt4) or import vtk.wx; help(vtk.wx)
|
|
|
|
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
if ARGV.include? '--examples' or vtk.installed_with? '--examples'
|
|
|
|
s += <<-EOS.undent
|
|
|
|
|
|
|
|
The scripting examples are stored in #{HOMEBREW_PREFIX}/share/vtk
|
|
|
|
|
|
|
|
EOS
|
2010-07-01 09:30:46 +00:00
|
|
|
end
|
2012-06-13 12:53:24 +00:00
|
|
|
return s.empty? ? nil : s
|
|
|
|
end
|
|
|
|
|
|
|
|
def which_python
|
|
|
|
"python" + `python -c 'import sys;print(sys.version[:3])'`.strip
|
2010-07-01 09:30:46 +00:00
|
|
|
end
|
|
|
|
end
|