% vim: set textwidth=78 autoindent:

\section{Installation Guide}\label{label_install}

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

The following chapters provide build and installation information for QGIS
Version \CURRENT. This document corresponds almost to a \LaTeX~ conversion of
the INSTALL.t2t file coming with the QGIS sources from November, 27th 2009.

A current version is also available at the wiki, see:
\url{http://www.qgis.org/wiki/Installation_Guide}

\subsection{General Build Notes}
Since version 0.8.1 QGIS no longer uses the autotools for building. QGIS, like a
number of major projects (eg. KDE 4.0), now uses CMake (\htmladdnormallink{http://www.cmake.org}{http://www.cmake.org})
for building from source. The configure script in this directory simply checks
for the existence of cmake and provides some clues to build QGIS.

\subsubsection{An overview of the dependencies required for building}
'''Required build deps:'''
* CMake $>$= 2.4.3
* Flex, Bison

'''Required runtime deps:'''
* Qt $>$= 4.3.0
* Proj $>$= 4.4.x
* GEOS $>$= 3.0
* Sqlite3 $>$= 3.0.0
* GDAL/OGR $>$= 1.4.x

'''Optional dependencies:'''
* for GRASS plugin - GRASS $>$= 6.0.0 (libraries compiled with exceptions support)
* for georeferencer - GSL $>$= 1.8
* for postgis support and SPIT plugin - PostgreSQL $>$= 8.0.x
* for gps plugin - expat $>$= 1.95
* for mapserver export and PyQGIS - Python $>$= 2.3 (2.5+ preferred)
* for PyQGIS - SIP $>$= 4.8, PyQt $>$= must match Qt version
* for GPS tracking - Qwt $>$= 5.0

'''Recommended runtime deps:'''
* for gps plugin - gpsbabel


\subsection{Building under windows using msys}
\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...

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

\subsubsection{Qt4.3}
Download qt4.3 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.3.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.3.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.3.0$\backslash$bin$\backslash$qtvars.bat compile\_debug

Note: there is a problem when compiling debug version of Qt 4.3, 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.3.0 make 
\end{verbatim}

\subsubsection{Flex and Bison}
*** Note I think this section can be removed as it should be installed int the
msys image already. TS

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

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

\minisec{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/}

\minisec{Download SIP and PyQt4 sources}
\htmladdnormallink{http://www.riverbankcomputing.com/software/sip/download}{http://www.riverbankcomputing.com/software/sip/download}

\htmladdnormallink{http://www.riverbankcomputing.com/software/pyqt/download}{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.

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

\minisec{Compile PyQt}
\begin{verbatim}
c:\Qt\4.3.0\bin\qtvars.bat 
python configure.py 
make 
make install 
\end{verbatim}

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

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

\htmladdnormallink{http://subversion.tigris.org/files/documents/15/36797/svn-1.4.3-setup.exe}{http://subversion.tigris.org/files/documents/15/36797/svn-1.4.3-setup.exe}

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

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

\subsubsection{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 head:

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

\begin{verbatim}
 svn co https://svn.osgeo.org/qgis/branches/Release-0_8_0 qgis0.8
\end{verbatim}

\subsubsection{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.3.0\bin\qtvars.bat 
\end{verbatim}

For ease of use add c:$\backslash$Qt$\backslash$4.3.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}

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

/!$\backslash$ 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 cripts 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.

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

The best way to do this is to download both the QGIS current release installer
package from \htmladdnormallink{http://qgis.org/uploadfiles/testbuilds/}{http://qgis.org/uploadfiles/testbuilds/} and install it. Now copy
the installation dir from C:$\backslash$Program Files$\backslash$Quantum GIS into c:$\backslash$Program
Files$\backslash$qgis-0.8.1 (or whatever the current version is. The name should strictly
match the version no.) After making this copy you can uninstall the release
version of QGIS from your c:$\backslash$Program Files directory using the provided
uninstaller. Double check that the Quantum GIS dir is completely gone under
program files afterwards.

Another 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.

\subsubsection{Create the installation package: (optional)}
Downlad 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'. 


\subsection{Building on Mac OSX using frameworks and cmake or Xcode}
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}) and below. Included are a few notes
for building on Mac OS X 10.5 (\underline{Leopard}) and 10.6 (\underline{Snow Leopard}). 

\underline{Snow Leopard note:} A cmake/qt/sip bug currently exists where a 32-bit
cmake build fails to provide python bindings. This means that python plugin support
is currently lacking for 32-bit builds using cmake in Snow Leopard. See the Xcode
build method to if you require python support.

\subsubsection{Install Xcode}
I recommend to get the latest Xcode dmg from the Apple XDC Web site 
(http:/developer.apple.com). The Mac system install disks come with a copy of
Xcode, but it's likely out of date.
Install Xcode after the \~{}1gb download is complete.

/!$\backslash$ Note: It may be that you need to create some symlinks after installing 
Xcode (in particular if you are using Xcode 2.5 on Tiger):

\begin{verbatim}
cd /Developer/SDKs/MacOSX10.4u.sdk/usr/
sudo mv local/ local_
sudo ln -s /usr/local/ local
\end{verbatim}

\subsubsection{Install Qt4 from .dmg}
You need a minimum of Qt-4.3.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.

\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 4.4+ 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 (which will
happen in the Xcode build), 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.

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

\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}

\underline{Leopard note:} To compile for 64bit, substitute the standard configure line with:

\begin{verbatim}
./configure CFLAGS="-Os -arch x86_64"
\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.

Make sure you install at least the latest Python 2.5 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 -d /Library/Python/2.5/site-packages -b /usr/local/bin \
-e /usr/local/include -v /usr/local/share/sip
\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 -d /Library/Python/2.6/site-packages -b /usr/local/bin 
-e /usr/local/include -v /usr/local/share/sip --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
-e /usr/local/include -v /usr/local/share/sip --arch=x86_64
\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}
export QTDIR=/Developer/Applications/Qt
python configure.py 
yes 
\end{verbatim}

There is a problem with the configuration that needs to be fixed now (it affect 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:

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

Now, 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 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'.  Also uncomment
(remove \# prefix) the line 'CONFIG += QwtDll'.

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
\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 and older 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.\&\#65533; 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}

\subsubsection{Install CMake for OSX}
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}

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

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

\subsubsection{Configure the build}
There are 2 different methods to build QGIS: the traditional CMake method,
and the new Xcode project (starting with QGIS 1.1). The Xcode project has
additional bundling steps, though some optional QGIS features must be explicitly
stated in a user configuration file. The CMake build handles optional features,
and some bundling steps are available with scripts in the mac directory.

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

\begin{verbatim}
cd qgis
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D CMAKE_BUILD_TYPE=Release ..
\end{verbatim}

To use the application build of GRASS on OSX, you can optionally use the
following cmake invocation (minimum GRASS 6.3 required, substitute the GRASS
version as required):

\begin{verbatim}
cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D CMAKE_BUILD_TYPE=Release \
-D GRASS_INCLUDE_DIR=/Applications/GRASS-6.4.app/Contents/MacOS/include \
-D GRASS_PREFIX=/Applications/GRASS-6.4.app/Contents/MacOS \
..
\end{verbatim}

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 GRASS_INCLUDE_DIR=/user/local/grass-6.4.0/include \
-D GRASS_PREFIX=/user/local/grass-6.4.0 \
..
\end{verbatim}

\underline{Leopard note:} To find the custom install of SIP on Leopard, add
'-D SIP\_BINARY\_PATH=/usr/local/bin/sip' to the cmake commands above,
before the '..' at the end, ie:

\begin{verbatim}
cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D CMAKE_BUILD_TYPE=Release \
-D SIP_BINARY_PATH=/usr/local/bin/sip \
..
\end{verbatim}

\underline{Snow Leopard note:} To handle the appropriate version of Qt (32-bit or 64-bit), you will need to invoke cmake based on which version of Qt you installed.  Also, SIP/PyQt detection will fail for 32bit because Python runs 64bit.

For 32-bit Qt (Carbon) with GRASS-6.4, create a 32bit python 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 SIP_BINARY_PATH=/usr/local/bin/sip \
-D CMAKE_CXX_FLAGS="-arch i386" -D CMAKE_OSX_ARCHITECTURES=i386 \
-D GRASS_INCLUDE_DIR=/Applications/GRASS-6.4.app/Contents/MacOS/include \
-D GRASS_PREFIX=/Applications/GRASS-6.4.app/Contents/MacOS \
-D PYTHON_EXECUTABLE=/usr/local/bin/python32 \
..
\end{verbatim}

For 64-bit Qt (Cocoa) with GRASS-6.4:

\begin{verbatim}
cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D CMAKE_BUILD_TYPE=Release \
-D SIP_BINARY_PATH=/usr/local/bin/sip \
-D CMAKE_CXX_FLAGS="-arch x86_64" -D CMAKE_OSX_ARCHITECTURES=x86_64 \
-D GRASS_INCLUDE_DIR=/Applications/GRASS-6.4.app/Contents/MacOS/include \
-D GRASS_PREFIX=/Applications/GRASS-6.4.app/Contents/MacOS \
..
\end{verbatim}

\minisec{Configure the Xcode build}
In the mac/xcode folder in the source, duplicate the 'qgis\_user-template.xcconfig'
file and name it 'qgis\_user.xcconfig'. A default build will use the KyngChaos
frameworks, Postgres, GRASS 6.4, the python.org Python 2.5 (for Tiger)
or the system Python (for Leopard and Snow Leopard) and extra dependencies
as described above, and compile for the current OSX architecture and version, so no
extra configuration is necessary.

See the mac/xcode/readme.rtf for details, if you need to customize the build.
The default build will also bundle the Qt frameworks, Postgres library, and
other dependency libraries to create a self-contained package. The KyngChaos
frameworks and GRASS application are not bundled.

\subsubsection{Building}
\minisec{Building with Cmake}
Now we can start the build process:

\begin{verbatim}
make 
\end{verbatim}

If all built without errors you can then install it:

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

or, for a Unix-style build

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

\minisec{Building with Xcode}
Open the Xcode project file in the mac/xcode directory. Select 'Release' build
configuration and select the 'Full Qgis' target, then build. If you use ccache,
there have been compilation problems reported, so it is suggested that you disable
ccache support.

Alternatively, from within the mac/xcode directory, build with the command:

\begin{verbatim}
xcodebuild
\end{verbatim}

The Qgis application will be found in the 'build/\$SDKSYS/Release' folder
in the xcode folder, where \$SDKSYS is the system you configured for in your
qgis\_user.xcconfig. Copy this to whereever you like.


\subsection{Building on GNU/Linux}
\subsubsection{Building QGIS with Qt4.x}
\textbf{Requires:} Ubuntu Hardy / Debian derived distro

These notes are current for Ubuntu 7.10 - 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.

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

\begin{verbatim}
sudo apt-get update 
\end{verbatim}

\subsubsection{Install Qt4}
\begin{verbatim}
sudo apt-get install libqt4-core libqt4-debug  \
libqt4-dev libqt4-gui libqt4-qt3support libqt4-sql lsb-qt4 qt4-designer \
qt4-dev-tools qt4-doc qt4-qtconfig uim-qt gcc libapt-pkg-perl resolvconf
\end{verbatim}

/!$\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.

\subsubsection{Install additional software dependencies required by QGIS}
\begin{verbatim}
sudo apt-get install gdal-bin libgdal1-dev libgeos-dev proj \
libgdal-doc libhdf4g-dev libhdf4g-run python-dev \
libgsl0-dev g++ libjasper-dev libtiff4-dev subversion \
libsqlite3-dev sqlite3 ccache make libpq-dev flex bison cmake txt2tags \
python-qt4 python-qt4-dev python-sip4 sip4 python-sip4-dev
\end{verbatim}

/!$\backslash$ Debian users should use libgdal-dev above rather

/!$\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.

If you do not have cmake installed already:

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

\subsubsection{GRASS Specific Steps}
/!$\backslash$ \textbf{*Note:*} If you don't need to build with GRASS support,  you can
skip this section.

Now you can install grass from dapper:

\begin{verbatim}
sudo apt-get install grass libgrass-dev 
\end{verbatim}

\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}

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

\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}

\subsubsection{Starting the compile}
/!$\backslash$ \textbf{*Note:*} The next section describes howto build debian packages

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.

\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}

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 the packages are created in the parent directory (ie. one level up).
Install them using dpkg.  E.g.:

\begin{verbatim}
sudo dpkg -i \
	../qgis_1.0preview16_amd64.deb \
	../libqgis-gui1_1.0preview16_amd64.deb \
	../libqgis-core1_1.0preview16_amd64.deb \
	../qgis-plugin-grass_1.0preview16_amd64.deb \
	../python-qgis_1.0preview16_amd64.deb
\end{verbatim}

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

\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}


\subsection{Creation of MSYS environment for compilation of Quantum GIS}
\subsubsection{Initial setup}
\minisec{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).

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

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

\subsubsection{Installing dependencies}
\minisec{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}

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

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

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

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

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

\minisec{POSTGRES}
We're going to use precompiled binaries. Use the link below for download:

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

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

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


\subsection{Building with MS Visual Studio}
/!$\backslash$ This section describes a process where you build all dependencies yourself. See the section
after this for a simpler procedure where we have all the dependencies you need pre-packaged
and we focus just on getting Visual Studio Express set up and building QGIS.

Note that this does not currently include GRASS or Python plugins.

\subsubsection{Setup Visual Studio}
This section describes the setup required to allow Visual Studio to be used to build QGIS. 

\minisec{Express Edition}
The free Express Edition lacks the platform SDK which contains headers and so on that are needed when building QGIS. The platform SDK can be installed as described here:

	\begin{quotation}
\htmladdnormallink{http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/}{http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/}
	\end{quotation}
Once this is done, you will need to edit the $<$vsinstalldir$>$$\backslash$Common7$\backslash$Tools$\backslash$vsvars file as follows:

	\begin{quotation}
Add \texttt{\%PlatformSDKDir\%$\backslash$Include$\backslash$atl} and \texttt{\%PlatformSDKDir\%$\backslash$Include$\backslash$mfc} to the \texttt{@set INCLUDE} entry.
	\end{quotation}
This will add more headers to the system INCLUDE path. Note that this will only work when you use the Visual Studio command prompt when building. Most of the dependencies will be built with this.
You will also need to perform the edits described here to remove the need for a library that Visual Studio Express lacks:

	\begin{quotation}
\htmladdnormallink{http://www.codeproject.com/wtl/WTLExpress.asp}{http://www.codeproject.com/wtl/WTLExpress.asp}
	\end{quotation}

\minisec{All Editions}
You will need stdint.h and unistd.h. unistd.h comes with GnuWin32 version of flex \& bison binaries (see later). stdint.h can be found here:

	\begin{quotation}
\htmladdnormallink{http://www.azillionmonkeys.com/qed/pstdint.h}{http://www.azillionmonkeys.com/qed/pstdint.h}.
	\end{quotation}
Copy both of these to $<$vsinstalldir$>$$\backslash$VC$\backslash$include.

\subsubsection{Download/Install Dependencies}
This section describes the downloading and installation of the various QGIS dependencies.

\minisec{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 and run the installers:

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

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

\minisec{To include  PostgreSQL support in Qt}
If you want to build Qt with PostgreSQL support you need to download
PostgreSQL, install it and create a library you can later link with Qt.

Download from .../binary/v8.2.5/win32/postgresql-8.2.5-1.zip from an
PostgreSQL.org Mirror and install.

PostgreSQL is currently build with MinGW and comes with headers and libraries
for MinGW.  The headers can be used with Visual C++ out of the box, but the library
is only shipped in DLL and archive (.a) form and therefore cannot be used with
Visual C++ directly.

To create a library copy following sed script to the file mkdef.sed in
PostgreSQL lib directory:

\begin{verbatim}
/Dump of file / {
	s/Dump of file \([^	 ]*\)$/LIBRARY \1/p
	a\
EXPORTS
}
/[ 	]*ordinal hint/,/^[	]*Summary/ {
 /^[ 	]\+[0-9]\+/ {
   s/^[ 	]\+[0-9]\+[ 	]\+[0-9A-Fa-f]\+[ 	]\+[0-9A-Fa-f]\+[ 	]\+\([^ 	=]\+\).*$/	\1/p
 }
}
\end{verbatim}

and process execute in the Visual Studio C++ command line (from Programs menu):

\begin{verbatim}
cd c:\Program Files\PostgreSQL\8.2\bin
dumpbin /exports ..\bin\libpq.dll | sed -nf ../lib/mkdef.sed >..\lib\libpq.def
cd ..\lib
lib /def:libpq.def /machine:x86
\end{verbatim}

You'll need an sed for that to work in your path (e.g. from cygwin or msys).

That's almost it.  You only need to the include and lib path to INCLUDE and LIB
in vcvars.bat respectively.

\minisec{Qt}
Build Qt following the instructions here:

	\begin{quotation}
\htmladdnormallink{http://wiki.qgis.org/qgiswiki/Building\_QT\_4\_with\_Visual\_C\%2B\%2B\_2005}{http://wiki.qgis.org/qgiswiki/Building\_QT\_4\_with\_Visual\_C\%2B\%2B\_2005}
	\end{quotation}

\minisec{Proj.4}
Get proj.4 source from here:

	\begin{quotation}
\htmladdnormallink{http://proj.maptools.org/}{http://proj.maptools.org/}
	\end{quotation}
Using the Visual Studio command prompt (ensures the environment is setup properly), run the following in the src directory:

\begin{verbatim}
nmake -f makefile.vc
\end{verbatim}

Install by running the following in the top level directory setting PROJ\_DIR as appropriate:

\begin{verbatim}
set PROJ_DIR=c:\lib\proj

mkdir %PROJ_DIR%\bin
mkdir %PROJ_DIR%\include
mkdir %PROJ_DIR%\lib

copy src\*.dll %PROJ_DIR%\bin
copy src\*.exe %PROJ_DIR%\bin
copy src\*.h %PROJ_DIR%\include
copy src\*.lib %PROJ_DIR%\lib 
\end{verbatim}

This can also be added to a batch file.

\minisec{GSL}
Get gsl source from here:

	\begin{quotation}
\htmladdnormallink{http://david.geldreich.free.fr/downloads/gsl-1.9-windows-sources.zip}{http://david.geldreich.free.fr/downloads/gsl-1.9-windows-sources.zip}
	\end{quotation}
Build using the gsl.sln file

\minisec{GEOS}
Get geos from svn (svn checkout \htmladdnormallink{http://svn.refractions.net/geos/trunk}{http://svn.refractions.net/geos/trunk} geos).
Edit geos$\backslash$source$\backslash$makefile.vc as follows:

Uncomment lines 333 and 334 to allow the copying of version.h.vc to version.h.

Uncomment lines 338 and 339.

Rename geos\_c.h.vc to geos\_c.h.in on lines 338 and 339 to allow the copying of geos\_c.h.in to geos\_c.h.

Using the Visual Studio command prompt (ensures the environment is setup properly), run the following in the top level directory:

\begin{verbatim}
nmake -f makefile.vc 
\end{verbatim}

Run the following in top level directory, setting GEOS\_DIR as appropriate:

\begin{verbatim}
set GEOS_DIR="c:\lib\geos"

mkdir %GEOS_DIR%\include
mkdir %GEOS_DIR%\lib
mkdir %GEOS_DIR%\bin

xcopy /S/Y source\headers\*.h %GEOS_DIR%\include
copy /Y capi\*.h %GEOS_DIR%\include
copy /Y source\*.lib %GEOS_DIR%\lib
copy /Y source\*.dll %GEOS_DIR%\bin
\end{verbatim}

This can also be added to a batch file.

\minisec{GDAL}
Get gdal from svn (svn checkout \htmladdnormallink{https://svn.osgeo.org/gdal/branches/1.4/gdal}{https://svn.osgeo.org/gdal/branches/1.4/gdal} gdal).

Edit nmake.opt to suit, it's pretty well commented.

Using the Visual Studio command prompt (ensures the environment is setup properly), run the following in the top level directory:

\begin{verbatim}
nmake -f makefile.vc 
\end{verbatim}

and

\begin{verbatim}
nmake -f makefile.vc devinstall 
\end{verbatim}

\minisec{PostGIS}
Get PostGIS and the Windows version of PostgreSQL from here:

	\begin{quotation}
\htmladdnormallink{http://postgis.refractions.net/download/}{http://postgis.refractions.net/download/}
	\end{quotation}
Note the warning about not installing the version of PostGIS that comes with the PostgreSQL installer. Simply run the installers.

\minisec{Expat}
Get expat from here:

	\begin{quotation}
\htmladdnormallink{http://sourceforge.net/project/showfiles.php?group\_id=10127}{http://sourceforge.net/project/showfiles.php?group\_id=10127}
	\end{quotation}
You'll need expat-win32bin-2.0.1.exe.

Simply run the executable to install expat.

\minisec{CMake}
Get CMake from here:

	\begin{quotation}
\htmladdnormallink{http://www.cmake.org/HTML/Download.html}{http://www.cmake.org/HTML/Download.html}
	\end{quotation}
You'll need cmake-$<$version$>$-win32-x86.exe. Simply run this to install CMake.

\subsubsection{Building QGIS with CMAKE}
Get QGIS source from svn (svn co \htmladdnormallink{https://svn.osgeo.org/qgis/trunk/qgis}{https://svn.osgeo.org/qgis/trunk/qgis} qgis).

Create a 'Build' directory in the top level QGIS directory. This will be where all the build output will be generated.

Run Start out{$>$All Programs}$>$CMake--$>$CMake. 

In the 'Where is the source code:' box, browse to the top level QGIS directory.

In the 'Where to build the binaries:' box, browse to the 'Build' directory you created in the top level QGIS directory.

Fill in the various *\_INCLUDE\_DIR and *\_LIBRARY entries in the 'Cache Values' list.

Click the Configure button. You will be prompted for the type of makefile that will be generated. Select Visual Studio 8 2005 and click OK.

All being well, configuration should complete without errors. If there are errors, it is usually due to an incorrect path to a header or library directory. Failed items will be shown in red in the list.

Once configuration completes without error, click OK to generate the solution and project files.

With Visual Studio 2005, open the qgis.sln file that will have been created in the Build directory you created earlier.

Build the ALL\_BUILD project. This will build all the QGIS binaries along with all the plugins.

 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). 

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


\subsection{Building under Windows using MSVC Express}
/!$\backslash$ This section of the document is in draft form and is not ready to be used
yet.

Tim Sutton, 2007

\subsubsection{System preparation}
I started with a clean XP install with Service Pack 2 and all patches applied.
I have already compiled all the dependencies you need for gdal, expat etc,
so this tutorial wont cover compiling those from source too. Since compiling 
these dependencies was a somewhat painful task I hope my precompiled libs 
will be adequate. If not I suggest you consult the individual projects for
specific build documentation and support. Lets go over the process in a nutshell 
before we begin:

 * Install XP (I used a Parallels virtual machine)
 * Install the premade libraries archive I have made for you
 * Install Visual Studio Express 2005 sp1
 * Install the Microsoft Platform SDK
 * Install command line subversion client
 * Install library dependencies bundle
 * Install Qt 4.3.2
 * Check out QGIS sources
 * Compile QGIS
 * Create setup.exe installer for QGIS

\subsubsection{Install the libraries archive}
Half of the point of this section of the MSVC setup procedure is to make 
things as simple as possible for you. To that end I have prepared an
archive that includes all dependencies needed to build QGIS except Qt 
(which we will build further down). Fetch the archive from:

\begin{verbatim}
http://qgis.org/uploadfiles/msvc/qgis_msvc_deps_except_qt4.zip
\end{verbatim}

Create the following directory structure:

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

And then extract the libraries archive into a subdirectory of the above
directory so that you end up with:

\begin{verbatim}
c:\dev\cpp\qgislibs-release
\end{verbatim}

/!$\backslash$ Note that you are not obliged to use this directory layout, but you 
should adjust any instructions that follow if you plan to do things 
differently.

\subsubsection{Install Visual Studio Express 2005}
First thing we need to get is MSVC Express from here:

\htmladdnormallink{http://msdn2.microsoft.com/en-us/express/aa975050.aspx}{http://msdn2.microsoft.com/en-us/express/aa975050.aspx}

The page is really confusing so don't feel bad if you cant actually find the 
download at first! There are six colored blocks on the page for the various  
studio family members (vb / c\# / j\# etc). Simply choose your language under 
the 'select your language' combo under the yellow C++ block, and your download 
will begin. Under internet explorer I had to disable popup blocking for the 
download to be able to commence.

Once the setup commences you will be prompted with various options. Here is what 
I chose :

 * Send usage information to Microsoft    (No)
 * Install options:
   * Graphical IDE                        (Yes)
   * Microsoft MSDN Express Edition       (No)
   * Microsoft SQL Server Express Edition (No)
 * Install to folder: C:$\backslash$Program Files$\backslash$Microsoft Visual Studio 8$\backslash$   (default)

It will need to download around 90mb of installation files and reports 
that the install will consume 554mb of disk space.

\subsubsection{Install Microsoft Platform SDK2}
Go to this page:

\htmladdnormallink{http://msdn2.microsoft.com/en-us/express/aa700755.aspx}{http://msdn2.microsoft.com/en-us/express/aa700755.aspx}

Start by using the link provided on the above page to download and install the
platform SDK2.

The actual SDK download page is once again a bit confusing since the links for 
downloading are hidden amongst a bunch of other links. Basically look for these 
three links with their associated 'Download' buttons and choose the correct 
link for your platform:

\begin{verbatim}
PSDK-amd64.exe  1.2 MB  Download 
PSDK-ia64.exe   1.3 MB  Download 
PSDK-x86.exe    1.2 MB  Download
\end{verbatim}

When you install make sure to choose 'custom install'. These instructions 
assume you are installing into the default path of:

\begin{verbatim}
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\
\end{verbatim}

We will go for the minimal install that will give us a working environment, 
so on the custom installation screen I made the following choices:

\begin{verbatim}
Configuration Options
  + Register Environmental Variables            (Yes)
Microsoft Windows Core SDK
  + Tools                                       (Yes)
    + Tools (AMD 64 Bit)                        (No unless this applies)
    + Tools (Intel 64 Bit)                      (No unless this applies)
  + Build Environment
    + Build Environment (AMD 64 Bit)            (No unless this applies)
    + Build Environment (Intel 64 Bit)          (No unless this applies)
    + Build Environment (x86 32 Bit)            (Yes)
  + Documentation                               (No)
  + Redistributable Components                  (Yes)
  + Sample Code                                 (No)
  + Source Code                                 (No)
    + AMD 64 Source                             (No)
    + Intel 64 Source                           (No)
Microsoft Web Workshop                          (Yes) (needed for shlwapi.h)
  + Build Environment                           (Yes)
  + Documentation                               (No)
  + Sample Code                                 (No)
  + Tools                                       (No)
Microsoft Internet Information Server (IIS) SDK (No)
Microsoft Data Access Services (MDAC) SDK       (Yes) (needed by GDAL for odbc)
  + Tools
    + Tools (AMD 64 Bit)                        (No)
    + Tools (AMD 64 Bit)                        (No)
    + Tools (x86 32 Bit)                        (Yes)
  + Build Environment
    + Tools (AMD 64 Bit)                        (No)
    + Tools (AMD 64 Bit)                        (No)
    + Tools (x86 32 Bit)                        (Yes)
  + Documentation                               (No)
  + Sample Code                                 (No)
Microsodt Installer SDK                         (No)
Microsoft Table PC SDK                          (No)
Microsoft Windows Management Instrumentation    (No)
Microsoft DirectShow SDK                        (No)
Microsoft Media Services SDK                    (No)
Debuggin Tools for Windows                      (Yes)
\end{verbatim}

/!$\backslash$ Note that you can always come back later to add extra bits if you like.

/!$\backslash$ Note that installing the SDK requires validation with the 
Microsoft Genuine Advantage application. Some people have a philosophical 
objection to installing this software on their computers. If you are one 
of them you should probably consider using the MINGW build instructions 
described elsewhere in this document.

The SDK installs a directory called

\begin{verbatim}
C:\Office10
\end{verbatim}

Which you can safely remove.

After the SDK is installed, follow the remaining notes on the page link 
above to get your MSVC Express environment configured correctly. For your 
convenience, these are summarised again below, and I have added a couple 
more paths that I discovered were needed:

1) open Visual Studio Express IDE

2) Tools -$>$ Options -$>$ Projects and Solutions -$>$ VC++ Directories

3) Add:

\begin{verbatim}
Executable files: 
  C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin

Include files: 
  C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
  C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\atl
  C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\mfc
Library files: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib
\end{verbatim}

4) Close MSVC Express IDE

5) Open the following file with notepad:

\begin{verbatim}
C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults\corewin_express.vsprops
\end{verbatim}

and change the property:

\begin{verbatim}
AdditionalDependencies="kernel32.lib"
\end{verbatim}

To read:

\begin{verbatim}
AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
                        advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"
\end{verbatim}

The notes go on to show how to build a mswin32 application which you can try if you like - 
I'm not going to recover that here.

\subsubsection{Edit your vsvars}
Backup your vsvars32.bat file in 

\begin{verbatim}
C:\Program Files\Microsoft Visual Studio 8\Common7\Tools
\end{verbatim}

and replace it with this one:

\begin{verbatim}
@SET VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8
@SET VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8\VC
@SET FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework
@SET FrameworkVersion=v2.0.50727
@SET FrameworkSDKDir=C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0
@if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR
@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR

@echo Setting environment for using Microsoft Visual Studio 2005 x86 tools.

@rem
@rem Root of Visual Studio IDE installed files.
@rem
@set DevEnvDir=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

@set PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program \
Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual \
Studio 8\Common7\Tools;C:\Program Files\Microsoft Visual Studio \
8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program \
Files\Microsoft Visual Studio 8\VC\VCPackages;%PATH%
@rem added by Tim
@set PATH=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin;%PATH%
@set INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;%INCLUDE%
@rem added by Tim
@set INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server \
2003 R2\Include;%INCLUDE%
@set INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server \
2003 R2\Include\mfc;%INCLUDE%
@set INCLUDE=%INCLUDE%;C:\dev\cpp\qgislibs-release\include\postgresql
@set LIB=C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program \
Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%LIB%
@rem added by Tim
@set LIB=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib;%LIB%
@set LIB=%LIB%;C:\dev\cpp\qgislibs-release\lib
@set LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

@goto end

:error_no_VSINSTALLDIR
@echo ERROR: VSINSTALLDIR variable is not set. 
@goto end

:error_no_VCINSTALLDIR
@echo ERROR: VCINSTALLDIR variable is not set. 
@goto end

:end

\end{verbatim}

\subsubsection{Environment Variables}
Right click on 'My computer' then select the 'Advanced' tab. Click environment variables and 
create or augment the following '''System''' variables (if they don't already exist):

\begin{verbatim}
Variable Name:     Value:
--------------------------------------------------------------------------
EDITOR             vim
INCLUDE            C:\Program Files\Microsoft Platform SDK for Windows Server \
                   2003 R2\Include\.
LIB                C:\Program Files\Microsoft Platform SDK for Windows Server \
                   2003 R2\Lib\.
LIB_DIR            C:\dev\cpp\qgislibs-release
PATH               C:\Program Files\CMake 2.4\bin;
                   %SystemRoot%\system32;
                   %SystemRoot%;
                   %SystemRoot%\System32\Wbem;
                   C:\Program Files\Microsoft Platform SDK for Windows Server \
                   2003 R2\Bin\.;
                   C:\Program Files\Microsoft Platform SDK for Windows Server \
                   2003 R2\Bin\WinNT\;
                   C:\Program Files\svn\bin;C:\Program Files\Microsoft Visual \
                   Studio 8\VC\bin;
                   C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;
                   "c:\Program Files\Microsoft Visual Studio 8\Common7\Tools";
                   c:\Qt\4.3.2\bin;
                   "C:\Program Files\PuTTY"
QTDIR              c:\Qt\4.3.2
SVN_SSH            "C:\\Program Files\\PuTTY\\plink.exe"
\end{verbatim}

\subsubsection{Building Qt4.3.2}
You need a minimum of Qt 4.3.2 here since this is the first version to officially 
support building the open source version of Qt for windows under MSVC.

Download Qt 4.x.x source for windows from

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

Unpack the source to 

\begin{verbatim}
c:\Qt\4.x.x\
\end{verbatim}

\minisec{Compile Qt}
Open the Visual Studio C++ command line and cd to c:$\backslash$Qt$\backslash$4.x.x where you
extracted the source and enter:

\begin{verbatim}
configure -platform win32-msvc2005
nmake
nmake install
\end{verbatim}

Add -qt-sql-odbc -qt-sql-psql to the configure line if your want odbc and
PostgreSQL support build into Qt.

/!$\backslash$ Note: For me in some cases I got a build error on qscreenshot.pro. If you
are only interested in having the libraries needed for building Qt apps, you 
can probably ignore that. Just check in c:$\backslash$Qt$\backslash$4.3.2$\backslash$bin to check all dlls and 
helper apps (assistant etc) have been made.

\minisec{Configure Visual C++ to use Qt}
After building configure the Visual Studio Express IDE to use Qt:

1) open Visual Studio Express IDE

2) Tools -$>$ Options -$>$ Projects and Solutions -$>$ VC++ Directories

3) Add:

\begin{verbatim}
Executable files: 
  $(QTDIR)\bin

Include files: 
  $(QTDIR)\include
  $(QTDIR)\include\Qt
  $(QTDIR)\include\QtCore
  $(QTDIR)\include\QtGui
  $(QTDIR)\include\QtNetwork
  $(QTDIR)\include\QtSvg
  $(QTDIR)\include\QtXml
  $(QTDIR)\include\Qt3Support
  $(LIB_DIR)\include   (needed during qgis compile to find stdint.h and unistd.h)

Library files: 
  $(QTDIR)\lib

Source Files:
  $(QTDIR)\src
\end{verbatim}

Hint:  You can also add

\begin{verbatim}
QString = t=<d->data, su>, size=<d->size, i>
\end{verbatim}

to AutoExp.DAT in C:$\backslash$Program Files$\backslash$Microsoft Visual Studio 8$\backslash$Common7$\backslash$Packages$\backslash$Debugger before 

\begin{verbatim}
[Visualizer]
\end{verbatim}

That way the Debugger will show the contents of QString when you point at or
watch a variable in the debugger.  There are probably much more additions -
feel free to add some - I just needed QString and took the first hit in google
I could find.

\subsubsection{Install Python}
Download \htmladdnormallink{http://python.org/ftp/python/2.5.1/python-2.5.1.msi}{http://python.org/ftp/python/2.5.1/python-2.5.1.msi} and install it.

\subsubsection{Install SIP}
Download \htmladdnormallink{http://www.riverbankcomputing.com/Downloads/sip4/sip-4.7.1.zip}{http://www.riverbankcomputing.com/Downloads/sip4/sip-4.7.1.zip} and extract it 
into your c:$\backslash$dev$\backslash$cpp directory.
From a Visual C++ command line cd to the directory where you extract SIP and run:

\begin{verbatim}
c:\python25\python configure.py -p win32-msvc2005
nmake
nmake install
\end{verbatim}

\subsubsection{Install PyQt4}
Download \htmladdnormallink{http://www.riverbankcomputing.com/Downloads/PyQt4/GPL/PyQt-win-gpl-4.3.1.zip}{http://www.riverbankcomputing.com/Downloads/PyQt4/GPL/PyQt-win-gpl-4.3.1.zip} and extract it 
into your c:$\backslash$dev$\backslash$cpp directory.
From a Visual C++ command line cd to the directory where you extracted PyQt4 and run:

\begin{verbatim}
c:\python25\python configure.py -p win32-msvc2005
nmake
nmake install
\end{verbatim}

\subsubsection{Install CMake}
Download and install cmake 2.4.7 or better, making sure to enable the 
option

\begin{verbatim}
Update path for all users
\end{verbatim}

\subsubsection{Install Subversion}
You '''must''' install the command line version if you want the CMake svn scripts to work.
Its a bit tricky to find the correct version on the subversion download site as they have 
som misleadingly named similar downloads. Easiest is to just get this file:

\htmladdnormallink{http://subversion.tigris.org/downloads/1.4.5-win32/apache-2.2/svn-win32-1.4.5.zip}{http://subversion.tigris.org/downloads/1.4.5-win32/apache-2.2/svn-win32-1.4.5.zip}

Extract the zip file to

\begin{verbatim}
C:\Program Files\svn
\end{verbatim}

And then add

\begin{verbatim}
C:\Program Files\svn\bin
\end{verbatim}

To your path.

\subsubsection{Initial SVN Check out}
Open a cmd.exe window and do:

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

At this point you will probably get a message like this:

\begin{verbatim}
C:\dev\cpp>svn co https://svn.osgeo.org/qgis/trunk/qgis
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 Sat, 01 Apr 2006 03:30:47 GMT until Fri, 21 Mar 2008 03:30:47 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}

Press 'p' to accept and the svn checkout will commence.

\subsubsection{Create Makefiles using cmakesetup.exe}
I wont be giving a detailed description of the build process, because 
the process is explained in the first section (where you manually build 
all dependencies) of the windows build notes in this document. Just skip 
past the parts where you need to build GDAL etc, since this simplified 
install process does all the dependency provisioning for you.

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

Cmakesetup should find all dependencies for you automatically (it uses the 
LIB\_DIR environment to find them all in c:$\backslash$dev$\backslash$cpp$\backslash$qgislibs-release). 
Press configure again after the cmakesetup gui appears and when all the red 
fields are gone, and you have made any personalisations to the setup, press 
ok to close the cmake gui.

Now open Visual Studio Express and do:

File -$>$ Open -$>$ Project / Solution

Now open the cmake generated QGIS solution which should be in :

\begin{verbatim}
c:\dev\cpp\qgis\build\qgisX.X.X.sln
\end{verbatim}

Where X.X.X represents the current version number of QGIS. Currently I 
have only made release built dependencies for QGIS (debug versions will follow 
in future), so you need to be sure to select 'Release' from the solution 
configurations toolbar.

Next right click on ALL\_BUILD in the solution browser, and then choose build.

Once the build completes right click on INSTALL in the solution browser and 
choose build. This will by default install qgis into c:$\backslash$program files$\backslash$qgisX.X.X.

\subsubsection{Running and packaging}
To run QGIS you need to at the minimum copy the dlls from c:$\backslash$dev$\backslash$cpp$\backslash$qgislibs-release$\backslash$bin 
into the c:$\backslash$program files$\backslash$qgisX.X.X directory.



