Skip to content

Commit 0ce8e49

Browse files
committed
Add support for Visual Studio 2019 in build scripts
This adjusts the documentation and the scripts related to the versions of Windows SDK supported. Author: Haribabu Kommi Reviewed-by: Andrew Dunstan, Juan José Santamaría Flecha, Michael Paquier Discussion: https://postgr.es/m/CAJrrPGcfqXhfPyMrny9apoDU7M1t59dzVAvoJ9AeAh5BJi+UzA@mail.gmail.com Backpatch-through: 9.4
1 parent 90434e6 commit 0ce8e49

File tree

5 files changed

+115
-27
lines changed

5 files changed

+115
-27
lines changed

doc/src/sgml/install-windows.sgml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
<para>
2020
There are several different ways of building PostgreSQL on
2121
<productname>Windows</productname>. The simplest way to build with
22-
Microsoft tools is to install <productname>Visual Studio Express 2017
22+
Microsoft tools is to install <productname>Visual Studio Express 2019
2323
for Windows Desktop</productname> and use the included
2424
compiler. It is also possible to build with the full
25-
<productname>Microsoft Visual C++ 2005 to 2017</productname>.
25+
<productname>Microsoft Visual C++ 2005 to 2019</productname>.
2626
In some cases that requires the installation of the
2727
<productname>Windows SDK</productname> in addition to the compiler.
2828
</para>
@@ -69,28 +69,29 @@
6969
<productname>Visual Studio Express</productname> or some versions of the
7070
<productname>Microsoft Windows SDK</productname>. If you do not already have a
7171
<productname>Visual Studio</productname> environment set up, the easiest
72-
ways are to use the compilers from <productname>Visual Studio Express 2017
72+
ways are to use the compilers from <productname>Visual Studio Express 2019
7373
for Windows Desktop</productname> or those in the <productname>Windows SDK
74-
8.1</productname>, which are both free downloads from Microsoft.
74+
10</productname>, which are both free downloads from Microsoft.
7575
</para>
7676

7777
<para>
7878
Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
7979
32-bit PostgreSQL builds are possible with
8080
<productname>Visual Studio 2005</productname> to
81-
<productname>Visual Studio 2017</productname> (including Express editions),
82-
as well as standalone Windows SDK releases 6.0 to 8.1.
81+
<productname>Visual Studio 2019</productname> (including Express editions),
82+
as well as standalone Windows SDK releases 6.0 to 10.
8383
64-bit PostgreSQL builds are supported with
84-
<productname>Microsoft Windows SDK</productname> version 6.0a to 8.1 or
84+
<productname>Microsoft Windows SDK</productname> version 6.0a to 10 or
8585
<productname>Visual Studio 2008</productname> and above. Compilation
8686
is supported down to <productname>Windows XP</productname> and
8787
<productname>Windows Server 2003</> when building with
8888
<productname>Visual Studio 2005</> to
8989
<productname>Visual Studio 2013</productname>. Building with
9090
<productname>Visual Studio 2015</productname> is supported down to
9191
<productname>Windows Vista</> and <productname>Windows Server 2008</>.
92-
Building with <productname>Visual Studio 2017</productname> is supported
93-
down to <productname>Windows 7 SP1</> and <productname>Windows Server 2008 R2 SP1</>.
92+
Building with <productname>Visual Studio 2017</productname> and
93+
<productname>Visual Studio 2019</productname> is supported
94+
down to <productname>Windows 7 SP1</> and <productname>Windows Server 2008 R2 SP1</>.
9495
</para>
9596

9697
<para>
@@ -162,7 +163,7 @@ $ENV{MSBFLAGS}="/m";
162163
If your build environment doesn't ship with a supported version of the
163164
<productname>Microsoft Windows SDK</productname> it
164165
is recommended that you upgrade to the latest version (currently
165-
version 7.1), available for download from
166+
version 10), available for download from
166167
<ulink url="https://www.microsoft.com/download"></>.
167168
</para>
168169
<para>

src/tools/msvc/MSBuildProject.pm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,29 @@ sub new
508508
return $self;
509509
}
510510

511+
package VC2019Project;
512+
513+
#
514+
# Package that encapsulates a Visual C++ 2019 project file
515+
#
516+
517+
use strict;
518+
use warnings;
519+
use base qw(VC2012Project);
520+
521+
no warnings qw(redefine); ## no critic
522+
523+
sub new
524+
{
525+
my $classname = shift;
526+
my $self = $classname->SUPER::_new(@_);
527+
bless($self, $classname);
528+
529+
$self->{vcver} = '16.00';
530+
$self->{PlatformToolset} = 'v142';
531+
$self->{ToolsVersion} = '16.0';
532+
533+
return $self;
534+
}
535+
511536
1;

src/tools/msvc/README

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MSVC build
44
==========
55

66
This directory contains the tools required to build PostgreSQL using
7-
Microsoft Visual Studio 2005 - 2017. This builds the whole backend, not just
7+
Microsoft Visual Studio 2005 - 2019. This builds the whole backend, not just
88
the libpq frontend library. For more information, see the documentation
99
chapter "Installation on Windows" and the description below.
1010

