= Building on MacOS X = In this approach I will try to avoid as much as possible building dependencies from source and rather use frameworks wherever possible. The base system here is Mac OS X 10.4 (__Tiger__), with a single, default, architecture build. "Universal", SDK and non-default arch builds require more complex options and some fiddling with the system. Included are notes for building on Mac OS X 10.5 (__Leopard__), 10.6 (__Snow Leopard__) and 10.7 (__Lion__). (These names will be used throughout the instructions.) Make sure to read each section completely before typing the first command you see. __General note on Terminal usage:__ When I say "cd" to a folder in a Terminal, it means type "cd " (without the quotes, make sure to type a space after) and then type the path to said folder, then . A simple way to do this without having to know and type the full path is, after type the "cd " part, drag the folder (use the icon in its window title bar, or drag a folder from within a window) from the Desktop to the Terminal, then tap . __Parallel Compilation:__ On multiprocessor/multicore Macs, it's possible to speed up compilation, but it's not automatic. Whenever you type "make" (but NOT "make install"), instead type: ``` make -j [n] ``` Replace [n] with the number of cores and/or processors your Mac has. On recent models with hyperthreading processors this can be double the physical count of processors and cores. ie: Mac Pro "8 Core" model (2 quad core processors) = 8 ie: Macbook Pro i5 (hyperthreading) = 2 cores X 2 = 4 == Install Developer Tools == Developer tools are not a part of a standard OS X installation. Up through Snow Leopard, the Developer Tools, later called Xcode, were included with the system install disks, though it's best to download the latest version compatible with your system to get important updates fixing various issues. Starting with Lion, Xcode is available as a download and from the App Store. BUT, there is really no need for the full Xcode on Lion, and in fact could be tricky to use for compiling QGIS. Downloading Xcode/Developer Tools requires a free developer account at developer.apple.com. Up through Snow Leopard, get the latest __Xcode__ that is supported for your system. For Lion, all you need is the much smaller __Command Line Tools for Xcode__ (you don't get the IDE or system SDKs but they are not necessary for QGIS). When installing Xcode up through Snow Leopard, make sure to do a custom install and install the Unix Development or Command Line Tools option. On Lion, if you have installed Xcode 4.0 - 4.2 and are upgrading to 4.3, it's a good idea to uninstall the old version first with: ``` sudo /Developer/Library/uninstall-devtools ``` == Install Qt4 from disk image == You need a minimum of Qt-4.4.0. I suggest getting the latest. There is no need for the full Qt SDK, so save yourself some download time and get the frameworks only. This is available in the Libraries section of the Qt download page. __Snow Leopard+ note:__ If you are building on Snow Leopard+, you will need to decide between 32-bit support in the older Qt Carbon branch, or 64-bit support in the Qt Cocoa branch. Appropriate installers are available for both as of Qt-4.5.2, though they stopped making Carbon packages at Qt 4.7.4. Qt 4.6+ is recommended for Cocoa. Starting with Lion, Carbon may not work properly, if at all. __PPC note:__ The readymade Qt Cocoa installers don't include PPC support, you'd have to compile Qt yourself. But, there appear to be issues with Qt Cocoa on PPC Macs anyways. Qt Carbon is recommended on PPC Macs. http://qt.nokia.com/downloads If you want debug frameworks, Qt also provides a separate download with these. These are in addition to the non-debug frameworks. Earlier OS X systems may need an old Qt version - check the requirements of the current Qt version. To get old Qt downloads, there is an FTP link at the bottom of the download page. Files are in the qt/source (yes, even the binary packages). Once downloaded open the disk image and run the installer. Note you need admin privileges to install. __Leopard note:__ Qt includes a couple non-framework libraries in /usr/lib. When using a system SDK these libraries will not be found. To fix this problem, add symlinks to /usr/local: ``` sudo ln -s /usr/lib/libQtUiTools.a /usr/local/lib/ sudo ln -s /usr/lib/libQtCLucene.dylib /usr/local/lib/ ``` These should then be found automatically. Earlier systems may need some help by adding '-L/usr/local/lib' to CMAKE_SHARED_LINKER_FLAGS, CMAKE_MODULE_LINKER_FLAGS and CMAKE_EXE_LINKER_FLAGS in the cmake build. == Install CMake for OSX == Get the latest source release from here: http://www.cmake.org/cmake/resources/software.html Binary installers are available for OS X, but they are not recommended (2.4 versions install in /usr instead of /usr/local, and 2.6+ versions are a strange application). Instead, download the source. NOTE: 2.8.5 is broken for detecting part of Qt. Fixed in 2.8.6. Double-click the source tarball, then cd to the source folder and: ``` ./bootstrap --docdir=/share/doc/CMake --mandir=/share/man make sudo make install ``` == Install development frameworks for QGIS dependencies == Download William Kyngesburye's excellent GDAL Complete package that includes PROJ, GEOS, GDAL, SQLite3, Spatialite, and image libraries, as frameworks. There is also a GSL framework. http://www.kyngchaos.com/wiki/software/frameworks Once downloaded, open and install the frameworks. William provides an additional installer package for Postgresql (for PostGIS support). QGIS just needs the libpq client library, so unless you want to setup the full Postgres + PostGIS server, all you need is the client-only package. It's available here: http://www.kyngchaos.com/wiki/software/postgres Also available is a GRASS application: http://www.kyngchaos.com/wiki/software/grass Old versions of these packages for older systems are available in the software archive section. === Additional Dependencies: General compatibility note === There are some additional dependencies that, at the time of writing, are not provided as frameworks or installers so we will need to build these from source. If you are wanting to build QGIS as a 64-bit application, you will need to provide the appropriate build commands to produce 64-bit support in dependencies. Likewise, for 32-bit support on Snow Leopard, you will need to override the default system architecture, which is 64-bit, according to instructions for individual dependency packages. Stable release versions are preferred. Beta and other development versions may have problems and you are on your own with those. === Additional Dependencies: Expat === __Snow Leopard+ note:__ Snow Leopard includes a usable expat, so this step is not necessary on Snow Leopard or Lion. Get the expat sources: http://sourceforge.net/project/showfiles.php?group_id=10127 Double-click the source tarball to unpack, then, in Terminal.app, cd to the source folder and: ``` ./configure make sudo make install ``` === Additional Dependencies: Spatialindex === Get the libspatialindex sources: http://download.osgeo.org/libspatialindex/ Double-click the source tarball to unpack, then, in Terminal.app, cd to the source folder and: ``` ./configure make sudo make install ``` === Additional Dependencies: Python === __Leopard+ note:__ Starting with Leopard a usable Python is included in the system. This Python 2.5, 2.6 and 2.7, respectively for Leo, Snow and Lion. So there is no need to install Python on Leopard and newer. You can still install Python from python.org if preferred. If installing from python.org, make sure you install the latest Python 2.x from http://www.python.org/download/ Python 3 is a major change, and may have compatibility issues, so try it at your own risk. === Additional Dependencies: SIP === Retrieve the python bindings toolkit SIP from http://www.riverbankcomputing.com/software/sip/download Double-click the source tarball to unpack it, then, in Terminal.app, cd to the source folder. Then for your chosen Python: __python.org Python__ ``` python configure.py make sudo make install ``` __Leopard system Python__ SIP wants to install in the system path -- this is not a good idea. More configuration is needed to install outside the system path: ``` python configure.py -n -d /Library/Python/2.5/site-packages -b /usr/local/bin \ -e /usr/local/include -v /usr/local/share/sip -s MacOSX10.5.sdk ``` __Snow Leopard system Python__ Similar to Leopard, you should install outside the system Python path. Also, you need to specify the architecture you want (requires at least SIP 4.9), and make sure to run the versioned python binary (this one responds to the 'arch' command, 'python' does not). Substitute '2.7' for python version and 10.7 for SDK version below for Lion. If you are using 32-bit Qt (Qt Carbon): ``` python2.6 configure.py -n -d /Library/Python/2.6/site-packages -b /usr/local/bin \ -e /usr/local/include -v /usr/local/share/sip --arch=i386 -s MacOSX10.6.sdk ``` For 64-bit Qt (Qt Cocoa), use this configure line: ``` python2.6 configure.py -n -d /Library/Python/2.6/site-packages -b /usr/local/bin \ -e /usr/local/include -v /usr/local/share/sip --arch=x86_64 -s MacOSX10.6.sdk ``` __Lion system Python__ Similar to Snow Leopard, you should install outside the system Python path. There is no need for the SDK option (the CLI tools for Lion don't inlcude SDKs) or arch option: ``` python2.7 configure.py -d /Library/Python/2.7/site-packages -b /usr/local/bin \ -e /usr/local/include -v /usr/local/share/sip ``` __continue...__ Then continue with compilation and installation: ``` make sudo make install ``` === Additional Dependencies: PyQt === Retrieve the python bindings toolkit for Qt from http://www.riverbankcomputing.com/software/pyqt/download Double-click the source tarball to unpack it, then, in Terminal.app, cd to the source folder. Then for your chosen Python: __python.org Python__ ``` python configure.py yes ``` __Leopard system Python__ PyQt wants to install in the system path -- this is not a good idea. More configuration is needed to install outside the system path: ``` python configure.py -d /Library/Python/2.5/site-packages -b /usr/local/bin ``` __Snow Leopard system Python__ Similar to Leopard, you should install outside the system Python path. Also, you need to specify the architecture you want (requires at least PyQt 4.6), and make sure to run the versioned python binary (this one responds to the 'arch' command, which is important for pyuic4, 'python' does not). Substitute '2.7' for python version and 10.7 for SDK version below for Lion. If you are using 32-bit Qt (Qt Carbon): ``` python2.6 configure.py -d /Library/Python/2.6/site-packages -b /usr/local/bin --use-arch i386 ``` For 64-bit Qt (Qt Cocoa), use this configure line: ``` python2.6 configure.py -d /Library/Python/2.6/site-packages -b /usr/local/bin --use-arch x86_64 ``` __Snow Leopard system Python__ Similar to Snow Leopard, you should install outside the system Python path. But you don't need the arch option: ``` python2.7 configure.py -d /Library/Python/2.7/site-packages -b /usr/local/bin ``` __continue...__ ``` make sudo make install ``` If there is a problem with undefined symbols in QtOpenGL on Leopard, edit QtOpenGL/makefile and add ""-undefined dynamic_lookup"" to LFLAGS. Then make again. === Additional Dependencies: Qwt === The GPS tracking feature uses Qwt. NOTE: PyQwt is not compatible with PyQt 4.9, so we will skip that. Download the latest Qwt 5.x source (6.x is untested) from: http://sourceforge.net/projects/qwt Double-click the tarball to unpack it. Now, cd to the qwt source folder in a Terminal. Type these commands to build and install (assumes v5.2.2, adjust commands for other version as needed): ``` qmake -spec macx-g++ make sudo make install sudo install_name_tool -id /usr/local/qwt-5.2.2/lib/libqwt.5.dylib \ /usr/local/qwt-5.2.2/lib/libqwt.5.dylib ``` The Qwt shared library is now installed in /usr/local/qwt-5.x.x (x.x is the minor.point version). Remember this for QGIS configuration. === Additional Dependencies: Bison === The version of bison available by default on Mac OS X is too old so you need to get a more recent one on your system. Download at least version 2.4 from: ``` ftp.gnu.org/gnu/bison/ ``` Now build and install it to a prefix of /usr/local. Double-click the source tarball to unpack it, then cd to the source folder and: ``` ./configure --disable-dependency-tracking CFLAGS=-Os make sudo make install ``` === Additional Dependencies: gpsbabel === For integrated GPS Tools functions, a gpsbabel executable is required. You can find this at: http://www.gpsbabel.org/ Download the GPSBabel OS X package, and copy GPSBabelFE.app from the disk image to /Applications. === Optional Dependencies: libfcgi === If you want to use the QGIS Mapserver, you need libfcgi. This is included on systems up through Snow Leopard, but was dropped at Lion. So, on Lion you need to get the source from: http://www.fastcgi.com/dist/ Grab the latest fcgi SNAP package there. Double-click the source tarball to unpack it, then cd to the source folder and: ``` ./configure --disable-dependency-tracking CFLAGS=-Os make sudo make install ``` === Optional Dependencies: OSG & osgEarth === If you want the Globe plugin in QGIS (default OFF), OSG and osgEarth are needed. First, **OpenSceneGraph**. The main site is: http://www.openscenegraph.org/ Get the tarball (or zip) for the the latest 3.x version. Binary availability is unknown at this time as the site is down. Another place to get the source is github: http://github.com/openscenegraph/osg/tags Download the latest 3.1 version (you can select a tarball when you hover over the entry). Double-click the source tarball to unpack it. (There is a version numbering oddity in the source, but since we'll be bundling OSG as it's meant to be, it really doesn't matter). Installation is a bit out of touch with OS X standards, so we'll stage it to a temporary location first. You could stage it to the folder that the OSG source folder is in, or a common staging area like /Users/Shared/unix/osg. Pick a folder not hidden and that doesn't need admin permissions to write to for simplicity. In a new Terminal cd to the source folder and: ``` mkdir build cd build cmake -D CMAKE_INSTALL_PREFIX=/path/to/some/staging/folder \ -D OSG_COMPILE_FRAMEWORKS=ON \ -D OSG_PLUGIN_SEARCH_INSTALL_DIR_FOR_PLUGINS=OFF \ .. make make install sudo mkdir -p "/Library/Application Support/OpenSceneGraph/PlugIns" ``` Enter the staging path you chose for the CMAKE_INSTALL_PREFIX option above. Now move all .frameworks from the lib/ folder in the staging area to /Library/Frameworks. Move the files in the osgPlugins folder in the lib/ folder to /Library/Application Support/OpenSceneGraph/PlugIns. The bin/ executables can be left where they are, we don't need them. Next up is **libzip**. Get the latest tarball at: http://nih.at/libzip/ Double-click the source tarball to unpack it. In a new Terminal cd to the source folder and: ``` ./configure --disable-dependency-tracking --disable-shared CFLAGS=-Os make sudo make install ``` Then it's time for **osgEarth**. Downloads are also on github: http://github.com/gwaldron/osgearth/tags Download a tarball for the latest stable release (sorting can be confusing here). Double-click the source tarball to unpack it. This one also needs an intermediate staging area. Choose a folder similar to OSG. In a new Terminal cd to the source folder and: ``` mkdir build cd build export PATH="/path/to/osg/staging/folder/bin:$PATH" cmake -D CMAKE_INSTALL_PREFIX=/path/to/some/staging/folder \ -D CMAKE_BUILD_TYPE=MinSizeRel \ -D OSGEARTH_BUILD_FRAMEWORKS=true \ .. make make install sudo mkdir -p "/Library/Application Support/OpenSceneGraph/Headers" ``` Enter the staging path you chose for the CMAKE_INSTALL_PREFIX option above. Also enter the OSG staging path /bin folder in the export above. Move all the .frameworks from the lib/ folder to /Library/Frameworks. Move the files in the osgPlugins folder in the lib/ folder to /Library/Application Support/OpenSceneGraph/PlugIns. Move the osgEarthDrivers folder in the include/ folder to /Library/Application Support/OpenSceneGraph/Headers. And as for OSG, you can leave the bin/ executables where they are. == QGIS source == Unzip the QGIS source tarball to a working folder of your choice (/usr/somewhere is not a good choice as it's hidden and requires root privileges). If you are reading this from the source, you've already done this. If you want to experiment with the latest development sources, go to the github QGIS project page: http://github.com/qgis/Quantum-GIS It should default to the master branch. Click the __Downloads__ button and select __Download .tar.gz__. Double-click the tarball to unzip it. == Configure the build == CMake supports out of source build so we will create a 'build' dir for the build process. OS X uses ${HOME}/Applications as a standard user app folder (it gives it the system app folder icon). If you have the correct permissions you may want to build straight into your /Applications folder. The instructions below assume you are building into a ${HOME}/Applications directory. In a Terminal cd to the qgis source folder previously downloaded, then: ``` mkdir build cd build cmake -D CMAKE_INSTALL_PREFIX=~/Applications \ -D CMAKE_BUILD_TYPE=MinSizeRel -D ENABLE_TESTS=FALSE \ -D WITH_INTERNAL_SPATIALITE=FALSE -D WITH_PYSPATIALITE=FALSE \ -D QWT_LIBRARY=/usr/local/qwt-5.2.2/lib/libqwt.dylib \ -D QWT_INCLUDE_DIR=/usr/local/qwt-5.2.2/include \ -D BISON_EXECUTABLE=/usr/local/bin/bison \ .. ``` This will automatically find and use the previously installed frameworks, and the GRASS application if installed. Remember to change the Qwt version if a different version was installed. __Snow Leopard note:__ To handle 32-bit Qt (Carbon), create a 32bit python wrapper script and add arch flags to the configuration: ``` sudo cat >/usr/local/bin/python32 <