1
1
2
2
==Building with Microsoft Visual Studio==
3
3
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).
7
6
8
7
This section describes the setup required to allow Visual Studio to be used to
9
8
build QGIS.
@@ -24,62 +23,47 @@ Download and install following packages:
24
23
| OSGeo4W | http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86.exe (32bit) or http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe (64bit) |
25
24
| ninja | https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip |
26
25
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
+
31
30
For the QGIS build you need to install following packages from cygwin:
32
31
- bison
33
32
- flex
34
33
- git
35
34
-
36
35
37
- and from OSGeo4W (select //Advanced Installation//):
38
-
39
- - expat
40
- - fcgi
41
- - gdal
42
- - grass
43
- - gsl-devel
44
- - iconv
45
- - libzip-devel
46
- - libspatialindex-devel
47
- - pyqt5
48
- - python3-devel
49
- - python3-qscintilla
50
- - python3-nose2
51
- - python3-future
52
- - python3-pyyaml
53
- - python3-mock
54
- - qca-qt5-devel
55
- - qca-qt5-libs
56
- - qscintilla-qt5
57
- - qt5-devel
58
- - qt5-libs-debug
59
- - qtwebkit-qt5-devel
60
- - qtwebkit-qt5-libs-debug
61
- - qwt-devel-qt5
62
- - sip-qt5
63
- - spatialite
64
- - oci
65
- - qtkeychain
66
- - libzip
67
- -
68
-
69
-
36
+ OSGeo4W does not only provide ready packages for the current QGIS release and
37
+ nightly builds of master, but also offers most of the dependencies needs to
38
+ build it.
70
39
71
- This will also select packages the above packages depend on.
40
+ OSGeo4W Installation (select //Advanced Installation//):
41
+ The easiest way to install the build and run dependencies would be to run the following
42
+ command from cmd (otherwise you would need to select the packages one by one).
43
+ In the following example d:\OSGeo4W64 will refer to the destination OSGeo4W Path,
44
+ You may choose a different directory if you wish.
45
+ All the required packages are listed in the following command following a set of -P switches.
46
+ This will also select packages the above packages depend on.
47
+ The qgis-dev package [QGIS dev release] is also listed here, partly because then
48
+ all the runtime dependencies for QGIS will also get selected.
49
+ You may run OSGeo4W-setup-x86_64.exe --help to get a list of all the available parameters
50
+
51
+ ```
52
+ 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
53
+ ```
72
54
73
- If you install other packages, this might cause issues. Particularly, make sure
74
- **not** to install the msinttypes package. It installs a stdint.h file in
75
- OSGeo4W[64]\include, that conflicts with Visual Studio own stdint.h, which for
76
- example breaks the build of the virtuallayer provider.
55
+ If you install other packages, this might cause issues. Particularly, make sure
56
+ **not** to install the msinttypes package. It installs a stdint.h file in
57
+ OSGeo4W[64]\include, that conflicts with Visual Studio own stdint.h, which for
58
+ example breaks the build of the virtuallayer provider.
77
59
78
60
Earlier versions of this document also covered how to build all above
79
61
dependencies. If you're interested in that, check the history of this page in the Wiki
80
62
or the SVN repository.
81
63
82
-
64
+ ninja:
65
+ copy ninja.exe to d:\OSGeo4W64\bin\
66
+
83
67
=== Setting up the Visual Studio project with CMake ===
84
68
85
69
/!\ Consider this section as example. It tends to outdate, when OSGeo4W and
@@ -93,75 +77,113 @@ installed in the default locations):
93
77
94
78
```
95
79
@echo off
96
- set OSGEO4W_ROOT=C:\OSGeo4W
80
+
81
+ set OSGEO4W_ROOT=D:\OSGeo4W64
97
82
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
98
- call "%OSGEO4W_ROOT%\bin\py3_env.bat"
99
83
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
84
+ call "%OSGEO4W_ROOT%\bin\py3_env.bat"
100
85
101
- set O4W_ROOT=%OSGEO4W_ROOT:\=/%
102
- set LIB_DIR=%O4W_ROOT%
86
+ set VS140COMNTOOLS=%PROGRAMFILES(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\
87
+ call "%PROGRAMFILES(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
103
88
104
- call "C:\Program Files\ Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
105
- path %path%;C:\Program Files\ Microsoft Visual Studio 14.0\VC\bin
89
+ set INCLUDE=%INCLUDE%;%PROGRAMFILES(x86)%\ Microsoft SDKs\Windows\v7.1A\include
90
+ set LIB=%LIB%;%PROGRAMFILES(x86)%\ Microsoft SDKs\Windows\v7.1A\lib
106
91
107
- path %PATH%;C:\Program Files \CMake\bin;c:\cygwin\bin
92
+ path %PATH%;%PROGRAMFILES% \CMake\bin;c:\cygwin\bin
108
93
109
- @set GRASS_PREFIX=c:/OSGeo4W/ apps/ grass/ grass-7.2.1
94
+ @set GRASS_PREFIX="%OSGEO4W_ROOT%\ apps\ grass\ grass-7.2.1
110
95
@set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include
111
96
@set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\lib
112
97
113
- set LIB=%LIB%;%OSGEO4W_ROOT%\apps\Qt5\lib;%OSGEO4W_ROOT%\lib
114
- set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\apps\Qt5\include;%OSGEO4W_ROOT%\include
115
-
116
98
@cmd
117
99
```
118
100
119
- Start the batch file and on the command prompt checkout the QGIS source from
101
+ Save the batch file as ``d:\OSGeo4W64\OSGeo4W-dev.bat`` and run it.
102
+ On the command prompt checkout the QGIS source from
120
103
git to the source directory ``QGIS``:
121
104
122
-
123
105
```
124
106
git clone git://github.com/qgis/QGIS.git
125
107
```
126
108
127
- Create a 'build' directory somewhere. This will be where all the build output
128
- will be generated.
129
-
130
- Now run ``cmake-gui`` (still from ``cmd``) and in the //Where is the source code://
131
- box, browse to the top level QGIS directory.
132
-
133
- In the //Where to build the binaries:// box, browse to the 'build' directory you
134
- created.
135
-
136
- If the path to bison and flex contains blanks, you need to use the short name
137
- for the directory (i.e. ``C:\Program Files`` should be rewritten to
138
- ``C:\Progra~n``, where ``n`` is the number as shown in `dir /x C:\``).
139
-
140
- Verify that the 'BINDINGS_GLOBAL_INSTALL' option is not checked, so that python
141
- bindings are placed into the output directory when you run the INSTALL target.
142
-
143
- Hit ``Configure`` to start the configuration and select ``Visual Studio 9 2008``
144
- and keep ``native compilers`` and click ``Finish``.
145
-
146
- The configuration should complete without any further questions and allow you to
147
- click ``Generate``.
148
-
149
- Now close ``cmake-gui`` and continue on the command prompt by starting
150
- ``vcexpress``. Use File / Open / Project/Solutions and open the
151
- qgis-x.y.z.sln File in your project directory.
152
-
153
- Change ``Solution Configuration`` from ``Debug`` to ``RelWithDebInfo`` (Release
154
- with Debug Info) or ``Release`` before you build QGIS using the ALL_BUILD
155
- target (otherwise you need debug libraries that are not included).
156
-
157
- After the build completed you should install QGIS using the INSTALL target.
158
-
159
- Install QGIS by building the INSTALL project. By default this will install to
160
- c:\Program Files\qgis<version> (this can be changed by changing the
161
- CMAKE_INSTALL_PREFIX variable in cmake-gui).
162
-
163
- You will also either need to add all the dependency DLLs to the QGIS install
164
- directory or add their respective directories to your PATH.
109
+ Using package-nightly.cmd to create the MSVC solution file:
110
+ We will be using the file ms-windows/osgeo4w/package-nightly.cmd to create an MSVC solution file.
111
+ There are a few options for a solution file, following are the options: ninja, native MSVC.
112
+ The advantage of using native MSVC solution is that you can find the root of build problems much easily.
113
+ Currently the package-nightly.cmd file creates a ninja solution.
114
+ In order to modify it to create an MSVC solution instead, edit it and replace the following line:
115
+
116
+ ``cmake -G Ninja ^``
117
+ with
118
+ ``cmake -G "Visual Studio 14 2015 Win64" ^``
119
+
120
+ Currently, package-nightly.cmd will also build QGIS. if you want it only to create the solution file,
121
+ then following the line:
122
+ ``if errorlevel 1 (echo cmake failed & goto error)``
123
+ add the following line:
124
+ ``goto end``
125
+
126
+ Running package-nightly.cmd:
127
+ Run the batch file OSGeo4W-dev.bat you created before. On the command prompt run:
128
+ ```
129
+ package-nightly.cmd 2.99.0 1 qgis-dev x86_64
130
+ ```
131
+
132
+ Compiling QGIS with MSVC:
133
+ We will need to run MSVC with all the enviroment variables set, thus we will run it as follows:
134
+ Run the batch file OSGeo4W-dev.bat you created before. On the command prompt run: ``devenv``
135
+ From MSVC, open the solution file
136
+ ``d:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-dev-x86_64\qgis2.99.0.sln``
137
+ Try to build the solution [go grab a cup of coffee, it may take a while].
138
+ If it fails, run it again and again untill there are [hopefully] no errors.
139
+
140
+
141
+ Running QGIS from within MSVC:
142
+ Edit the properties of the project ALL_BUILD:
143
+ Debugging -> Command -> D:\OSGeo4W64\QGIS\ms-windows\osgeo4w\build-qgis-dev-x86_64\output\bin\RelWithDebInfo\qgis.exe
144
+ Run.
145
+ Ignore the "These projects are out of date" message, it appeares even if no files were was changed.
146
+
147
+
148
+ Old alternative method that might still work using cmake-gui:
149
+ Create a 'build' directory somewhere. This will be where all the build output
150
+ will be generated.
151
+
152
+ Now run ``cmake-gui`` (still from ``cmd``) and in the //Where is the source code://
153
+ box, browse to the top level QGIS directory.
154
+
155
+ In the //Where to build the binaries:// box, browse to the 'build' directory you
156
+ created.
157
+
158
+ If the path to bison and flex contains blanks, you need to use the short name
159
+ for the directory (i.e. ``C:\Program Files`` should be rewritten to
160
+ ``C:\Progra~n``, where ``n`` is the number as shown in `dir /x C:\``).
161
+
162
+ Verify that the 'BINDINGS_GLOBAL_INSTALL' option is not checked, so that python
163
+ bindings are placed into the output directory when you run the INSTALL target.
164
+
165
+ Hit ``Configure`` to start the configuration and select ``Visual Studio 9 2008``
166
+ and keep ``native compilers`` and click ``Finish``.
167
+
168
+ The configuration should complete without any further questions and allow you to
169
+ click ``Generate``.
170
+
171
+ Now close ``cmake-gui`` and continue on the command prompt by starting
172
+ ``vcexpress``. Use File / Open / Project/Solutions and open the
173
+ qgis-x.y.z.sln File in your project directory.
174
+
175
+ Change ``Solution Configuration`` from ``Debug`` to ``RelWithDebInfo`` (Release
176
+ with Debug Info) or ``Release`` before you build QGIS using the ALL_BUILD
177
+ target (otherwise you need debug libraries that are not included).
178
+
179
+ After the build completed you should install QGIS using the INSTALL target.
180
+
181
+ Install QGIS by building the INSTALL project. By default this will install to
182
+ c:\Program Files\qgis<version> (this can be changed by changing the
183
+ CMAKE_INSTALL_PREFIX variable in cmake-gui).
184
+
185
+ You will also either need to add all the dependency DLLs to the QGIS install
186
+ directory or add their respective directories to your PATH.
165
187
166
188
=== Packaging ===
167
189
0 commit comments