% vim: set textwidth=78 autoindent:

% when the revision of a section has been finalized,
% comment out the following line:
% \updatedisclaimer

\section{Installation Guide}

The following chapters provide build and installation information for QGIS Version 1.6. This document
corresponds almost to a LATEX conversion of the INSTALL.t2t file coming with the QGIS sources from
November, 29th 2010.
A current version is also available at the wiki, see: http://www.qgis.org/wiki/Installation\_Guide

\hypertarget{toc2}{}
\subsection{Overview}
QGIS, like a number of major projects (eg. KDE 4.0), uses CMake
(\htmladdnormallink{http://www.cmake.org}{http://www.cmake.org}) for building from source.

Following a summary of the required dependencies for building:

Required build tools:

\begin{itemize}
\item CMake $>$= 2.6.0
\item Flex
\item Bison
\end{itemize}


Required build deps:

\begin{itemize}
\item Qt $>$= 4.4.0
\item Proj $>$= 4.4.x
\item GEOS $>$= 3.0
\item Sqlite3 $>$= 3.0.0
\item GDAL/OGR $>$= 1.4.x
\item Qwt $>$= 5.0
\end{itemize}


Optional dependencies:

\begin{itemize}
\item for GRASS plugin - GRASS $>$= 6.0.0 (libraries compiled with exceptions support on Linux 32bit)
\item for georeferencer - GSL $>$= 1.8
\item for postgis support and SPIT plugin - PostgreSQL $>$= 8.0.x
\item for gps plugin - expat $>$= 1.95 and gpsbabel
\item for mapserver export and PyQGIS - Python $>$= 2.3 (2.5+ preferred)
\item for python support - SIP $>$= 4.8, PyQt $>$= must match Qt version
\item for qgis mapserver - FastCGI
\end{itemize}



\hypertarget{toc3}{}
\subsection{Building on GNU/Linux}
\hypertarget{toc4}{}
\subsubsection{Building QGIS with Qt 4.x}
\textbf{Requires:} Ubuntu / Debian derived distro

These notes are for Ubuntu - other versions and Debian derived distros may
require slight variations in package names.

These notes are for if you want to build QGIS from source. One of the major
aims here is to show how this can be done using binary packages for \textbf{*all*}
dependencies - building only the core QGIS stuff from source. I prefer this
approach because it means we can leave the business of managing system packages
to apt and only concern ourselves with coding QGIS! 

This document assumes you have made a fresh install and have a 'clean' system.
These instructions should work fine if this is a system that has already been
in use for a while, you may need to just skip those steps which are irrelevant
to you.

/!$\backslash$ \textbf{Note:} Refer to the section ''Building Debian packages'' for building 
debian packages.  Unless you plan to develop on QGIS, that is probably the
easiest option to compile and install QGIS.

\hypertarget{toc5}{}
\subsubsection{Prepare apt}
The packages qgis depends on to build are available in the "universe" component
of Ubuntu. This is not activated by default, so you need to activate it:

1. Edit your /etc/apt/sources.list file.  
2. Uncomment the all the lines starting with "deb"

Also you will need to be running (K)Ubuntu 'edgy' or higher in order for 
all dependencies to be met.

Now update your local sources database with \texttt{sudo apt-get update} 

\hypertarget{toc6}{}
\subsubsection{Install build dependencies}
\begin{center}\begin{tabular}{|l|l|}
\hline \textbf{Distribution} & \textbf{install command for packages} \\
hardy & apt-get install  bison cmake fcgi-dev flex grass-dev libexpat1-dev \\
& libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libqt4-core libqt4-dev libqt4-gui \\
& libqt4-sql libsqlite3-dev proj pyqt4-dev-tools python python-dev python-qt4 \\
& python-qt4-dev python-sip4 python-sip4-dev sip4 \\
\hline intrepid & apt-get install  bison cmake flex grass-dev \\
& libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev \\
& libqt4-core libqt4-dev libqt4-gui libqt4-sql libqwt5-qt4-dev libsqlite3-dev \\
& proj pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip4 \\
& python-sip4-dev sip4 \\
\hline jaunty & apt-get install  bison cmake flex grass-dev libexpat1-dev \\
& libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libqt4-core libqt4-dev \\
& libqt4-gui libqt4-sql libqwt5-qt4-dev libsqlite3-dev proj pyqt4-dev-tools python \\
& python-dev python-qt4 python-qt4-dev python-sip4 python-sip4-dev sip4 \\
\hline karmic & apt-get install  bison cmake flex grass-dev libexpat1-dev \\
& libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libqt4-core libqt4-dev \\
& libqt4-gui libqt4-sql libqwt5-qt4-dev libsqlite3-dev proj pyqt4-dev-tools python \\
& python-dev python-qt4 python-qt4-dev python-sip4 python-sip4-dev sip4 \\
\hline lenny & apt-get install  bison cmake flex grass-dev libexpat1-dev libfcgi-dev \\
& libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libqt4-dev libqwt5-qt4-dev \\
& libsqlite3-dev pkg-config proj pyqt4-dev-tools python python-dev python-qt4 \\
& python-qt4-dev python-sip4-dev sip4 \\
\hline lucid & apt-get install  bison cmake flex grass-dev libexpat1-dev \\
& libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev \\
& libqwt5-qt4-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python \\
& python-dev python-qt4 python-qt4-dev python-sip python-sip-dev \\
\hline maverick & apt-get install  bison cmake flex grass-dev libexpat1-dev \\
& libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev \\
& libqtwebkit-dev libqwt5-qt4-dev libspatialite-dev libsqlite3-dev pkg-config \\
& pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip \\
& python-sip-dev \\
\hline sid & apt-get install  bison cmake flex grass-dev libexpat1-dev libfcgi-dev \\
& libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev \\
& libqwt5-qt4-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python \\
& python-dev python-qt4 python-qt4-dev python-sip python-sip-dev \\
\hline squeeze & apt-get install  bison cmake flex grass-dev libexpat1-dev \\
& libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev \\
& libqwt5-qt4-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python \\
& python-dev python-qt4 python-qt4-dev python-sip python-sip-dev \\
\hline \end{tabular}\end{center}

(extracted from the respective control files in \texttt{debian/})

/!$\backslash$ \textbf{A Special Note:} If you are following this set of instructions on
a system where you already have Qt3 development tools installed, there will
be a conflict between Qt3 tools and Qt4 tools. For example, qmake will
point to the Qt3 version not the Qt4. Ubuntu Qt4 and Qt3 packages are
designed to live alongside each other. This means that for example if you
have them both installed you will have three qmake exe's:

\begin{verbatim}
/usr/bin/qmake -> /etc/alternatives/qmake 
/usr/bin/qmake-qt3
/usr/bin/qmake-qt4 
\end{verbatim}

The same applies to all other Qt binaries. You will notice above that the
canonical 'qmake' is managed by apt alternatives, so before we start to
build QGIS, we need to make Qt4 the default. To return Qt3 to default later
you can use this same process.

You can use apt alternatives to correct this so that the Qt4 version of
applications is used in all cases:

\begin{verbatim}
sudo update-alternatives --config qmake
sudo update-alternatives --config uic 
sudo update-alternatives --config designer 
sudo update-alternatives --config assistant 
sudo update-alternatives --config qtconfig 
sudo update-alternatives --config moc 
sudo update-alternatives --config lupdate 
sudo update-alternatives --config lrelease 
sudo update-alternatives --config linguist 
\end{verbatim}

Use the simple command line dialog that appears after running each of the
above commands to select the Qt4 version of the relevant applications.

/!$\backslash$ \textbf{Note:} For python language bindings SIP $>$= 4.5 and PyQt4 $>$= 4.1 is required! Some stable GNU/Linux
distributions (e.g. Debian or SuSE) only provide SIP $<$ 4.5 and PyQt4 $<$ 4.1. To include support for python 
language bindings you may need to build and install those packages from source.

\hypertarget{toc7}{}
\subsubsection{Setup ccache (Optional)}
You should also setup ccache to speed up compile times:

\begin{verbatim}
cd /usr/local/bin 
sudo ln -s /usr/bin/ccache gcc 
sudo ln -s /usr/bin/ccache g++ 
\end{verbatim}

\hypertarget{toc8}{}
\subsubsection{Prepare your development environment}
As a convention I do all my development work in \$HOME/dev/$<$language$>$, so in
this case we will create a work environment for C++ development work like
this:

\begin{verbatim}
mkdir -p ${HOME}/dev/cpp 
cd ${HOME}/dev/cpp 
\end{verbatim}

This directory path will be assumed for all instructions that follow.

\hypertarget{toc9}{}
\subsubsection{Check out the QGIS Source Code}
There are two ways the source can be checked out. Use the anonymous method
if you do not have edit privaleges for the QGIS source repository, or use
  the developer checkout if you have permissions to commit source code
  changes.

1. Anonymous Checkout

\begin{verbatim}
cd ${HOME}/dev/cpp 
svn co https://svn.osgeo.org/qgis/trunk/qgis qgis
\end{verbatim}

2. Developer Checkout

\begin{verbatim}
cd ${HOME}/dev/cpp 
svn co --username <yourusername> https://svn.osgeo.org/qgis/trunk/qgis qgis 
\end{verbatim}

The first time you check out the source you will be prompted to accept the
qgis.org certificate. Press 'p' to accept it permanently:

\begin{verbatim}
Error validating server certificate for 'https://svn.qgis.org:443':
   - The certificate is not issued by a trusted authority. Use the
     fingerprint to validate the certificate manually!  Certificate
     information:
   - Hostname: svn.qgis.org
   - Valid: from Apr  1 00:30:47 2006 GMT until Mar 21 00:30:47 2008 GMT
   - Issuer: Developer Team, Quantum GIS, Anchorage, Alaska, US
   - Fingerprint:
     2f:cd:f1:5a:c7:64:da:2b:d1:34:a5:20:c6:15:67:28:33:ea:7a:9b (R)eject,
     accept (t)emporarily or accept (p)ermanently?  
\end{verbatim}

\hypertarget{toc10}{}
\subsubsection{Starting the compile}
I compile my development version of QGIS into my \~{}/apps directory to avoid
conflicts with Ubuntu packages that may be under /usr. This way for example
you can use the binary packages of QGIS on your system along side with your
development version. I suggest you do something similar:

\begin{verbatim}
mkdir -p ${HOME}/apps 
\end{verbatim}

Now we create a build directory and run ccmake:

\begin{verbatim}
cd qgis
mkdir build
cd build
ccmake ..
\end{verbatim}

When you run ccmake (note the .. is required!), a menu will appear where 
you can configure various aspects of the build. If you do not have root
access or do not want to overwrite existing QGIS installs (by your
packagemanager for example), set the CMAKE\_BUILD\_PREFIX to somewhere you
have write access to (I usually use /home/timlinux/apps). Now press
'c' to configure, 'e' to dismiss any error messages that may appear.
and 'g' to generate the make files. Note that sometimes 'c' needs to 
be pressed several times before the 'g' option becomes available.
After the 'g' generation is complete, press 'q' to exit the ccmake 
interactive dialog.

Now on with the build:

\begin{verbatim}
make
make install
\end{verbatim}

It may take a little while to build depending on your platform.

\hypertarget{toc11}{}
\subsubsection{Building Debian packages}
Instead of creating a personal installation as in the previous step you can
also create debian package.  This is done from the qgis root directory, where
you'll find a debian directory.

First you need to install the debian packaging tools once:

\begin{verbatim}
apt-get install build-essential
\end{verbatim}

First you need to create an changelog entry for your distribution. For example for Ubuntu Lucid:

\begin{verbatim}
dch -l ~lucid  --force-distribution --distribution lucid "lucid build"
\end{verbatim}

The QGIS packages will be created with:

\begin{verbatim}
dpkg-buildpackage -us -uc -b
\end{verbatim}

/!$\backslash$ \textbf{Note:} If \texttt{dpkg-buildpackage} complains about unmet build dependencies
you can install them using \texttt{apt-get} and re-run the command.

/!$\backslash$ \textbf{Note:} If you have \texttt{libqgis1-dev} installed, you need to remove it first
using \texttt{dpkg -r libqgis1-dev}.  Otherwise \texttt{dpkg-buildpackage} will complain about a
build conflict.

The packages are created in the parent directory (ie. one level up).
Install them using dpkg.  E.g.:

\begin{verbatim}
sudo debi
\end{verbatim}

\hypertarget{toc12}{}
\subsubsection{Running QGIS}
Now you can try to run QGIS:

\begin{verbatim}
$HOME/apps/bin/qgis 
\end{verbatim}

If all has worked properly the QGIS application should start up and appear
on your screen.

\hypertarget{toc13}{}
\subsubsection{A practical case: Building QGIS and GRASS from source on Ubuntu with ECW and MrSID formats support}
The following procedure has been tested on Ubuntu 8.04, 8.10 and 9.04 32bit. If you want 
to use different versions of the software (gdal, grass, qgis), just make the 
necessary adjustments to the following code. This guide assumes that you don't have 
installed any previous version of gdal, grass and qgis.

\minisec{Step 1: install base packages}
First you need to install the necessary packages required to download the source 
code and compile it. Open the terminal and issue the following command:

\begin{verbatim}
sudo apt-get install build-essential g++ subversion
\end{verbatim}

\minisec{Step 2: compile and install the ecw libraries}
Go to the ERDAS web site \htmladdnormallink{http://www.erdas.com/}{http://www.erdas.com/} and follow the links
"'''products --$>$ ECW JPEG2000 Codec SDK --$>$ downloads'''" 
then download the "'''Image Compression SDK Source Code 3.3'''" (you'll need to make a registration 
and accept a license).

Uncompress the arquive in a proper location (this guide assumes 
that all the downloaded source code will be placed in the user home) 
and the enter the newly created folder

\begin{verbatim}
cd /libecwj2-3.3
\end{verbatim}

Compile the code with the standard commands

\begin{verbatim}
./configure
\end{verbatim}

then

\begin{verbatim}
make
\end{verbatim}

then

\begin{verbatim}
sudo make install
\end{verbatim}

leave the folder 

\begin{verbatim}
cd ..
\end{verbatim}

\minisec{Step 3: download the MrSID binaries}
Go to the LIZARDTECH web site \htmladdnormallink{http://www.lizardtech.com/}{http://www.lizardtech.com/} and follow the links
"'''download --$>$ Developer SDKs'''", 
then download the "'''GeoExpress SDK for Linux (x86) - gcc 4.1 32-bit'''"
(you'll need to make a registration and accept a license).

Uncompress the downloaded file. The resulting directory name should be similar to "Geo\_DSDK-7.0.0.2167"

\minisec{Step 4: compile and install the gdal libraries}
Download the latest gdal source code

\begin{verbatim}
svn checkout https://svn.osgeo.org/gdal/trunk/gdal gdal
\end{verbatim}

then copy a few files from the MrSID binaries folder to the folder with the gdal source code
('''replace "USERNAME" with your actual account username''')

\begin{verbatim}
cp /home/USERNAME/Geo_DSDK-7.0.0.2167/include/*.* /home/USERNAME/gdal/frmts/mrsid/
\end{verbatim}

enter the gdal source code folder

\begin{verbatim}
cd /gdal
\end{verbatim}

and run configure with a few specific parameters

\begin{verbatim}
./configure --without-grass --with-mrsid=../Geo_DSDK-7.0.0.2167 --without-jp2mrsid
\end{verbatim}

at the end of the configuration process you should read something like

\begin{verbatim}
...
GRASS support:             no
...
...
...
ECW support:               yes
MrSID support              yes			
...
\end{verbatim}

then compile normally

\begin{verbatim}
make
\end{verbatim}

and

\begin{verbatim}
sudo make install
\end{verbatim}

finish the process by creating the necessary links to the most recent shared libraries

\begin{verbatim}
sudo ldconfig
\end{verbatim}

at this point you may want to check if gdal was compiled correctly with MrSID and ECW
support by issuing one (or both) of the following commands

\begin{verbatim}
gdalinfo --formats | grep 'ECW'
\end{verbatim}

\begin{verbatim}
gdalinfo --formats | grep 'SID'
\end{verbatim}

leave the folder 

\begin{verbatim}
cd ..
\end{verbatim}

\minisec{Step 5: compile and install GRASS}
Before downloading and compile GRASS source code you need to install a few
other libraries and programs. We can do this trough apt

\begin{verbatim}
sudo apt-get install flex bison libreadline5-dev libncurses5-dev lesstif2-dev debhelper \
dpatch libtiff4-dev tcl8.4-dev tk8.4-dev fftw-dev xlibmesa-gl-dev libfreetype6-dev \
autoconf2.13 autotools-dev libgdal1-dev proj libjpeg62-dev libpng12-dev libpq-dev \
unixodbc-dev doxygen fakeroot cmake python-dev python-qt4-common python-qt4-dev \
python-sip4 python2.5-dev sip4 libglew1.5-dev libxmu6 libqt4-dev libgsl0-dev \
python-qt4 swig python-wxversion python-wxgtk2.8 libwxgtk2.8-0 libwxbase2.8-0 tcl8.4-dev \
tk8.4-dev tk8.4 libfftw3-dev libfftw3-3
\end{verbatim}

At this point we can get the GRASS source code: you may want to download it
trough svn or maybe you want just to download the latest available source code arquive.
For example the GRASS 6.4rc4 is available at \htmladdnormallink{http://grass.itc.it/grass64/source/grass-6.4.0RC4.tar.gz}{http://grass.itc.it/grass64/source/grass-6.4.0RC4.tar.gz}

Uncompress the arquive, enter the newly created folder and run configure with a few specific parameters

\begin{verbatim}
CFLAGS="-fexceptions" ./configure --with-tcltk-includes=/usr/include/tcl8.4 \
--with-proj-share=/usr/share/proj --with-gdal=/usr/local/bin/gdal-config \
--with-python=/usr/bin/python2.5-config
\end{verbatim}

The additional gcc option -fexceptions is necessary to enable exceptions support in GRASS libraries. It is currently the only way to avoid QGIS crashes if a fatal error happens in GRASS library. See also \htmladdnormallink{http://trac.osgeo.org/grass/ticket/869}{http://trac.osgeo.org/grass/ticket/869}

Then as usual (it will take a while)

\begin{verbatim}
make
\end{verbatim}

and

\begin{verbatim}
sudo make install
\end{verbatim}

leave the folder 

\begin{verbatim}
cd ..
\end{verbatim}

you have now compiled and installed GRASS (also with the new wxpyhton interface) so you
may want to give it a try

\begin{verbatim}
grass64 -wxpython
\end{verbatim}

\minisec{Step 6: compile and install QGIS}
As for GRASS you can obtain the QGIS source code from different sources,
for instance from svn or just by downloading one of the source code arquives available
at \htmladdnormallink{http://www.qgis.org/download/sources.html}{http://www.qgis.org/download/sources.html}

For example download the QGIS 1.1.0 source code here \htmladdnormallink{http://download.osgeo.org/qgis/src/qgis\_1.1.0.tar.gz}{http://download.osgeo.org/qgis/src/qgis\_1.1.0.tar.gz}

uncompress the arquive and enter the newly created folder

\begin{verbatim}
cd /qgis_1.1.0
\end{verbatim}

then run ccmake

\begin{verbatim}
ccmake .
\end{verbatim}

press the "c" key, then when the option list will appear we need to manually
configure the "GRASS\_PREFIX" parameter. Scroll down until the "GRASS\_PREFIX" will appear, 
press enter and manually set it to

\begin{verbatim}
/usr/local/grass-6.4.0RC4
\end{verbatim}

then press enter again.

Press the "c" again and the option "Press [g] to generate and exit" will appear.
Press the "g" key to generate and exit.

then as usual (it will take a while)

\begin{verbatim}
make
\end{verbatim}

and

\begin{verbatim}
sudo make install
\end{verbatim}

At the end of the process you should have QGIS and GRASS working with MrSID and ECW
raster format support.

To run QGIS just use this command 

\begin{verbatim}
qgis
\end{verbatim}


\hypertarget{toc14}{}
\subsection{Building on Windows}
\hypertarget{toc15}{}
\minisec{Building with Microsoft Visual Studio}
This section describes how to build QGIS using Visual Studio on Windows.  This
is currently also who the binary QGIS packages are made (earlier versions used
MinGW).

This section describes the setup required to allow Visual Studio to be used to
build QGIS. 

\minisec{Visual C++ Express Edition}
The free (as in free beer) Express Edition installer is available under:

	\begin{quotation}
\htmladdnormallink{http://download.microsoft.com/download/d/c/3/dc3439e7-5533-4f4c-9ba0-8577685b6e7e/vcsetup.exe}{http://download.microsoft.com/download/d/c/3/dc3439e7-5533-4f4c-9ba0-8577685b6e7e/vcsetup.exe}
	\end{quotation}

The optional products are not necessary.  In the process the Windows SDKs for
Visual Studio 2008 will also be downloaded and installed.

You also need the Microsoft Windows Server� 2003 R2 Platform SDK (for setupapi):

	\begin{quotation}
\htmladdnormallink{http://download.microsoft.com/download/f/a/d/fad9efde-8627-4e7a-8812-c351ba099151/PSDK-x86.exe}{http://download.microsoft.com/download/f/a/d/fad9efde-8627-4e7a-8812-c351ba099151/PSDK-x86.exe}
	\end{quotation}

You only need Microsoft Windows Core SDK / Build Environment (x86 32-Bit).

\minisec{Other tools and dependencies}
Download and install following packages:

\begin{center}\begin{tabular}{|l|l|}
\hline \textbf{Tool} & \textbf{Website} \\
\hline CMake & \htmladdnormallink{http://www.cmake.org/files/v2.8/cmake-2.8.2-win32-x86.exe}{http://www.cmake.org/files/v2.8/cmake-2.8.2-win32-x86.exe} \\
\hline Flex & \htmladdnormallink{http://gnuwin32.sourceforge.net/downlinks/flex.php}{http://gnuwin32.sourceforge.net/downlinks/flex.php} \\
\hline Bison & \htmladdnormallink{http://gnuwin32.sourceforge.net/downlinks/bison.php}{http://gnuwin32.sourceforge.net/downlinks/bison.php} \\
\hline SVN & \htmladdnormallink{http://sourceforge.net/projects/win32svn/files/1.6.13/Setup-Subversion-1.6.13.msi/download}{http://sourceforge.net/projects/win32svn/files/1.6.13/Setup-Subversion-1.6.13.msi/download} \\
\hline OSGeo4W & \htmladdnormallink{http://download.osgeo.org/osgeo4w/osgeo4w-setup.exe}{http://download.osgeo.org/osgeo4w/osgeo4w-setup.exe} \\
\hline \end{tabular}\end{center}

OSGeo4W does not only provide ready packages for the current QGIS release and
nightly builds of the trunk, but also offers most of the dependencies needs to
build it.

For the QGIS build you need to install following packages from OSGeo4W (select
\textit{Advanced Installation}):

\begin{itemize}
\item expat
\item fcgi
\item gdal17
\item grass
\item gsl-devel
\item iconv
\item pyqt4
\item qt4-devel
\item qwt5-devel-qt4
\item sip
\end{itemize}


This will also select packages the above packages depend on.

Additionally QGIS also needs the include file \texttt{unistd.h}, which normally
doesn't exist on Windows.  It's shipped with Flex/Bison in \texttt{GnuWin32$\backslash$include}
and needs to be copied into the \texttt{VC$\backslash$include} directory of your Visual C++
installation.

Earlier versions of this document also covered how to build all above
dependencies.  If you're interested in that, check the history of this page in the Wiki
or the SVN repository.

\minisec{Setting up the Visual Studio project with CMake}
To start a command prompt with an environment that both has the VC++ and the OSGeo4W
variables create the following batch file (assuming the above packages were
installed in the default locations):

\begin{verbatim}
@echo off
path %SYSTEMROOT%\system32;%SYSTEMROOT%;%SYSTEMROOT%\System32\Wbem;%PROGRAMFILES\
%\CMake 2.8\bin;%PROGRAMFILES%\subversion\bin;%PROGRAMFILES%\GnuWin32\bin
set PYTHONPATH=

set VS90COMNTOOLS=%PROGRAMFILES%\Microsoft Visual Studio 9.0\Common7\Tools\
call "%PROGRAMFILES%\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86

set INCLUDE=%INCLUDE%;%PROGRAMFILES%\Microsoft Platform SDK for Windows Server \
2003 R2\include
set LIB=%LIB%;%PROGRAMFILES%\Microsoft Platform SDK for Windows Server 2003 R2\lib

set OSGEO4W_ROOT=C:\OSGeo4W
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"

@set GRASS_PREFIX=c:/OSGeo4W/apps/grass/grass-6.4.0
@set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\apps\gdal-17\include;%OSGEO4W_ROOT%\include
@set LIB=%LIB%;%OSGEO4W_ROOT%\apps\gdal-17\lib;%OSGEO4W_ROOT%\lib

@cmd
\end{verbatim}

Start the batch file and on the command prompt checkout the QGIS source from
svn to the source directory \texttt{qgis-trunk}:

\begin{verbatim}
svn co https://svn.osgeo.org/qgis/trunk/qgis qgis-trunk
\end{verbatim}

Create a 'build' directory somewhere. This will be where all the build output
will be generated.

Now run \texttt{cmake-gui} and in the \textit{Where is the source code:} box, browse to
the top level QGIS directory.

In the \textit{Where to build the binaries:} box, browse to the 'build' directory you
created.

Hit \texttt{Configure} to start the configuration and select \texttt{Visual Studio 9 2008}
and keep \texttt{native compilers} and click \texttt{Finish}.

The configuration should complete without any further questions and allow you to
click \texttt{Generate}.

Now close \texttt{cmake-gui} and continue on the command prompt by starting
\texttt{vcexpress}.  Use File / Open / Project/Solutions and open the
qgis-x.y.z.sln File in your project directory.

You probably want to change the \texttt{Solution Configuration} from \texttt{Debug}
to \texttt{RelWithDebInfo} (Release with Debug Info)  or \texttt{Release} before you
build QGIS using the ALL\_BUILD target.

After the build completed you should install QGIS using the INSTALL target.

Install QGIS by building the INSTALL project. By default this will install to
c:$\backslash$Program Files$\backslash$qgis$<$version$>$ (this can be changed by changing the
CMAKE\_INSTALL\_PREFIX variable in cmake-gui). 

You will also either need to add all the dependency DLLs to the QGIS install
directory or add their respective directories to your PATH.

\minisec{Packaging}
To create a windows 'all in one' standalone  package ''under ubuntu'' (yes you
read correctly) do the following:

\begin{verbatim}
sudo apt-get install nsis
\end{verbatim}

Now 

\begin{verbatim}
cd qgis/ms-windows/osgeo4w
\end{verbatim}

And run the nsis creation script:

\begin{verbatim}
creatensis.pl
\end{verbatim}

When the script completes, it should have created a QGIS installer executable
in the ms-windows directory.

\minisec{Osgeo4w packaging}
The actual packaging process is currently not documented, for now please take a
look at:

\textit{ms-windows/osgeo4w/package.cmd}

\hypertarget{toc16}{}
\subsubsection{Building using MinGW}
\textbf{Note:} This section might be outdated as nowadays Visual C++ is use to build
the "official" packages.

\textbf{Note:} For a detailed account of building all the dependencies yourself you
can visit Marco Pasetti's website here:

\htmladdnormallink{http://www.webalice.it/marco.pasetti/qgis+grass/BuildFromSource.html}{http://www.webalice.it/marco.pasetti/qgis+grass/BuildFromSource.html}

Read on to use the simplified approach with pre-built libraries...

\minisec{MSYS}
MSYS provides a unix style build environment under windows. We have created a
zip archive that contains just about all dependencies.

Get this: 

\htmladdnormallink{http://download.osgeo.org/qgis/win32/msys.zip}{http://download.osgeo.org/qgis/win32/msys.zip}

and unpack to c:$\backslash$msys

If you wish to prepare your msys environment yourself rather than using 
our pre-made one, detailed instructions are provided elsewhere in this
document.

\minisec{Qt}
Download Qt opensource precompiled edition exe and install (including the
download and install of mingw) from here:

\htmladdnormallink{http://qt.nokia.com/downloads/}{http://qt.nokia.com/downloads/}

When the installer will ask for MinGW, you don't need to download and install
it, just point the installer to c:$\backslash$msys$\backslash$mingw

When Qt installation is complete:

Edit C:$\backslash$Qt$\backslash$4.7.0$\backslash$bin$\backslash$qtvars.bat and add the following lines:

\begin{verbatim}
set PATH=%PATH%;C:\msys\local\bin;c:\msys\local\lib 
set PATH=%PATH%;"C:\Program Files\Subversion\bin" 
\end{verbatim}

I suggest you also add C:$\backslash$Qt$\backslash$4.7.0$\backslash$bin$\backslash$ to your Environment Variables Path in
the windows system preferences.

If you plan to do some debugging, you'll need to compile debug version of Qt:
C:$\backslash$Qt$\backslash$4.7.0$\backslash$bin$\backslash$qtvars.bat compile\_debug

Note: there is a problem when compiling debug version of Qt 4.7, the script ends with
this message  "mingw32-make: *** No rule to make target `debug'.  Stop.". To 
compile the debug version you have to go out of src directory and execute the
following command:

\begin{verbatim}
c:\Qt\4.7.0 make 
\end{verbatim}

\minisec{Flex and Bison}
Get Flex
\htmladdnormallink{http://sourceforge.net/project/showfiles.php?group\_id=23617\&package\_id=16424}{http://sourceforge.net/project/showfiles.php?group\_id=23617\&package\_id=16424}
(the zip bin) and extract it into c:$\backslash$msys$\backslash$mingw$\backslash$bin

\minisec{Python stuff (optional)}
Follow this section in case you would like to use Python bindings for QGIS.  To
be able to compile bindings, you need to compile SIP and PyQt4 from sources as
their installer doesn't include some development files which are necessary.

\paragraph{}\textbf{Download and install Python - use Windows installer}\\

(It doesn't matter to what folder you'll install it)

\htmladdnormallink{http://python.org/download/}{http://python.org/download/}

\paragraph{}\textbf{Download SIP and PyQt4 sources}\\

\url{http://www.riverbankcomputing.com/software/sip/download}
\url{http://www.riverbankcomputing.com/software/pyqt/download}

Extract each of the above zip files in a temporary directory. Make sure
to get versions that match your current Qt installed version.

\paragraph{}\textbf{Compile SIP}\\

\begin{verbatim}
c:\Qt\4.7.0\bin\qtvars.bat 
python configure.py -p win32-g++ 
make 
make install 
\end{verbatim}

\paragraph{}\textbf{Compile PyQt}\\

\begin{verbatim}
c:\Qt\4.7.0\bin\qtvars.bat 
python configure.py 
make 
make install 
\end{verbatim}

\paragraph{}\textbf{Final python notes}\\

/!$\backslash$ You can delete the directories with unpacked SIP and PyQt4 sources after a
successfull install, they're not needed anymore.

\minisec{Subversion}
In order to check out QGIS sources from the repository, you need Subversion
client. This installer should work fine:

\htmladdnormallink{http://www.sliksvn.com/pub/Slik-Subversion-1.6.13-win32.msi}{http://www.sliksvn.com/pub/Slik-Subversion-1.6.13-win32.msi}

\minisec{CMake}
CMake is build system used by Quantum GIS. Download it from here:

\htmladdnormallink{http://www.cmake.org/files/v2.8/cmake-2.8.2-win32-x86.exe}{http://www.cmake.org/files/v2.8/cmake-2.8.2-win32-x86.exe}

\minisec{QGIS}
Start a cmd.exe window ( Start -$>$ Run -$>$ cmd.exe ) Create development 
directory and move into it

\begin{verbatim}
md c:\dev\cpp 
cd c:\dev\cpp 
\end{verbatim}

Check out sources from SVN:

For svn trunk:

\begin{verbatim}
svn co https://svn.osgeo.org/qgis/trunk/qgis 
\end{verbatim}

For svn 1.5 branch

\begin{verbatim}
svn co https://svn.osgeo.org/qgis/branches/Release-1_5_0 qgis1.5.0
\end{verbatim}

\minisec{Compiling}
As a background read the generic building with CMake notes at the end of 
this document.

Start a cmd.exe window ( Start -$>$ Run -$>$ cmd.exe ) if you don't have one
already.  Add paths to compiler and our MSYS environment:

\begin{verbatim}
c:\Qt\4.7.0\bin\qtvars.bat 
\end{verbatim}

For ease of use add c:$\backslash$Qt$\backslash$4.7.0$\backslash$bin$\backslash$ to your system path in system
properties so you can just type qtvars.bat when you open the cmd console.
Create build directory and set it as current directory:

\begin{verbatim}
cd c:\dev\cpp\qgis 
md build 
cd build 
\end{verbatim}

\minisec{Configuration}
\begin{verbatim}
cmakesetup ..  
\end{verbatim}

\textbf{Note:} You must include the '..' above.

Click 'Configure' button.  When asked, you should choose 'MinGW Makefiles' as
generator.

There's a problem with MinGW Makefiles on Win2K. If you're compiling on this
platform, use 'MSYS Makefiles' generator instead.

All dependencies should be picked up automatically, if you have set up the
Paths correctly. The only thing you need to change is the installation
destination (CMAKE\_INSTALL\_PREFIX) and/or set 'Debug'.

For compatibility with NSIS packaging scripts I recommend to leave the install
prefix to its default c:$\backslash$program files$\backslash$

When configuration is done, click 'OK' to exit the setup utility.

\minisec{Compilation and installation}
\begin{verbatim}
 make make install 
\end{verbatim}

\minisec{Run qgis.exe from the directory where it's installed (CMAKE\_INSTALL\_PREFIX)}
Make sure to copy all .dll:s needed to the same directory as the qgis.exe
binary is installed to, if not already done so, otherwise QGIS will complain
about missing libraries when started.

A possibility is to run qgis.exe when your path contains c:$\backslash$msys$\backslash$local$\backslash$bin and
c:$\backslash$msys$\backslash$local$\backslash$lib directories, so the DLLs will be used from that place.

\minisec{Create the installation package: (optional)}
Download and install NSIS from (\htmladdnormallink{http://nsis.sourceforge.net/Main\_Page}{http://nsis.sourceforge.net/Main\_Page})

Now using windows explorer, enter the win\_build directory in your QGIS source
tree. Read the READMEfile there and follow the instructions. Next right click
on qgis.nsi and choose the option 'Compile NSIS Script'. 

\hypertarget{toc17}{}
\subsubsection{Creation of MSYS environment for compilation of Quantum GIS}
\minisec{Initial setup}
\paragraph{}\textbf{MSYS}\\

This is the environment that supplies many utilities from UNIX world in Windows and is needed
by many dependencies to be able to compile.

Download from here:

	\begin{quotation}
\htmladdnormallink{http://puzzle.dl.sourceforge.net/sourceforge/mingw/MSYS-1.0.11-2004.04.30-1.exe}{http://puzzle.dl.sourceforge.net/sourceforge/mingw/MSYS-1.0.11-2004.04.30-1.exe}
	\end{quotation}

Install to \texttt{c:$\backslash$msys}

All stuff we're going to compile is going to get to this directory (resp. its subdirs).

\paragraph{}\textbf{MinGW}\\

Download from here:

	\begin{quotation}
\htmladdnormallink{http://puzzle.dl.sourceforge.net/sourceforge/mingw/MinGW-5.1.3.exe}{http://puzzle.dl.sourceforge.net/sourceforge/mingw/MinGW-5.1.3.exe}
	\end{quotation}

Install to \texttt{c:$\backslash$msys$\backslash$mingw}

It suffices to download and install only \texttt{g++} and \texttt{mingw-make} components.

\paragraph{}\textbf{Flex and Bison}\\

Flex and Bison are tools for generation of parsers, they're needed for GRASS and also QGIS compilation.

Download the following packages:

	\begin{quotation}
\htmladdnormallink{http://gnuwin32.sourceforge.net/downlinks/flex-bin-zip.php}{http://gnuwin32.sourceforge.net/downlinks/flex-bin-zip.php}
	\end{quotation}

	\begin{quotation}
\htmladdnormallink{http://gnuwin32.sourceforge.net/downlinks/bison-bin-zip.php}{http://gnuwin32.sourceforge.net/downlinks/bison-bin-zip.php}
	\end{quotation}

	\begin{quotation}
\htmladdnormallink{http://gnuwin32.sourceforge.net/downlinks/bison-dep-zip.php}{http://gnuwin32.sourceforge.net/downlinks/bison-dep-zip.php}
	\end{quotation}

Unpack them all to \texttt{c:$\backslash$msys$\backslash$local}

\minisec{Installing dependencies}
\paragraph{}\textbf{Getting ready}\\

Paul Kelly did a great job and prepared a package of precompiled libraries for GRASS.
The package currently includes:

\begin{itemize}
\item zlib-1.2.3
\item libpng-1.2.16-noconfig
\item xdr-4.0-mingw2
\item freetype-2.3.4
\item fftw-2.1.5
\item PDCurses-3.1
\item proj-4.5.0
\item gdal-1.4.1
\end{itemize}

It's available for download here:

	\begin{quotation}
\htmladdnormallink{http://www.stjohnspoint.co.uk/grass/wingrass-extralibs.tar.gz}{http://www.stjohnspoint.co.uk/grass/wingrass-extralibs.tar.gz}
	\end{quotation}

Moreover he also left the notes how to compile it (for those interested):

	\begin{quotation}
\htmladdnormallink{http://www.stjohnspoint.co.uk/grass/README.extralibs}{http://www.stjohnspoint.co.uk/grass/README.extralibs}
	\end{quotation}

Unpack the whole package to \texttt{c:$\backslash$msys$\backslash$local}

\paragraph{}\textbf{GRASS}\\

Grab sources from CVS or use a weekly snapshot, see:

	\begin{quotation}
\htmladdnormallink{http://grass.itc.it/devel/cvs.php}{http://grass.itc.it/devel/cvs.php}
	\end{quotation}

In MSYS console go to the directory where you've unpacked or checked out sources
(e.g. \texttt{c:$\backslash$msys$\backslash$local$\backslash$src$\backslash$grass-6.3.cvs})

Run these commands:

\begin{verbatim}
export PATH="/usr/local/bin:/usr/local/lib:$PATH"
./configure --prefix=/usr/local --bindir=/usr/local --with-includes=/usr/local/include \
--with-libs=/usr/local/lib --with-cxx --without-jpeg --without-tiff \
--with-postgres=yes --with-postgres-includes=/local/pgsql/include \
--with-pgsql-libs=/local/pgsql/lib --with-opengl=windows --with-fftw \
--with-freetype --with-freetype-includes=/mingw/include/freetype2 --without-x \
--without-tcltk --enable-x11=no --enable-shared=yes \
--with-proj-share=/usr/local/share/proj
make
make install
\end{verbatim}

It should get installed to \texttt{c:$\backslash$msys$\backslash$local$\backslash$grass-6.3.cvs}

By the way, these pages might be useful:

\begin{itemize}
\item \htmladdnormallink{http://grass.gdf-hannover.de/wiki/WinGRASS\_Current\_Status}{http://grass.gdf-hannover.de/wiki/WinGRASS\_Current\_Status}
\item \htmladdnormallink{http://geni.ath.cx/grass.html}{http://geni.ath.cx/grass.html}
\end{itemize}

\paragraph{}\textbf{GEOS}\\

Download the sources:

	\begin{quotation}
\htmladdnormallink{http://geos.refractions.net/geos-2.2.3.tar.bz2}{http://geos.refractions.net/geos-2.2.3.tar.bz2}
	\end{quotation}

Unpack to e.g. \texttt{c:$\backslash$msys$\backslash$local$\backslash$src}

To compile, I had to patch the sources: in file \texttt{source/headers/timeval.h} line 13.
Change it from:

\begin{verbatim}
#ifdef _WIN32
\end{verbatim}
to:

\begin{verbatim}
#if defined(_WIN32) && defined(_MSC_VER)
\end{verbatim}

Now, in MSYS console, go to the source directory and run:

\begin{verbatim}
./configure --prefix=/usr/local
make
make install
\end{verbatim}

\paragraph{}\textbf{SQLITE}\\

You can use precompiled DLL, no need to compile from source:

Download this archive:

	\begin{quotation}
\htmladdnormallink{http://www.sqlite.org/sqlitedll-3\_3\_17.zip}{http://www.sqlite.org/sqlitedll-3\_3\_17.zip}
	\end{quotation}

and copy sqlite3.dll from it to \texttt{c:$\backslash$msys$\backslash$local$\backslash$lib}

Then download this archive:

	\begin{quotation}
\htmladdnormallink{http://www.sqlite.org/sqlite-source-3\_3\_17.zip}{http://www.sqlite.org/sqlite-source-3\_3\_17.zip}
	\end{quotation}

and copy sqlite3.h to \texttt{c:$\backslash$msys$\backslash$local$\backslash$include}

\paragraph{}\textbf{GSL}\\

Download sources:

	\begin{quotation}
\htmladdnormallink{ftp://ftp.gnu.org/gnu/gsl/gsl-1.9.tar.gz}{ftp://ftp.gnu.org/gnu/gsl/gsl-1.9.tar.gz}
	\end{quotation}

Unpack to \texttt{c:$\backslash$msys$\backslash$local$\backslash$src}

Run from MSYS console in the source directory:

\begin{verbatim}
./configure
make
make install
\end{verbatim}

\paragraph{}\textbf{EXPAT}\\

Download sources:

	\begin{quotation}
\htmladdnormallink{http://dfn.dl.sourceforge.net/sourceforge/expat/expat-2.0.0.tar.gz}{http://dfn.dl.sourceforge.net/sourceforge/expat/expat-2.0.0.tar.gz}
	\end{quotation}

Unpack to \texttt{c:$\backslash$msys$\backslash$local$\backslash$src}

Run from MSYS console in the source directory:

\begin{verbatim}
./configure
make
make install
\end{verbatim}

\paragraph{}\textbf{POSTGRES}\\

We're going to use precompiled binaries. Use the link below for download:

	\begin{quotation}
\url{http://wwwmaster.postgresql.org/download/mirrors-ftp}
	\end{quotation}

copy contents of pgsql directory from the archive to \texttt{c:$\backslash$msys$\backslash$local}

\minisec{Cleanup}
We're done with preparation of MSYS environment. Now you can delete all stuff in \texttt{c:$\backslash$msys$\backslash$local$\backslash$src} - it takes quite a lot
of space and it's not necessary at all.


\hypertarget{toc18}{}
\subsection{MacOS X: building using frameworks and Cmake}
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 (\underline{Tiger}), with a single architecture build.
Included are a few notes for building on Mac OS X 10.5 (\underline{Leopard}) and 10.6 (\underline{Snow Leopard}).
Make sure to read each section completely before typing the first command you see.

\underline{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 $<$return$>$.  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 $<$return$>$.

\underline{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:

\begin{verbatim}
make -j [n]
\end{verbatim}

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

\hypertarget{toc19}{}
\subsubsection{Install Qt4 from .dmg}
You need a minimum of Qt-4.4.0. I suggest getting the latest.

\underline{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.  Qt 4.6+ is recommended for Cocoa.

\underline{PPC note:} There appear to be issues with Qt Cocoa on PPC Macs.  QT Carbon
is recommended on PPC Macs.

\begin{verbatim}
http://qt.nokia.com/downloads
\end{verbatim}

If you want debug frameworks, Qt also provides a dmg with these.  These are in
addition to the non-debug frameworks.

Once downloaded open the dmg and run the installer. Note you need admin
privileges to install.

\underline{Qt note:} Starting in Qt 4.4, libQtCLucene was added, and in 4.5
libQtUiTools was added, both in /usr/lib.  When using a system SDK
these libraries will not be found.  To fix this problem,
add symlinks to /usr/local:

\begin{verbatim}
sudo ln -s /usr/lib/libQtUiTools.a /usr/local/lib/
sudo ln -s /usr/lib/libQtCLucene.dylib /usr/local/lib/
\end{verbatim}

These should then be found automatically on Leopard and above.  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.

\hypertarget{toc20}{}
\subsubsection{Install development frameworks for QGIS dependencies}
Download William Kyngesburye's excellent GDAL Complete package that includes
PROJ, GEOS, GDAL, SQLite3, and image libraries, as frameworks.  There is also
a GSL framework.

\begin{verbatim}
http://www.kyngchaos.com/wiki/software/frameworks
\end{verbatim}

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:

\begin{verbatim}
http://www.kyngchaos.com/wiki/software/postgres 
\end{verbatim}

Also available is a GRASS application:

\begin{verbatim}
http://www.kyngchaos.com/wiki/software/grass
\end{verbatim}

\minisec{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.

\minisec{Additional Dependencies: Expat}
\underline{Snow Leopard note:} Snow Leopard includes a usable expat, so this step is 
not necessary on Snow Leopard.

Get the expat sources:

\begin{verbatim}
http://sourceforge.net/project/showfiles.php?group_id=10127 
\end{verbatim}

Double-click the source tarball to unpack, then, in Terminal.app, cd to the source folder and:

\begin{verbatim}
./configure
make 
sudo make install 
\end{verbatim}

\minisec{Additional Dependencies: Python}
\underline{Leopard and Snow Leopard note:} Leopard and Snow Leopard include a usable
Python 2.5 and 2.6, respectively. So there is no need to install Python on
Leopard and Snow Leopard. You can still install Python from python.org if preferred.

If installing from python.org, make sure you install at least the latest Python 2.x from 

\begin{verbatim}
http://www.python.org/download/
\end{verbatim}

Python 3 is a major change, and may have compatibility issues, so try it at your own risk.

\minisec{Additional Dependencies: SIP}
Retrieve the python bindings toolkit SIP from

\begin{verbatim}
http://www.riverbankcomputing.com/software/sip/download
\end{verbatim}

Double-click the source tarball to unpack it, then, in Terminal.app, cd to the source folder
and (this installs by default into the Python framework, and is appropriate only for 
python.org Python installs):

\begin{verbatim}
python configure.py 
make 
sudo make install 
\end{verbatim}

\underline{Leopard notes}

If building on Leopard, using Leopard's bundled Python, SIP wants to install in the
system path -- this is not a good idea.  Use this configure command instead of the 
basic configure above:

\begin{verbatim}
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
\end{verbatim}

\underline{Snow Leopard notes}

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). If you are using 32-bit Qt (Qt Carbon):

\begin{verbatim}
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
\end{verbatim}

For 64-bit Qt (Qt Cocoa), use this configure line:

\begin{verbatim}
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
\end{verbatim}

\minisec{Additional Dependencies: PyQt}
Retrieve the python bindings toolkit for Qt from

\begin{verbatim}
http://www.riverbankcomputing.com/software/pyqt/download
\end{verbatim}

Double-click the source tarball to unpack it, then, in Terminal.app, cd to the source folder
and (this installs by default into the Python framework, and is appropriate only for
python.org Python installs):

\begin{verbatim}
python configure.py 
yes 
\end{verbatim}

There is a problem with the configuration that needs to be fixed now
(it affects PyQwt compilation later).  Edit pyqtconfig.py and change the qt\_dir line to:

\begin{verbatim}
    'qt_dir': '/usr',
\end{verbatim}

Then continue with compilation and installation (this is a good place to use
parallel compilation, if you can):

\begin{verbatim}
make 
sudo make install 
\end{verbatim}

\underline{Leopard notes}

If building on Leopard, using Leopard's bundled Python, PyQt wants to install
in the system path -- this is not a good idea.  Use this configure command
instead of the basic configure above:

\begin{verbatim}
python configure.py -d /Library/Python/2.5/site-packages -b /usr/local/bin
\end{verbatim}

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.

\underline{Snow Leopard notes}

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).
If you are using 32-bit Qt (Qt Carbon):

\begin{verbatim}
python2.6 configure.py -d /Library/Python/2.6/site-packages -b /usr/local/bin \
--use-arch i386
\end{verbatim}

For 64-bit Qt (Qt Cocoa), use this configure line:

\begin{verbatim}
python2.6 configure.py -d /Library/Python/2.6/site-packages -b /usr/local/bin \
--use-arch x86_64
\end{verbatim}

\minisec{Additional Dependencies: Qwt/PyQwt}
The GPS tracking feature uses Qwt.  Some popular 3rd-party plugins use PyQwt.
You can take care of both with the PyQwt source from:

\begin{verbatim}
http://pyqwt.sourceforge.net/
\end{verbatim}

Double-click the tarball to unpack it.  The following assumes PyQwt v5.2.0 (comes with Qwt 5.2.1).
Normal compilation does both Qwt and PyQwt at the same time, but Qwt is staically linked
into PyQwt, and Qgis can't use it.  So, we need to split the build.

First edit qwtconfig.pri in the qwt-5.2 subdir and change some settings so
you don't get a bloated debug static library (too bad they are not configurable from
qmake).  Scroll down to the 'release/debug mode' block.  Edit the last 'CONFIG +='
line, within an 'else' block, and change 'debug' to 'release'.  Like so:

\begin{verbatim}
    else {
        CONFIG           += release     # release/debug
    }
\end{verbatim}

Also uncomment (remove \# prefix) the line 'CONFIG += QwtDll'.  Like so:

\begin{verbatim}
CONFIG           += QwtDll
\end{verbatim}

If you are building for Qt Carbon 32bit on Snow Leopard, add a line at the bottom:

\begin{verbatim}
CONFIG += x86
\end{verbatim}

Save and close.

Now, cd into the qwt-5.2 subdir in a Terminal.  Type these commands to build and install:

\begin{verbatim}
qmake -spec macx-g++
make
sudo make install
sudo install_name_tool -id /usr/local/qwt-5.2.1-svn/lib/libqwt.5.dylib \
/usr/local/qwt-5.2.1-svn/lib/libqwt.5.dylib
\end{verbatim}

The Qwt shared library is now installed in /usr/local/qwt-5.x.x[-svn] (x.x is the 
minor.point version, and it may be an SVN version).  Remember this for QGIS and PyQwt configuration.

Now for PyQwt.  Still in the Terminal:

\begin{verbatim}
cd ../configure
python configure.py --extra-include-dirs=/usr/local/qwt-5.2.1-svn/include \
--extra-lib-dirs=/usr/local/qwt-5.2.1-svn/lib --extra-libs=qwt
make
sudo make install
\end{verbatim}

Make sure to use the qwt install path from the Qwt build above.

\underline{Snow Leopard note}

If using Qt Carbon, you need to specify which architectures to build, otherwise
it will default to a combination that does not work (ie x86\_64 for a Carbon Qt).
This is not needed for Qt Cocoa. Configure as follows:

\begin{verbatim}
python configure.py --extra-cflags="-arch i386" --extra-cxxflags="-arch i386" \
--extra-lflags="-arch i386" --extra-include-dirs=/usr/local/qwt-5.2.1-svn/include \
--extra-lib-dirs=/usr/local/qwt-5.2.1-svn/lib --extra-libs=qwt
\end{verbatim}

\minisec{Additional Dependencies: Bison}
\underline{Leopard and Snow Leopard note:} Leopard and Snow Leopard include Bison 2.3, so this step can be skipped on Leopard and Snow Leopard.

The version of bison available by default on Mac OS X 10.4 is too old so you need to
get a more recent one on your system. Download at least version 2.3 from:

\begin{verbatim}
ftp.gnu.org/gnu/bison/
\end{verbatim}

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:

\begin{verbatim}
./configure --prefix=/usr/local 
make
sudo make install 
\end{verbatim}

\hypertarget{toc21}{}
\subsubsection{Install CMake for OSX}
(Only needed for a cmake build.)

Get the latest source release from here:

\begin{verbatim}
http://www.cmake.org/cmake/resources/software.html
\end{verbatim}

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, double-click the source tarball,
then cd to the source folder and:

\begin{verbatim}
./bootstrap --docdir=/share/doc/CMake --mandir=/share/man
make
sudo make install
\end{verbatim}

\hypertarget{toc22}{}
\subsubsection{Install subversion for OSX}
\underline{Leopard and Snow Leopard note:} Leopard and Snow Leopard (Xcode 3+)
include SVN, so this step can be skipped on Leopard and Snow Leopard.

The [\htmladdnormallink{http://sourceforge.net/projects/macsvn/MacSVN}{http://sourceforge.net/projects/macsvn/MacSVN}] project has a downloadable
build of svn. If you are a GUI inclined person you may want to grab their gui
client too. Get the command line client here:

\begin{verbatim}
curl -O http://ufpr.dl.sourceforge.net/sourceforge/macsvn/Subversion_1.4.2.zip 
\end{verbatim}

Once downloaded open the zip file and run the installer.

You also need to install BerkleyDB available from the same
\htmladdnormallink{http://sourceforge.net/projects/macsvn/}{website}. At the time of writing the
file was here:

\begin{verbatim}
curl -O http://ufpr.dl.sourceforge.net/sourceforge/macsvn/Berkeley_DB_4.5.20.zip 
\end{verbatim}

Once again unzip this and run the installer therein.

Lastly we need to ensure that the svn commandline executeable is in the path.
Add the following line to the end of /etc/bashrc using sudo:

\begin{verbatim}
sudo vim /etc/bashrc 
\end{verbatim}

And add this line to the bottom before saving and quiting:

\begin{verbatim}
export PATH=/usr/local/bin:$PATH:/usr/local/pgsql/bin 
\end{verbatim}

/usr/local/bin needs to be first in the path so that the newer bison (that will
be built from source further down) is found before the bison (which is very
old) that is installed by MacOSX

Now close and reopen your shell to get the updated vars.

\hypertarget{toc23}{}
\subsubsection{Check out QGIS from SVN}
Now we are going to check out the sources for QGIS. First we will create a
directory for working in (or some folder of your choice):

\begin{verbatim}
mkdir -p ~/dev/cpp cd ~/dev/cpp 
\end{verbatim}

Now we check out the sources:

Trunk:

\begin{verbatim}
svn co https://svn.osgeo.org/qgis/trunk/qgis qgis 
\end{verbatim}

For a release branch version x.y.z:

\begin{verbatim}
svn co https://svn.qgis.org/qgis/branches/Release-x_y_z qgis-x.y.z
\end{verbatim}

The first time you check out QGIS sources you will probably get a message like
this:

\begin{verbatim}
 Error validating server certificate for 'https://svn.qgis.org:443':
 - The certificate is not issued by a trusted authority. Use the fingerprint to
   validate the certificate manually!  Certificate information:
 - Hostname: svn.qgis.org
 - Valid: from Apr  1 00:30:47 2006 GMT until Mar 21 00:30:47 2008 GMT
 - Issuer: Developer Team, Quantum GIS, Anchorage, Alaska, US
 - Fingerprint: 2f:cd:f1:5a:c7:64:da:2b:d1:34:a5:20:c6:15:67:28:33:ea:7a:9b
   (R)eject, accept (t)emporarily or accept (p)ermanently?  
\end{verbatim}

I suggest you press 'p' to accept the key permanently.

\hypertarget{toc24}{}
\subsubsection{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 pre-existing \$\{HOME\}/Applications directory.
In a Terminal cd to the qgis source folder previously downloaded, then:

\begin{verbatim}
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_BUILD_TYPE=MinSizeRel -D WITH_INTERNAL_SPATIALITE=FALSE \
-D QWT_LIBRARY=/usr/local/qwt-5.2.1-svn/lib/libqwt.dylib \
-D QWT_INCLUDE_DIR=/usr/local/qwt-5.2.1-svn/include \
..
\end{verbatim}

This will automatically find and use the previously installed frameworks, and the GRASS
application if installed.

Or, to use a Unix-style build of GRASS, use the following cmake invocation
(minimum GRASS version as stated in the Qgis requirements, substitute the GRASS
path and version as required):

\begin{verbatim}
cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_BUILD_TYPE=MinSizeRel -D WITH_INTERNAL_SPATIALITE=FALSE \
-D QWT_LIBRARY=/usr/local/qwt-5.2.1-svn/lib/libqwt.dylib \
-D QWT_INCLUDE_DIR=/usr/local/qwt-5.2.1-svn/include \
-D GRASS_PREFIX=/user/local/grass-6.4.0 \
..
\end{verbatim}

\underline{Snow Leopard note:} To handle 32-bit Qt (Carbon), create a 32bit python wrapper
script and add arch flags to the configuration:

\begin{verbatim}
sudo cat >/usr/local/bin/python32 <<EOF
#!/bin/sh
exec arch -i386 /usr/bin/python2.6 \${1+"\$@"}
EOF

sudo chmod +x /usr/local/bin/python32

cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_BUILD_TYPE=MinSizeRel -D WITH_INTERNAL_SPATIALITE=FALSE \
-D QWT_LIBRARY=/usr/local/qwt-5.2.1-svn/lib/libqwt.dylib \
-D QWT_INCLUDE_DIR=/usr/local/qwt-5.2.1-svn/include \
-D CMAKE_OSX_ARCHITECTURES=i386 -D PYTHON_EXECUTABLE=/usr/local/bin/python32 \
..
\end{verbatim}

\underline{Bundling note:} Older Qt versions may have problems with some Qt plugins and Qgis.
The way to handle this is to bundle Qt inside the Qgis application.  You can do this now
or wait to see if there are immediate crashes when running Qgis.  It's also a good
idea to bundle Qt if you need to copy Qgis to other Macs (where you would have to
install Xcode just so Qt would install!).

To bundle Qt, add the following line before the last line in the above cmake configurations:

\begin{verbatim}
-D QGIS_MACAPP_BUNDLE=1 \
\end{verbatim}

\hypertarget{toc25}{}
\subsubsection{Building}
Now we can start the build process (remember the parallel compilation note at
the beginning, this is a good place to use it, if you can):

\begin{verbatim}
make 
\end{verbatim}

If all built without errors you can then install it:

\begin{verbatim}
make install 
\end{verbatim}

or, for a /Applications build:

\begin{verbatim}
sudo make install
\end{verbatim}

