Skip to content

Instantly share code, notes, and snippets.

@telwertowski
Created May 2, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telwertowski/a047772c8ae38bb6612c0c7180e82a0c to your computer and use it in GitHub Desktop.
Save telwertowski/a047772c8ae38bb6612c0c7180e82a0c to your computer and use it in GitHub Desktop.
Building QGIS from Source on macOS

Building QGIS from Source on macOS

This document shows how to build QGIS, including many dependencies, from source on macOS.

This is a developer oriented Unix-like approach which does not rely on a package manager. All components will be installed in standard system locations (which will be noted later in the document).

MacOS 10.13.4 (High Sierra) is used and all dependencies are current as of May 1, 2018.

⚠️ Draft document. There may be errors or missing dependencies.

Terminal

Most tasks are accomplished using the Terminal app located in /Applications/Utilities.

When building each dependency, you may want to create a new terminal session so that you can easily save the output of each configure/make sequence for future reference. If a later step fails, inspecting the output of earlier steps may be helpful.

Command Line Tools

For building applications, you will need some additional developer tools not included with basic macOS. This will download and install them.

xcode-select --install

More info: How to Install Command Line Tools (Without XCode)

CMake

Download dmg (3.11.1) from CMake download page and install.

Enable command line access.

sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

Python

Download dmg (3.6.5) from Python download page and install.

Install owslib, psycopg2, jinja2, pygments, pyyaml, numpy, plotly using pip3.

Python related dependencies built later will be installed in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages.

KyngChaos frameworks

Download QGIS installer (3.0.2-2) and install GDAL Complete (contains GDAL, GEOS, PROJ, SQLite3 and UnixImageIO frameworks; gdal, pyproj and shapely Python modules).

Download GSL (1.16-1) and install.

Download PostgreSQL (9.4.15-1) and PostGIS (2.2.6-1) and install.

Frameworks will be installed in /Library/Frameworks.

Other

Some additional or newer command line tools are required. These will be installed in /usr/local.

Bison

Download bison-3.0.4.tar.xz and build. QGIS needs a newer version than provided by macOS.

Download secure_snprintf.patch. A macOS 10.13 compatibility issue has been fixed in the maintenance branch but there has not been a Bison release since this fix.

tar -xf ~/Downloads/bison-3.0.4.tar.xz -C ~/Developer/packages
cd ~/Developer/packages/bison-3.0.4
patch -p0 < ~/Downloads/secure_snprintf.patch 
./configure
make
sudo make install

libtool

Download libtool-2.4.6.tar.xz and build.

tar -xf ~/Downloads/libtool-2.4.6.tar.xz -C ~/Developer/packages
cd ~/Developer/packages/libtool-2.4.6
./configure
make
sudo make install

LibreSSL

Download libressl-2.2.7.tar.gz and build. This is the same version included with macOS 10.13 but macOS does not provide header files needed by QCA.

tar -xf ~/Downloads/libressl-2.2.7.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/libressl-2.2.7
./configure --prefix=/usr/local/libressl-2.2.7
make
sudo make install

libspatialindex

Download spatialindex-src-1.8.5.tar.bz2 and build.

tar -xf ~/Downloads/spatialindex-src-1.8.5.tar.bz2 -C ~/Developer/packages
cd ~/Developer/packages/spatialindex-src-1.8.5
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/libspatialindex-1.8.5 ..
make
sudo make install

lintasn1

Download libtasn1-4.13.tar.gz and build.

tar -xf ~/Downloads/libtasn1-4.13.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/libtasn1-4.13
./configure --prefix=/usr/local/libtasn1-4.13
make
sudo make install

libzip

Download libzip-1.5.1.tar.xz and build.

tar -xf ~/Downloads/libzip-1.5.1.tar.xz -C ~/Developer/packages
cd ~/Developer/packages/libzip-1.5.1
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/libzip-1.5.1 ..
make
sudo make install

Qt

Qt

Download Qt Online Installer from the Qt Downloads page.

The default install location is /User/USER/Qt. I change this to /Applications/Qt since Cmake and Python are there.