@@ -93,11 +93,12 @@ These configuration arguments are passed over to Mkvcbuild::mkvcbuild
9393
It does this by using VSObjectFactory::CreateSolution to create an object
9494
implementing the Solution interface (this could be either a VS2005Solution,
9595
a VS2008Solution, a VS2010Solution or a VS2012Solution or a VS2013Solution,
96-
or a VS2015Solution or a VS2017Solution, all in Solution.pm, depending on
97-
the user's build environment) and adding objects implementing the corresponding
98-
Project interface (VC2005Project or VC2008Project from VCBuildProject.pm or
99-
VC2010Project or VC2012Project or VC2013Project or VC2015Project or VC2017Project
100-
from MSBuildProject.pm) to it.
96+
or a VS2015Solution or a VS2017Solution or a VS2019Solution, all in
97+
Solution.pm, depending on the user's build environment) and adding objects
98+
implementing the corresponding Project interface (VC2005Project or
99+
VC2008Project from VCBuildProject.pm or VC2010Project or VC2012Project or
100+
VC2013Project or VC2015Project or VC2017Project or VC2019Project from
101+
MSBuildProject.pm) to it.
101102
When Solution::Save is called, the implementations of Solution and Project
102103
save their content in the appropriate format.
103104
The final step of starting the appropriate build program (msbuild or vcbuild)

src/tools/msvc/Solution.pm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,34 @@ sub new
972972
return $self;
973973
}
974974

975+
package VS2019Solution;
976+
977+
#
978+
# Package that encapsulates a Visual Studio 2019 solution file
979+
#
980+
981+
use Carp;
982+
use strict;
983+
use warnings;
984+
use base qw(Solution);
985+
986+
no warnings qw(redefine); ## no critic
987+
988+
sub new
989+
{
990+
my $classname = shift;
991+
my $self = $classname->SUPER::_new(@_);
992+
bless($self, $classname);
993+
994+
$self->{solutionFileVersion} = '12.00';
995+
$self->{vcver} = '16.00';
996+
$self->{visualStudioName} = 'Visual Studio 2019';
997+
$self->{VisualStudioVersion} = '16.0.28729.10';
998+
$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
999+
1000+
return $self;
1001+
}
1002+
9751003
sub GetAdditionalHeaders
9761004
{
9771005
my ($self, $f) = @_;

src/tools/msvc/VSObjectFactory.pm

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,30 @@ sub CreateSolution
5353
{
5454
return new VS2015Solution(@_);
5555
}
56-
# visual 2017 hasn't changed the nmake version to 15, so adjust the check to support it.
57-
elsif (($visualStudioVersion ge '14.10') or ($visualStudioVersion eq '15.00'))
56+
57+
# The version of nmake bundled in Visual Studio 2017 is greater
58+
# than 14.10 and less than 14.20. And the version number is
59+
# actually 15.00.
60+
elsif (
61+
($visualStudioVersion ge '14.10' && $visualStudioVersion lt '14.20')
62+
|| $visualStudioVersion eq '15.00')
5863
{
5964
return new VS2017Solution(@_);
6065
}
66+
67+
# The version of nmake bundled in Visual Studio 2019 is greater
68+
# than 14.20 and less than 14.30. And the version number is
69+
# actually 16.00.
70+
elsif (
71+
($visualStudioVersion ge '14.20' && $visualStudioVersion lt '14.30')
72+
|| $visualStudioVersion eq '16.00')
73+
{
74+
return new VS2019Solution(@_);
75+
}
6176
else
6277
{
63-
croak $visualStudioVersion;
64-
croak "The requested Visual Studio version is not supported.";
78+
croak
79+
"The requested Visual Studio version $visualStudioVersion is not supported.";
6580
}
6681
}
6782

@@ -98,15 +113,30 @@ sub CreateProject
98113
{
99114
return new VC2015Project(@_);
100115
}
101-
# visual 2017 hasn't changed the nmake version to 15, so adjust the check to support it.
102-
elsif (($visualStudioVersion ge '14.10') or ($visualStudioVersion eq '15.00'))
116+
117+
# The version of nmake bundled in Visual Studio 2017 is greater
118+
# than 14.10 and less than 14.20. And the version number is
119+
# actually 15.00.
120+
elsif (
121+
($visualStudioVersion ge '14.10' && $visualStudioVersion lt '14.20')
122+
|| $visualStudioVersion eq '15.00')
103123
{
104124
return new VC2017Project(@_);
105125
}
126+
127+
# The version of nmake bundled in Visual Studio 2019 is greater
128+
# than 14.20 and less than 14.30. And the version number is
129+
# actually 16.00.
130+
elsif (
131+
($visualStudioVersion ge '14.20' && $visualStudioVersion lt '14.30')
132+
|| $visualStudioVersion eq '16.00')
133+
{
134+
return new VC2019Project(@_);
135+
}
106136
else
107137
{
108-
croak $visualStudioVersion;
109-
croak "The requested Visual Studio version is not supported.";
138+
croak
139+
"The requested Visual Studio version $visualStudioVersion is not supported.";
110140
}
111141
}
112142

@@ -132,12 +162,15 @@ sub DetermineVisualStudioVersion
132162
sub _GetVisualStudioVersion
133163
{
134164
my ($major, $minor) = @_;
135-
# visual 2017 hasn't changed the nmake version to 15, so still using the older version for comparison.
136-
if ($major > 14)
165+
166+
# The major visual studio that is supported has nmake
167+
# version <= 14.30, so stick with it as the latest version
168+
# if bumping on something even newer.
169+
if ($major >= 14 && $minor >= 30)
137170
{
138171
carp
139172
"The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
140-
return '14.00';
173+
return '14.20';
141174
}
142175
elsif ($major < 6)
143176
{

0 commit comments

Comments
 (0)