Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active January 16, 2024 07:34
Show Gist options
  • Save nicerobot/7664605 to your computer and use it in GitHub Desktop.
Save nicerobot/7664605 to your computer and use it in GitHub Desktop.
Whew! QGIS 2 on Mavericks built using only Homebrew packages (i.e. without KyngChaos) \o/ -- WARNING: A _major_ assumption here is that your Homebrew PREFIX is /usr/local . -- DISCLAIMER: It worked for me. YMMV
#!/bin/bash
# Run this:
#
# curl https://gist.github.com/nicerobot/7664605/raw/install.sh | bash -s do-sudo
#
# which will run:
[ -f qgis2-homebrew-build.sh ] || {
curl -O https://gist.github.com/nicerobot/7664605/raw/qgis2-homebrew-build.sh
# If i download it, i'll remove it
trap 'rm -f qgis2-homebrew-build.sh' 0 1 2 3 15
}
bash ./qgis2-homebrew-build.sh ${*}
#!/bin/bash
# There's a few hoops to jump through but i mostly just followed the QGIS
# repository's INSTALL instructions for MacOSX. Also, there may be a few dependencies
# missing due to the fact that, when i was creating this, i think i already had
# many of the dependencies installed.
SELFD=$(cd -P $(dirname ${0} >/dev/null 2>&1; pwd))
SELF=$(basename ${0})
# This sudo is called from the following block if "do-sudo" is the first argument.
[ "${1}" = 'sudo' ] && {
which brew || exit ${LINENO}
brew install qt --HEAD
# Now install other dependencies normally.
for i in python bison pyqwt sip qscintilla2 spatialindex grass; do
[ -L /usr/local/opt/${i} ] || brew install ${i}
done
# Install qwt 6.0.1
[ -L /usr/local/lib/qwt.framework ] || {
# Use qwt 6.0.1 because QtPolar must be : 6.0.0 <= QtPolar <6.1.0
cd /usr/local
brew checkout 4392eba Library/Formula/qwt.rb
# Have to patch Library/Formula/qwt.rb with 6.1.0 lines so that it'll build using libc++ instead of libstc++
# Could probably also have simply patched the 6.1.0 formula to download the 6.0.1 tarball.
patch Library/Formula/qwt.rb <<-'PATCH'
--- a/Library/Formula/qwt.rb
+++ b/Library/Formula/qwt.rb
@@ -13,7 +13,15 @@ class Qwt < Formula
s.gsub! /^\s*QWT_INSTALL_PREFIX\s*=(.*)$/, "QWT_INSTALL_PREFIX=#{prefix}"
end
- system "qmake -spec macx-g++ -config release"
+ #system "qmake -spec macx-g++ -config release"
+ args = ['-config', 'release', '-spec']
+ # On Mavericks we want to target libc++, this requires a unsupported/macx-clang-libc++ flag
+ if ENV.compiler == :clang and MacOS.version >= :mavericks
+ args << "unsupported/macx-clang-libc++"
+ else
+ args << "macx-g++"
+ end
+ system 'qmake', *args
system "make"
system "make install"
end
PATCH
}
exit 0
}
#
[ "${1:-skip-sudo}" = 'do-sudo' ] && {
[ -w /usr/local ] || SUDO=sudo
${SUDO} ${SELFD}/${SELF} ${SUDO} || exit ${?}
# If sudo completes successfully, continue with QGIS build.
}
# If not already in QGIS directory,
[ -d .git ] && grep QGIS.git .git/config || {
# Then check if it exists, otherwise, clone it.
[ -d QGIS ] || git clone https://github.com/qgis/QGIS.git
# And get into it.
cd QGIS || exit ${LINENO}
}
#
[ -d build ] || mkdir -p build
cd build || exit ${LINENO}
cmake -D CMAKE_INSTALL_PREFIX=${HOME}/local \
-D CMAKE_BUILD_TYPE=MINSIZEREL -D ENABLE_TESTS=FALSE \
-D WITH_INTERNAL_SPATIALITE=FALSE -D WITH_PYSPATIALITE=FALSE \
-D SPATIALINDEX_LIBRARY=/usr/local/lib/libspatialindex.dylib \
-D SPATIALINDEX_INCLUDE_DIR=/usr/local/include/spatialindex \
-D QWT_LIBRARY=/usr/local/opt/qwt/lib/qwt.framework/qwt \
-D QWT_INCLUDE_DIR=/usr/local/lib/qwt.framework/Versions/Current/Headers \
-D BISON_EXECUTABLE=/usr/local/opt/bison/bin/bison \
-D WITH_APIDOC=TRUE \
..
make -j $(/usr/sbin/sysctl -n hw.ncpu)
# Hack to ensure QGIS has Homebrew's `python` before the system's so that `sip` is available.
[ -x output/bin/QGIS.app/Contents/MacOS/QGIS_ ] || {
cd output/bin/QGIS.app/Contents/MacOS || exit ${LINENO}
mv QGIS QGIS_
printf '#!/bin/bash\nPATH=/usr/local/bin:${PATH} $(dirname ${0})/QGIS_\n' >QGIS
chmod +x QGIS
}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment