Find file
Fetching contributors…
Cannot retrieve contributors at this time
167 lines (134 sloc) 5.4 KB
require 'formula'
def grass?
ARGV.include? "--with-grass"
def postgis?
ARGV.include? "--with-postgis"
def py_version
`python -c 'import sys;print sys.version[:3]'`.chomp
# QWT 6.x has an insane build system---can't use the framework files it
# produces as they don't link properly. So, we use an internal static brew of
# QWT 5.2.2.
class Qwt52 < Formula
url ''
homepage ''
sha1 '77de405c5f9867a001f0e0a668154023faccb0a0'
# QGIS requires a newer version of bison than OS X provides.
class Bison < Formula
url ''
homepage ''
sha1 '907319624fe4f4c5f9e2c3e23601041ac636ae31'
class Qgis < Formula
homepage ''
url ''
sha1 '99c0d716acbe0dd70ad0774242d01e9251c5a130'
head '', :branch => 'master'
def options
['--with-grass', 'Build support for GRASS GIS.'],
['--with-postgis', 'Build support for PostGIS databases.']
depends_on 'cmake' => :build
depends_on 'gsl'
depends_on 'pyqt'
depends_on 'gdal'
depends_on 'spatialindex'
depends_on 'grass' if grass?
depends_on 'gettext' if grass? # For libintl
depends_on 'postgis' if postgis?
def install
# Double-check that pyqt is importable. Often, QGIS triggers pyqt
# installation and users miss the caveats.
unless quiet_system 'python', '-c', 'from PyQt4 import QtCore'
onoe <<-EOS.undent
Python could not import the PyQt4 module. This will cause the QGIS build to fail.
The most common reason for this failure is that the PYTHONPATH needs to be adjusted.
The pyqt caveats explain this adjustment and may be reviewed using:
brew info pyqt
exit 1
internal_qwt = + 'qwt52'
internal_bison = + 'bison' do
system "./configure", "--prefix=#{internal_bison}", "--disable-debug", "--disable-dependency-tracking"
system 'make install'
end do
inreplace 'qwtconfig.pri' do |s|
# change_make_var won't work because there are leading spaces
s.gsub! /^\s*INSTALLBASE\s*=(.*)$/, "INSTALLBASE=#{internal_qwt}"
# Removing the `QwtDll` config option will cause Qwt to build as a
# satic library. We could build dynamic, but we would need to hit the
# results with `install_name_tool` to make sure the paths are right. As
# the QGIS main executable seems to be the only thing that links
# against this, I'm keeping it simple with a static lib.
s.gsub! /^(\s*CONFIG.*QwtDll)$/, ''
system 'qmake -spec macx-g++ -config release'
system 'make install'
# Some test programs invoke binaries during construction that have
# incorrect library load paths---this causes the builds to fail.
# Set bundling level back to 0 (the default in all versions prior to 1.8.0)
# so that no time and energy is wasted copying the Qt frameworks into QGIS.
args = std_cmake_args.concat %W[
ARGV.filter_for_dependencies do
# Ensure --HEAD flags get stripped.
grass = Formula.factory 'grass'
gettext = Formula.factory 'gettext'
args << "-DGRASS_PREFIX='#{Dir[grass.prefix + 'grass-*']}'"
# So that `libintl.h` can be found
ENV.append 'CXXFLAGS', "-I'#{gettext.include}'"
end if grass?
Dir.mkdir 'build'
Dir.chdir 'build' do
system 'cmake', '..', *args
system 'make install'
# Symlink the PyQGIS Python module somewhere convienant for users to put on
py_lib = lib + "python#{py_version}/site-packages"
qgis_modules = prefix + ''
ln_s qgis_modules, py_lib + 'qgis'
# Create script to launch QGIS app
(bin + 'qgis').write <<-EOS.undent
# Ensure Python modules can be found when QGIS is running.
env PYTHONPATH='#{HOMEBREW_PREFIX}/lib/python#{py_version}/site-packages':$PYTHONPATH\\
open #{prefix}/
def caveats; <<-EOS.undent
QGIS has been built as an application bundle. To make it easily available, a
wrapper script has been written that launches the app with environment
variables set so that Python modules will be functional:
You may also symlink into ~/Applications:
brew linkapps
mkdir -p #{ENV['HOME']}/.MacOSX
defaults write #{ENV['HOME']}/.MacOSX/environment.plist PYTHONPATH -string "#{HOMEBREW_PREFIX}/lib/python#{py_version}/site-packages"
You will need to log out and log in again to make environment.plist effective.
The QGIS python modules have been symlinked to:
If you are interested in PyQGIS development and are not using the Homebrew
Python formula, then you will need to ensure this directory is on your