Under Select Components (only Qt Tools is initially selected), expand Qt, expand the version (5.10.1) and check macOS.

Add to .profile file.

export QT5DIR=/Applications/Qt/5.10.1/clang_64
export CMAKE_PREFIX_PATH=$QT5DIR
alias qmake=$QT5DIR/bin/qmake

Qt dependent libraries built later will be installed in /Applications/Qt/5.10.1. When upgrading Qt, the dependent libraries must be rebuilt.

Upgrade note

Although the installer appears to support versions, it doesn't let you select an existing directory to upgrade.

To upgrade, rename the existing installation.

mv /Applications/Qt /Applications/Qt~

Install the new version and move the older version into the new folder. The older version can be deleted later when no longer needed.

mv /Applications/Qt~/Qt-5.0.0/ Applications/Qt
mv /Applications/Qt~/Docs/Qt-5.0.0/ Applications/Qt/Docs
mv /Applications/Qt~/Examples/Qt-5.0.0/ Applications/Qt/Examples

QtWebkit

Download qtwebkit-opensource-src-5.9.0.tar.xz and build. (This will take awhile.)

tar -xf ~/Downloads/qtwebkit-opensource-src-5.9.0.tar.xz -C ~/Developer/packages
cd ~/Developer/packages/qtwebkit-opensource-src-5.9.0
mkdir build
cd build
qmake ../WebKit.pro
make
sudo make install

Riverbank software

Download QScintilla_gpl-2.10.4.tar.gz and build.

tar -xf ~/Downloads/QScintilla_gpl-2.10.4.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/QScintilla_gpl-2.10.4/Qt4Qt5
mkdir build
cd build
qmake qscintilla.pro -spec macx-clang
make
sudo make install
cd ../../designer-Qt4Qt5
qmake designer.pro -spec macx-clang
make
sudo make install

Download ip-4.19.8.tar.gz and build.

tar -xf ~/Downloads/sip-4.19.8.tar.gz.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/sip-4.19.8
python3 configure.py
make
sudo make install

Download PyQt5_gpl-5.10.1.tar.gz and build.

tar -xf ~/Downloads/PyQt5_gpl-5.10.1.tar.gz.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/PyQt5_gpl-5.10.1
python3 configure.py --qmake=/Applications/Qt/5.10.1/clang_64/bin/qmake
make
sudo make install

Build QScintilla Python module after PyQt.

cd ~/Developer/packages/QScintilla_gpl-2.10.4/Python
python3 configure.py --qmake=/Applications/Qt/5.10.1/clang_64/bin/qmake --pyqt=PyQt5
make
sudo make install

QCA (Qt Cryptographic Architecture)

Download qca-2.1.3.tar.gz and build.

tar -xf ~/Downloads/qca-2.1.3.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/qca-2.1.3
mkdir build
cd build
cmake \
  -D CMAKE_INSTALL_PREFIX=/usr/local/qca-2.1.3 \
  -D OPENSSL_ROOT_DIR=/usr/local/libressl-2.2.7 \
  ..
make
sudo make install

Add to .profile file.

export PATH=$PATH:/usr/local/qca-2.1.3/bin

QtKeychain

Download qtkeychain-0.8.0.tar.gz and build.

tar -xf ~/Downloads/qtkeychain-0.8.0.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/qtkeychain-0.8.0
mkdir build
cd build
cmake \
  -D CMAKE_INSTALL_PREFIX=/usr/local/qtkeychain-0.8.0 \
  ..
make
sudo make install

Qwt

Download qwt-6.1.3.tar.bz2 and build.

tar -xf ~/Downloads/qwt-6.1.3.tar.bz2 -C ~/Developer/packages
cd ~/Developer/packages/qwt-6.1.3
mkdir build
cd build
qmake ../qwt.pro
make
sudo make install

GRASS

Download grass-7.4.0.tar.gz and build.

The options below are not sufficient to build a working GRASS application but is does create the 'include' directories needed to build the QGIS GRASS components.

