Skip to content

Commit

Permalink
Updated instructions on building QGIS master under MSVC 2015
Browse files Browse the repository at this point in the history
  • Loading branch information
Idan Miara committed Aug 6, 2017
1 parent 42d7e0b commit 23c7b29
Showing 1 changed file with 119 additions and 97 deletions.
216 changes: 119 additions & 97 deletions doc/msvc.t2t
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

==Building with Microsoft Visual Studio==

This section describes how to build QGIS using Visual Studio on Windows. This
is currently also how the binary QGIS packages are made (earlier versions used
MinGW).
This section describes how to build QGIS using Visual Studio (MSVC) 2015 on Windows.
This is currently also how 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.
Expand All @@ -24,62 +23,47 @@ Download and install following packages:
| OSGeo4W | http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86.exe (32bit) or http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe (64bit) |
| ninja | https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip |

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

cygwin:
You should install cygwin to c:\cygwin (and not c:\cygwin64, which is the default for the x64)
otherwise you would need to edit some batch files.
For the QGIS build you need to install following packages from cygwin:
- bison
- flex
- git
-

and from OSGeo4W (select //Advanced Installation//):

- expat
- fcgi
- gdal
- grass
- gsl-devel
- iconv
- libzip-devel
- libspatialindex-devel
- pyqt5
- python3-devel
- python3-qscintilla
- python3-nose2
- python3-future
- python3-pyyaml
- python3-mock
- qca-qt5-devel
- qca-qt5-libs
- qscintilla-qt5
- qt5-devel
- qt5-libs-debug
- qtwebkit-qt5-devel
- qtwebkit-qt5-libs-debug
- qwt-devel-qt5
- sip-qt5
- spatialite
- oci
- qtkeychain
- libzip
-


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

This will also select packages the above packages depend on.
OSGeo4W Installation (select //Advanced Installation//):
The easiest way to install the build and run dependencies would be to run the following
command from cmd (otherwise you would need to select the packages one by one).
In the following example d:\OSGeo4W64 will refer to the destination OSGeo4W Path,
You may choose a different directory if you wish.
All the required packages are listed in the following command following a set of -P switches.
This will also select packages the above packages depend on.
The qgis-dev package [QGIS dev release] is also listed here, partly because then
all the runtime dependencies for QGIS will also get selected.
You may run OSGeo4W-setup-x86_64.exe --help to get a list of all the available parameters

```
OSGeo4W-setup-x86_64.exe -R d:\OSGeo4W64 -a x86_64 -A -k -P qgis-dev -P qtkeychain-qt5-devel -P oci-devel -P expat -P fcgi -P gdal -P grass -P gsl-devel -P iconv -P libzip-devel -P libspatialindex-devel -P pyqt5 -P python3-devel -P python3-qscintilla -P python3-nose2 -P python3-future -P python3-pyyaml -P python3-mock -P qca-qt5-devel -P qca-qt5-libs -P qscintilla-qt5 -P qt5-devel -P qt5-libs-debug -P qtwebkit-qt5-devel -P qtwebkit-qt5-libs-debug -P qwt-devel-qt5 -P sip-qt5 -P spatialite
```

If you install other packages, this might cause issues. Particularly, make sure
**not** to install the msinttypes package. It installs a stdint.h file in
OSGeo4W[64]\include, that conflicts with Visual Studio own stdint.h, which for
example breaks the build of the virtuallayer provider.
If you install other packages, this might cause issues. Particularly, make sure
**not** to install the msinttypes package. It installs a stdint.h file in
OSGeo4W[64]\include, that conflicts with Visual Studio own stdint.h, which for
example breaks the build of the virtuallayer provider.

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.


ninja:
copy ninja.exe to d:\OSGeo4W64\bin\

=== Setting up the Visual Studio project with CMake ===

/!\ Consider this section as example. It tends to outdate, when OSGeo4W and
Expand All @@ -93,75 +77,113 @@ installed in the default locations):

```
@echo off
set OSGEO4W_ROOT=C:\OSGeo4W

set OSGEO4W_ROOT=D:\OSGeo4W64
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"

set O4W_ROOT=%OSGEO4W_ROOT:\=/%
set LIB_DIR=%O4W_ROOT%
set VS140COMNTOOLS=%PROGRAMFILES(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\
call "%PROGRAMFILES(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

call "C:\Program Files\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
path %path%;C:\Program Files\Microsoft Visual Studio 14.0\VC\bin
set INCLUDE=%INCLUDE%;%PROGRAMFILES(x86)%\Microsoft SDKs\Windows\v7.1A\include
set LIB=%LIB%;%PROGRAMFILES(x86)%\Microsoft SDKs\Windows\v7.1A\lib

path %PATH%;C:\Program Files\CMake\bin;c:\cygwin\bin
path %PATH%;%PROGRAMFILES%\CMake\bin;c:\cygwin\bin

@set GRASS_PREFIX=c:/OSGeo4W/apps/grass/grass-7.2.1
@set GRASS_PREFIX="%OSGEO4W_ROOT%\apps\grass\grass-7.2.1
@set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include
@set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\lib

set LIB=%LIB%;%OSGEO4W_ROOT%\apps\Qt5\lib;%OSGEO4W_ROOT%\lib
set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\apps\Qt5\include;%OSGEO4W_ROOT%\include

@cmd
```

Start the batch file and on the command prompt checkout the QGIS source from
Save the batch file as ``d:\OSGeo4W64\OSGeo4W-dev.bat`` and run it.
On the command prompt checkout the QGIS source from
git to the source directory ``QGIS``:


```
git clone git://github.com/qgis/QGIS.git
```

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

Now run ``cmake-gui`` (still from ``cmd``) and 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.

If the path to bison and flex contains blanks, you need to use the short name
for the directory (i.e. ``C:\Program Files`` should be rewritten to
``C:\Progra~n``, where ``n`` is the number as shown in `dir /x C:\``).

Verify that the 'BINDINGS_GLOBAL_INSTALL' option is not checked, so that python
bindings are placed into the output directory when you run the INSTALL target.

Hit ``Configure`` to start the configuration and select ``Visual Studio 9 2008``
and keep ``native compilers`` and click ``Finish``.

The configuration should complete without any further questions and allow you to
click ``Generate``.

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

Change ``Solution Configuration`` from ``Debug`` to ``RelWithDebInfo`` (Release
with Debug Info) or ``Release`` before you build QGIS using the ALL_BUILD
target (otherwise you need debug libraries that are not included).

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:\Program Files\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.
Using package-nightly.cmd to create the MSVC solution file:
We will be using the file ms-windows/osgeo4w/package-nightly.cmd to create an MSVC solution file.
There are a few options for a solution file, following are the options: ninja, native MSVC.
The advantage of using native MSVC solution is that you can find the root of build problems much easily.
Currently the package-nightly.cmd file creates a ninja solution.
In order to modify it to create an MSVC solution instead, edit it and replace the following line:

``cmake -G Ninja ^``
with
``cmake -G "Visual Studio 14 2015 Win64" ^``

Currently, package-nightly.cmd will also build QGIS. if you want it only to create the solution file,
then following the line:
``if errorlevel 1 (echo cmake failed & goto error)``
add the following line:
``goto end``

Running package-nightly.cmd:
Run the batch file OSGeo4W-dev.bat you created before. On the command prompt run:
```
package-nightly.cmd 2.99.0 1 qgis-dev x86_64
```

Compiling QGIS with MSVC:
We will need to run MSVC with all the enviroment variables set, thus we will run it as follows:
Run the batch file OSGeo4W-dev.bat you created before. On the command prompt run: ``devenv``
From MSVC, open the solution file
``d:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-dev-x86_64\qgis2.99.0.sln``
Try to build the solution [go grab a cup of coffee, it may take a while].
If it fails, run it again and again untill there are [hopefully] no errors.


Running QGIS from within MSVC:
Edit the properties of the project ALL_BUILD:
Debugging -> Command -> D:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-dev-x86_64\output\bin\RelWithDebInfo\qgis.exe
Run.
Ignore the "These projects are out of date" message, it appeares even if no files were was changed.


Old alternative method that might still work using cmake-gui:
Create a 'build' directory somewhere. This will be where all the build output
will be generated.

Now run ``cmake-gui`` (still from ``cmd``) and 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.

If the path to bison and flex contains blanks, you need to use the short name
for the directory (i.e. ``C:\Program Files`` should be rewritten to
``C:\Progra~n``, where ``n`` is the number as shown in `dir /x C:\``).

Verify that the 'BINDINGS_GLOBAL_INSTALL' option is not checked, so that python
bindings are placed into the output directory when you run the INSTALL target.

Hit ``Configure`` to start the configuration and select ``Visual Studio 9 2008``
and keep ``native compilers`` and click ``Finish``.

The configuration should complete without any further questions and allow you to
click ``Generate``.

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

Change ``Solution Configuration`` from ``Debug`` to ``RelWithDebInfo`` (Release
with Debug Info) or ``Release`` before you build QGIS using the ALL_BUILD
target (otherwise you need debug libraries that are not included).

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:\Program Files\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.

=== Packaging ===

Expand Down

0 comments on commit 23c7b29

Please sign in to comment.