Skip to content

Commit cab6a4b

Browse files
authored
Merge pull request #4990 from imiara/master
Updated instructions on building QGIS master under MSVC 2015
2 parents 5797c49 + 1a2213d commit cab6a4b

File tree

1 file changed

+102
-63
lines changed

1 file changed

+102
-63
lines changed

doc/msvc.t2t

+102-63
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

22
==Building with Microsoft Visual Studio==
33

4-
This section describes how to build QGIS using Visual Studio on Windows. This
5-
is currently also how the binary QGIS packages are made (earlier versions used
6-
MinGW).
4+
This section describes how to build QGIS using Visual Studio (MSVC) 2015 on Windows.
5+
This is currently also how the binary QGIS packages are made (earlier versions used MinGW).
76

87
This section describes the setup required to allow Visual Studio to be used to
98
build QGIS.
@@ -24,10 +23,10 @@ Download and install following packages:
2423
| OSGeo4W | http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86.exe (32bit) or http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe (64bit) |
2524
| ninja | https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip |
2625

27-
OSGeo4W does not only provide ready packages for the current QGIS release and
28-
nightly builds of master, but also offers most of the dependencies needs to
29-
build it.
30-
26+
cygwin:
27+
You should install cygwin to c:\cygwin (and not c:\cygwin64, which is the default for the x64)
28+
otherwise you would need to edit some batch files.
29+
3130
For the QGIS build you need to install following packages from cygwin:
3231
- bison
3332
- flex
@@ -41,16 +40,18 @@ and from OSGeo4W (select //Advanced Installation//):
4140

4241
This will also select packages the above packages depend on.
4342

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

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

53-
52+
ninja:
53+
copy ninja.exe to d:\OSGeo4W64\bin\
54+
5455
=== Setting up the Visual Studio project with CMake ===
5556

5657
/!\ Consider this section as example. It tends to outdate, when OSGeo4W and
@@ -64,75 +65,113 @@ installed in the default locations):
6465

6566
```
6667
@echo off
67-
set OSGEO4W_ROOT=C:\OSGeo4W
68+
69+
set OSGEO4W_ROOT=D:\OSGeo4W64
6870
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
69-
call "%OSGEO4W_ROOT%\bin\py3_env.bat"
7071
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
72+
call "%OSGEO4W_ROOT%\bin\py3_env.bat"
7173

72-
set O4W_ROOT=%OSGEO4W_ROOT:\=/%
73-
set LIB_DIR=%O4W_ROOT%
74+
set VS140COMNTOOLS=%PROGRAMFILES(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\
75+
call "%PROGRAMFILES(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
7476

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

78-
path %PATH%;C:\Program Files\CMake\bin;c:\cygwin\bin
80+
path %PATH%;%PROGRAMFILES%\CMake\bin;c:\cygwin\bin
7981

80-
@set GRASS_PREFIX=c:/OSGeo4W/apps/grass/grass-7.2.1
82+
@set GRASS_PREFIX="%OSGEO4W_ROOT%\apps\grass\grass-7.2.1
8183
@set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include
8284
@set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\lib
8385

84-
set LIB=%LIB%;%OSGEO4W_ROOT%\apps\Qt5\lib;%OSGEO4W_ROOT%\lib
85-
set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\apps\Qt5\include;%OSGEO4W_ROOT%\include
86-
8786
@cmd
8887
```
8988

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

93-
9493
```
9594
git clone git://github.com/qgis/QGIS.git
9695
```
9796