tar -xf ~/Downloads/grass-7.4.0.tar.gz -C ~/Developer/packages
cd ~/Developer/packages/grass-7.4.0
NAD2BIN=/Library/Frameworks/PROJ.framework/unix/bin/nad2bin ./configure \
  --with-proj-includes=/Library/Frameworks/PROJ.framework/unix/include \
  --with-proj-libs=/Library/Frameworks/PROJ.framework/unix/lib \
  --with-proj-share=/Library/Frameworks/PROJ.framework/unix/share/proj \
  --with-gdal=/Library/Frameworks/GDAL.framework/unix/bin/gdal-config \
  --with-geos=/Library/Frameworks/GEOS.framework/unix/bin/geos-config \
  --with-tiff-includes=/Library/Frameworks/UnixImageIO.framework/unix/include \
  --with-tiff-libs=/Library/Frameworks/UnixImageIO.framework/unix/lib \
  --with-png-includes=/Library/Frameworks/UnixImageIO.framework/unix/include \
  --with-png-libs=/Library/Frameworks/UnixImageIO.framework/unix/lib \
  --with-postgres \
  --with-postgres-includes=/usr/local/pgsql/include \
  --with-postgres-libs=/usr/local/pgsql/lib \
  --with-mysql \
  --with-mysql-includes=/usr/local/mysql/include \
  --with-mysql-libs=/usr/local/mysql/lib \
  --without-opengl \
  --without-fftw \
  --with-blas \
  --with-blas-includes=/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers \
  --with-lapack \
  --with-lapack-includes=/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers \
  --without-cairo \
  --without-freetype \
  --enable-macosx-app \
  --with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
  --prefix=/Applications
make

QGIS

Get source from GitHub and build.

mkdir ~/Developer/qgis
git clone git://github.com/qgis/QGIS.git
cd QGIS
git checkout master
mkdir ../build
cd ../build
cmake -D CMAKE_INSTALL_PREFIX=. \
  -D WITH_3D=TRUE \
  -D ENABLE_TESTS=FALSE \
  -D GRASS_PREFIX7=~/Developer/packages/grass-7.4.0/dist.x86_64-apple-darwin17.4.0 \
  -D LIBTASN1_INCLUDE_DIR=/usr/local/libtasn1-4.13/include \
  -D LIBTASN1_LIBRARY=/usr/local/libtasn1-4.13/lib/libtasn1.dylib \
  -D LIBZIP_INCLUDE_DIR=/usr/local/libzip-1.5.1/include \
  -D LIBZIP_CONF_INCLUDE_DIR=/usr/local/libzip-1.5.1/include \
  -D LIBZIP_LIBRARY=/usr/local/libzip-1.5.1/lib/libzip.dylib \
  -D QCA_LIBRARY=/usr/local/qca-2.1.3/lib/qca-qt5.framework \
  -D QTKEYCHAIN_INCLUDE_DIR=/usr/local/qtkeychain-0.8.0/include/qt5keychain \
  -D QTKEYCHAIN_LIBRARY=/usr/local/qtkeychain-0.8.0/lib/libqt5keychain.dylib \
  -D QWT_LIBRARY=/usr/local/qwt-6.1.3/lib/qwt.framework \
  -D SPATIALINDEX_INCLUDE_DIR=/usr/local/libspatialindex-1.8.5/include/spatialindex \
  -D SPATIALINDEX_LIBRARY=/usr/local/libspatialindex-1.8.5/lib/libspatialindex.dylib \
  ../QGIS
make install

The app is now built but will crash when it loads QCA plugins. There is no QCA API to set the plugin path so QCA loads both the QGIS and system copies of the plugins. Hiding the Qt developer folder will prevent the system copy of the QCA plugins from loading.

This will move the Qt developer folder out of the way, launch QGIS and restore the developer folder after quitting.

mv /Applications/Qt /Applications/Qt~
QGIS.app/Contents/MacOS/QGIS 
mv /Applications/Qt~ /Applications/Qt

One resolution would be to remove macOS packaging from the install process. Then a locally built copy of QGIS would run using the system libraries. Plugins and system libraries would be copied into the QGIS folder only when doing release packaging.

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