Skip to content

Commit 9ca32a6

Browse files
committed
Support building with Visual Studio 2015
Adjust the way we detect the locale. As a result the minumum Windows version supported by VS2015 and later is Windows Vista. Add some tweaks to remove new compiler warnings. Remove documentation references to the now obsolete msysGit. Michael Paquier, somewhat edited by me, reviewed by Christian Ullrich. Rather belated backpatch to 9.4 and 9.3
1 parent 35ea98f commit 9ca32a6

File tree

9 files changed

+166
-35
lines changed

9 files changed

+166
-35
lines changed

doc/src/sgml/install-windows.sgml

Lines changed: 16 additions & 13 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 2013
22+
Microsoft tools is to install <productname>Visual Studio Express 2015
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 2013</productname>.
25+
<productname>Microsoft Visual C++ 2005 to 2015</productname>.
2626
In some cases that requires the installation of the
2727
<productname>Windows SDK</productname> in addition to the compiler.
2828
</para>
@@ -77,19 +77,26 @@
7777
<productname>Visual Studio Express</productname> or some versions of the
7878
<productname>Microsoft Windows SDK</productname>. If you do not already have a
7979
<productname>Visual Studio</productname> environment set up, the easiest
80-
ways are to use the compilers from <productname>Visual Studio Express 2013
80+
ways are to use the compilers from <productname>Visual Studio Express 2015
8181
for Windows Desktop</productname> or those in the <productname>Windows SDK
8282
7.1</productname>, which are both free downloads from Microsoft.
8383
</para>
8484

8585
<para>
86-
PostgreSQL is known to support compilation using the compilers shipped with
86+
Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
87+
32-bit PostgreSQL buils are possible with
8788
<productname>Visual Studio 2005</productname> to
88-
<productname>Visual Studio 2013</productname> (including Express editions),
89+
<productname>Visual Studio 2015</productname> (including Express editions),
8990
as well as standalone Windows SDK releases 6.0 to 7.1.
90-
64-bit PostgreSQL builds are only supported with
91+
64-bit PostgreSQL builds are supported with
9192
<productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
92-
<productname>Visual Studio 2008</productname> and above.
93+
<productname>Visual Studio 2008</productname> and above. Compilation
94+
is supported down to <productname>Windows XP</productname> and
95+
<productname>Windows Server 2003</> when building with
96+
<productname>Visual Studio 2005</> to
97+
<productname>Visual Studio 2013</productname>. Building with
98+
<productname>Visual Studio 2015</productname> is supported down to
99+
<productname>Windows Vista</> and <productname>Windows Server 2008</>.
93100
</para>
94101

95102
<para>
@@ -211,9 +218,7 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
211218
Both <productname>Bison</productname> and <productname>Flex</productname>
212219
are included in the <productname>msys</productname> tool suite, available
213220
from <ulink url="http://www.mingw.org/wiki/MSYS"></> as part of the
214-
<productname>MinGW</productname> compiler suite. You can also get
215-
<productname>msys</productname> as part of
216-
<productname>msysGit</productname> from <ulink url="http://git-scm.com/"></>.
221+
<productname>MinGW</productname> compiler suite.
217222
</para>
218223

219224
<para>
@@ -222,9 +227,7 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
222227
PATH environment variable in <filename>buildenv.pl</filename> unless
223228
they are already in PATH. In the case of MinGW, the directory is the
224229
<filename>\msys\1.0\bin</filename> subdirectory of your MinGW
225-
installation directory. For msysGit, it's the <filename>bin</filename>
226-
directory in your Git install directory. Do not add the MinGW compiler
227-
tools themselves to PATH.
230+
installation directory.
228231
</para>
229232

230233
<note>

src/backend/port/win32/crashdump.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,21 @@
4141
#define WIN32_LEAN_AND_MEAN
4242
#include <windows.h>
4343
#include <string.h>
44+
/*
45+
* Some versions of the MS SDK contain "typedef enum { ... } ;" which the MS
46+
* compiler quite sanely complains about. Well done, Microsoft.
47+
* This pragma disables the warning just while we include the header.
48+
* The pragma is known to work with all (as at the time of writing) supported
49+
* versions of MSVC.
50+
*/
51+
#ifdef _MSC_VER
52+
#pragma warning(push)
53+
#pragma warning(disable : 4091)
54+
#endif
4455
#include <dbghelp.h>
56+
#ifdef _MSC_VER
57+
#pragma warning(pop)
58+
#endif
4559

