Skip to content

Commit 0fb54de

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. Backpatch to 9.5
1 parent 5945501 commit 0fb54de

File tree

9 files changed

+165
-34
lines changed

9 files changed

+165
-34
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>
@@ -210,9 +217,7 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
210217
Both <productname>Bison</productname> and <productname>Flex</productname>
211218
are included in the <productname>msys</productname> tool suite, available
212219
from <ulink url="http://www.mingw.org/wiki/MSYS"></> as part of the
213-
<productname>MinGW</productname> compiler suite. You can also get
214-
<productname>msys</productname> as part of
215-
<productname>msysGit</productname> from <ulink url="http://git-scm.com/"></>.
220+
<productname>MinGW</productname> compiler suite.
216221
</para>
217222

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

229232
<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
@@ -1830,6 +1830,11 @@ BaseBackup(void)
18301830
int r;
18311831
#else
18321832
DWORD status;
1833+
/*
1834+
* get a pointer sized version of bgchild to avoid warnings about
1835+
* casting to a different size on WIN64.
1836+
*/
1837+
intptr_t bgchild_handle = bgchild;
18331838
uint32 hi,
18341839
lo;
18351840
#endif
@@ -1892,15 +1897,15 @@ BaseBackup(void)
18921897
InterlockedIncrement(&has_xlogendptr);
18931898

18941899
/* First wait for the thread to exit */
1895-
if (WaitForSingleObjectEx((HANDLE) bgchild, INFINITE, FALSE) !=
1900+
if (WaitForSingleObjectEx((HANDLE) bgchild_handle, INFINITE, FALSE) !=
18961901
WAIT_OBJECT_0)
18971902
{
18981903
_dosmaperr(GetLastError());
18991904
fprintf(stderr, _("%s: could not wait for child thread: %s\n"),
19001905
progname, strerror(errno));
19011906
disconnect_and_exit(1);
19021907
}
1903-
if (GetExitCodeThread((HANDLE) bgchild, &status) == 0)
1908+
if (GetExitCodeThread((HANDLE) bgchild_handle, &status) == 0)
19041909
{
19051910
_dosmaperr(GetLastError());
19061911
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ pgwin32_putenv(const char *envval)
6969
{
7070
"msvcr120", 0, NULL
7171
}, /* Visual Studio 2013 */
72+
{
73+
"urctbase", 0, NULL
74+
}, /* Visual Studio 2015 and later */
7275
{
7376
NULL, 0, NULL
7477
}

src/tools/msvc/MSBuildProject.pm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,27 @@ sub new
465465
return $self;
466466
}
467467

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

src/tools/msvc/Solution.pm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,32 @@ sub new
790790
return $self;
791791
}
792792

793+
package VS2015Solution;
794+
795+
#
796+
# Package that encapsulates a Visual Studio 2015 solution file
797+
#
798+
799+
use Carp;
800+
use strict;
801+
use warnings;
802+
use base qw(Solution);
803+
804+
sub new
805+
{
806+
my $classname = shift;
807+
my $self = $classname->SUPER::_new(@_);
808+
bless($self, $classname);
809+
810+
$self->{solutionFileVersion} = '12.00';
811+
$self->{vcver} = '14.00';
812+
$self->{visualStudioName} = 'Visual Studio 2015';
813+
$self->{VisualStudioVersion} = '14.0.24730.2';
814+
$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
815+
816+
return $self;
817+
}
818+
793819
sub GetAdditionalHeaders
794820
{
795821
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.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
112120
sub _GetVisualStudioVersion
113121
{
114122
my ($major, $minor) = @_;
115-
if ($major > 12)
123+
if ($major > 14)
116124
{
117125
carp
118126
"The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
119-
return '12.00';
127+
return '14.00';
120128
}
121129
elsif ($major < 6)
122130
{

0 commit comments

Comments
 (0)