98-
Create a 'build' directory somewhere. This will be where all the build output
99-
will be generated.
100-
101-
Now run ``cmake-gui`` (still from ``cmd``) and in the //Where is the source code://
102-
box, browse to the top level QGIS directory.
103-
104-
In the //Where to build the binaries:// box, browse to the 'build' directory you
105-
created.
106-
107-
If the path to bison and flex contains blanks, you need to use the short name
108-
for the directory (i.e. ``C:\Program Files`` should be rewritten to
109-
``C:\Progra~n``, where ``n`` is the number as shown in `dir /x C:\``).
110-
111-
Verify that the 'BINDINGS_GLOBAL_INSTALL' option is not checked, so that python
112-
bindings are placed into the output directory when you run the INSTALL target.
113-
114-
Hit ``Configure`` to start the configuration and select ``Visual Studio 9 2008``
115-
and keep ``native compilers`` and click ``Finish``.
116-
117-
The configuration should complete without any further questions and allow you to
118-
click ``Generate``.
119-
120-
Now close ``cmake-gui`` and continue on the command prompt by starting
121-
``vcexpress``. Use File / Open / Project/Solutions and open the
122-
qgis-x.y.z.sln File in your project directory.
123-
124-
Change ``Solution Configuration`` from ``Debug`` to ``RelWithDebInfo`` (Release
125-
with Debug Info) or ``Release`` before you build QGIS using the ALL_BUILD
126-
target (otherwise you need debug libraries that are not included).
127-
128-
After the build completed you should install QGIS using the INSTALL target.
129-
130-
Install QGIS by building the INSTALL project. By default this will install to
131-
c:\Program Files\qgis<version> (this can be changed by changing the
132-
CMAKE_INSTALL_PREFIX variable in cmake-gui).
133-
134-
You will also either need to add all the dependency DLLs to the QGIS install
135-
directory or add their respective directories to your PATH.
97+
Using package-nightly.cmd to create the MSVC solution file:
98+
We will be using the file ms-windows/osgeo4w/package-nightly.cmd to create an MSVC solution file.
99+
There are a few options for a solution file, following are the options: ninja, native MSVC.
100+
The advantage of using native MSVC solution is that you can find the root of build problems much easily.
101+
Currently the package-nightly.cmd file creates a ninja solution.
102+
In order to modify it to create an MSVC solution instead, edit it and replace the following line:
103+
104+
``cmake -G Ninja ^``
105+
with
106+
``cmake -G "Visual Studio 14 2015 Win64" ^``
107+
108+
Currently, package-nightly.cmd will also build QGIS. if you want it only to create the solution file,
109+
then following the line:
110+
``if errorlevel 1 (echo cmake failed & goto error)``
111+
add the following line:
112+
``goto end``
113+
114+
Running package-nightly.cmd:
115+
Run the batch file OSGeo4W-dev.bat you created before. On the command prompt run:
116+
```
117+
package-nightly.cmd 2.99.0 1 qgis-dev x86_64
118+
```
119+
120+
Compiling QGIS with MSVC:
121+
We will need to run MSVC with all the environment variables set, thus we will run it as follows:
122+
Run the batch file OSGeo4W-dev.bat you created before. On the command prompt run: ``devenv``
123+
From MSVC, open the solution file
124+
``d:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-dev-x86_64\qgis2.99.0.sln``
125+
Try to build the solution [go grab a cup of tea, it may take a while].
126+
If it fails, run it again and again until there are [hopefully] no errors.
127+
128+
129+
Running QGIS from within MSVC:
130+
Edit the properties of the project ALL_BUILD:
131+
Debugging -> Command -> D:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-dev-x86_64\output\bin\RelWithDebInfo\qgis.exe
132+
Run.
133+
Ignore the "These projects are out of date" message, it appeares even if no files were was changed.
134+
135+
136+
Old alternative method that might still work using cmake-gui:
137+
Create a 'build' directory somewhere. This will be where all the build output
138+
will be generated.
139+
140+
Now run ``cmake-gui`` (still from ``cmd``) and in the //Where is the source code://
141+
box, browse to the top level QGIS directory.
142+
143+
In the //Where to build the binaries:// box, browse to the 'build' directory you
144+
created.
145+
146+
If the path to bison and flex contains blanks, you need to use the short name
147+
for the directory (i.e. ``C:\Program Files`` should be rewritten to
148+
``C:\Progra~n``, where ``n`` is the number as shown in `dir /x C:\``).
149+
150+
Verify that the 'BINDINGS_GLOBAL_INSTALL' option is not checked, so that python
151+
bindings are placed into the output directory when you run the INSTALL target.
152+
153+
Hit ``Configure`` to start the configuration and select ``Visual Studio 9 2008``
154+
and keep ``native compilers`` and click ``Finish``.
155+
156+
The configuration should complete without any further questions and allow you to
157+
click ``Generate``.
158+
159+
Now close ``cmake-gui`` and continue on the command prompt by starting
160+
``vcexpress``. Use File / Open / Project/Solutions and open the
161+
qgis-x.y.z.sln File in your project directory.
162+
163+
Change ``Solution Configuration`` from ``Debug`` to ``RelWithDebInfo`` (Release
164+
with Debug Info) or ``Release`` before you build QGIS using the ALL_BUILD
165+
target (otherwise you need debug libraries that are not included).
166+
167+
After the build completed you should install QGIS using the INSTALL target.
168+
169+
Install QGIS by building the INSTALL project. By default this will install to
170+
c:\Program Files\qgis<version> (this can be changed by changing the
171+
CMAKE_INSTALL_PREFIX variable in cmake-gui).
172+
173+
You will also either need to add all the dependency DLLs to the QGIS install
174+
directory or add their respective directories to your PATH.
136175

137176
=== Packaging ===
138177

0 commit comments

Comments
 (0)