4660
/*
4761
* Much of the following code is based on CodeProject and MSDN examples,

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,11 @@ BaseBackup(void)
18401840
int r;
18411841
#else
18421842
DWORD status;
1843+
/*
1844+
* get a pointer sized version of bgchild to avoid warnings about
1845+
* casting to a different size on WIN64.
1846+
*/
1847+
intptr_t bgchild_handle = bgchild;
18431848
uint32 hi,
18441849
lo;
18451850
#endif
@@ -1902,15 +1907,15 @@ BaseBackup(void)
19021907
InterlockedIncrement(&has_xlogendptr);
19031908

19041909
/* First wait for the thread to exit */
1905-
if (WaitForSingleObjectEx((HANDLE) bgchild, INFINITE, FALSE) !=
1910+
if (WaitForSingleObjectEx((HANDLE) bgchild_handle, INFINITE, FALSE) !=
19061911
WAIT_OBJECT_0)
19071912
{
19081913
_dosmaperr(GetLastError());
19091914
fprintf(stderr, _("%s: could not wait for child thread: %s\n"),
19101915
progname, strerror(errno));
19111916
disconnect_and_exit(1);
19121917
}
1913-
if (GetExitCodeThread((HANDLE) bgchild, &status) == 0)
1918+
if (GetExitCodeThread((HANDLE) bgchild_handle, &status) == 0)
19141919
{
19151920
_dosmaperr(GetLastError());
19161921
fprintf(stderr, _("%s: could not get child thread exit status: %s\n"),

src/include/port/win32.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@
66

77
/*
88
* Make sure _WIN32_WINNT has the minimum required value.
9-
* Leave a higher value in place.
10-
*/
11-
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
9+
* Leave a higher value in place. When building with at least Visual
10+
* Studio 2015 the minimum requirement is Windows Vista (0x0600) to
11+
* get support for GetLocaleInfoEx() with locales. For everything else
12+
* the minumum version is Windows XP (0x0501).
13+
* Also for VS2015, add a define that stops compiler complaints about
14+
* using the old Winsock API.
15+
*/
16+
#if defined(_MSC_VER) && _MSC_VER >= 1900
17+
#define _WINSOCK_DEPRECATED_NO_WARNINGS
18+
#define MIN_WINNT 0x0600
19+
#else
20+
#define MIN_WINNT 0x0501
21+
#endif
22+
23+
#if defined(_WIN32_WINNT) && _WIN32_WINNT < MIN_WINNT
1224
#undef _WIN32_WINNT
1325
#endif
26+
1427
#ifndef _WIN32_WINNT
15-
#define _WIN32_WINNT 0x0501
28+
#define _WIN32_WINNT MIN_WINNT
1629
#endif
30+
1731
/*
1832
* Always build with SSPI support. Keep it as a #define in case
1933
* we want a switch to disable it sometime in the future.

src/port/chklocale.c

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "postgres_fe.h"
2020
#endif
2121

22+
#if defined(WIN32) && (_MSC_VER >= 1900)
23+
#include <windows.h>
24+
#endif
25+
2226
#include <locale.h>
2327
#ifdef HAVE_LANGINFO_H
2428
#include <langinfo.h>
@@ -196,14 +200,24 @@ static const struct encoding_match encoding_match_list[] = {
196200
* locale machinery determine the code page. See comments at IsoLocaleName().
197201
* For other compilers, follow the locale's predictable format.
198202
*
203+
* Visual Studio 2015 should still be able to do the same, but the declaration
204+
* of lc_codepage is missing in _locale_t, causing this code compilation to
205+
* fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an
206+
* exception and post-VS2015 versions should be able to handle properly the
207+
* codepage number using _create_locale(). So, instead of the same logic as
208+
* VS 2012 and VS 2013, this routine uses GetLocaleInfoEx to parse short
209+
* locale names like "de-DE", "fr-FR", etc. If those cannot be parsed correctly
210+
* process falls back to the pre-VS-2010 manual parsing done with
211+
* using <Language>_<Country>.<CodePage> as a base.
212+
*
199213
* Returns a malloc()'d string for the caller to free.
200214
*/
201215
static char *
202216
win32_langinfo(const char *ctype)
203217
{
204218
char *r = NULL;
205219

206-
#if (_MSC_VER >= 1700)
220+
#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
207221
_locale_t loct = NULL;
208222

209223
loct = _create_locale(LC_CTYPE, ctype);
@@ -217,20 +231,41 @@ win32_langinfo(const char *ctype)
217231
#else
218232
char *codepage;
219233

220-
/*
221-
* Locale format on Win32 is <Language>_<Country>.<CodePage> . For
222-
* example, English_United States.1252.
223-
*/
224-
codepage = strrchr(ctype, '.');
225-
if (codepage != NULL)
226-
{
227-
int ln;
234+
#if (_MSC_VER >= 1900)
235+
uint32 cp;
236+
WCHAR wctype[LOCALE_NAME_MAX_LENGTH];
237+
238+
memset(wctype, 0, sizeof(wctype));
239+
MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, LOCALE_NAME_MAX_LENGTH);
228240

229-
codepage++;
230-
ln = strlen(codepage);
231-
r = malloc(ln + 3);
241+
if (GetLocaleInfoEx(wctype,
242+
LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
243+
(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
244+
{
245+
r = malloc(16); /* excess */
232246
if (r != NULL)
233-
sprintf(r, "CP%s", codepage);
247+
sprintf(r, "CP%u", cp);
248+
}
249+
else
250+
#endif
251+
{
252+
253+
/*
254+
* Locale format on Win32 is <Language>_<Country>.<CodePage> . For
255+
* example, English_United States.1252.
256+
*/
257+
codepage = strrchr(ctype, '.');
258+
if (codepage != NULL)
259+
{
260+
int ln;
261+
262+
codepage++;
263+
ln = strlen(codepage);
264+
r = malloc(ln + 3);
265+
if (r != NULL)
266+
sprintf(r, "CP%s", codepage);
267+
}
268+
234269
}
235270
#endif
236271

src/port/win32env.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ pgwin32_putenv(const char *envval)
8686
"msvcr120d", NULL, NULL
8787
},
8888
{
89-
NULL, NULL, NULL
89+
"urctbase", 0, NULL
90+
}, /* Visual Studio 2015 and later */
91+
{
92+
NULL, 0, NULL
9093
}
9194
};
9295
int i;

src/tools/msvc/MSBuildProject.pm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,27 @@ sub new
462462
return $self;
463463
}
464464

465+
package VC2015Project;
466+
467+
#
468+
# Package that encapsulates a Visual C++ 2015 project file
469+
#
470+
471+
use strict;
472+
use warnings;
473+
use base qw(VC2012Project);
474+
475+
sub new
476+
{
477+
my $classname = shift;
478+
my $self = $classname->SUPER::_new(@_);
479+
bless($self, $classname);
480+
481+
$self->{vcver} = '14.00';
482+
$self->{PlatformToolset} = 'v140';
483+
$self->{ToolsVersion} = '14.0';
484+
485+
return $self;
486+
}
487+
465488
1;

src/tools/msvc/Solution.pm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,32 @@ sub new
781781
return $self;
782782
}
783783

784+
package VS2015Solution;
785+
786+
#
787+
# Package that encapsulates a Visual Studio 2015 solution file
788+
#
789+
790+
use Carp;
791+
use strict;
792+
use warnings;
793+
use base qw(Solution);
794+
795+
sub new
796+
{
797+
my $classname = shift;
798+
my $self = $classname->SUPER::_new(@_);
799+
bless($self, $classname);
800+
801+
$self->{solutionFileVersion} = '12.00';
802+
$self->{vcver} = '14.00';
803+
$self->{visualStudioName} = 'Visual Studio 2015';
804+
$self->{VisualStudioVersion} = '14.0.24730.2';
805+
$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
806+
807+
return $self;
808+
}
809+
784810
sub GetAdditionalHeaders
785811
{
786812
my ($self, $f) = @_;

src/tools/msvc/VSObjectFactory.pm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ sub CreateSolution
4949
{
5050
return new VS2013Solution(@_);
5151
}
52+
elsif ($visualStudioVersion eq '14.00')
53+
{
54+
return new VS2015Solution(@_);
55+
}
5256
else
5357
{
5458
croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
8488
{
8589
return new VC2013Project(@_);
8690
}
91+
elsif ($visualStudioVersion eq '14.00')
92+
{
93+
return new VC2015Project(@_);
94+
}
8795
else
8896
{
8997
croak "The requested Visual Studio version is not supported.";
@@ -123,11 +131,11 @@ sub DetermineVisualStudioVersion
123131
sub _GetVisualStudioVersion
124132
{
125133
my ($major, $minor) = @_;
126-
if ($major > 12)
134+
if ($major > 14)
127135
{
128136
carp
129137
"The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
130-
return '12.00';
138+
return '14.00';
131139
}
132140
elsif ($major < 6)
133141
{

0 commit comments

Comments
 (0)