Skip to content

Commit 56c08df

Browse files
committed
Enable building with Visual Studion 2013.
Backpatch to 9.3. Brar Piening.
1 parent 8cb90b2 commit 56c08df

File tree

9 files changed

+141
-26
lines changed

9 files changed

+141
-26
lines changed

doc/src/sgml/install-windows.sgml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
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 2012
22+
Microsoft tools is to install <productname>Visual Studio Express 2013
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, 2008 or 2010</productname>. In some cases
26-
that requires the installation of the <productname>Windows SDK</productname>
27-
in addition to the compiler.
25+
<productname>Microsoft Visual C++ 2005 to 2013</productname>.
26+
In some cases that requires the installation of the
27+
<productname>Windows SDK</productname> in addition to the compiler.
2828
</para>
2929

3030
<para>
@@ -77,15 +77,15 @@
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 in the <productname>Windows SDK 7.1</productname>
81-
or those from <productname>Visual Studio Express 2012 for Windows
82-
Desktop</productname>, which are both free downloads from Microsoft.
80+
ways are to use the compilers from <productname>Visual Studio Express 2013
81+
for Windows Desktop</productname> or those in the <productname>Windows SDK
82+
7.1</productname>, which are both free downloads from Microsoft.
8383
</para>
8484

8585
<para>
8686
PostgreSQL is known to support compilation using the compilers shipped with
8787
<productname>Visual Studio 2005</productname> to
88-
<productname>Visual Studio 2012</productname> (including Express editions),
88+
<productname>Visual Studio 2013</productname> (including Express editions),
8989
as well as standalone Windows SDK releases 6.0 to 7.1.
9090
64-bit PostgreSQL builds are only supported with
9191
<productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or

src/backend/utils/adt/float.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,24 @@ get_float8_infinity(void)
111111
#endif
112112
}
113113

114+
/*
115+
* The funny placements of the two #pragmas is necessary because of a
116+
* long lived bug in the Microsoft compilers.
117+
* See http://support.microsoft.com/kb/120968/en-us for details
118+
*/
119+
#if (_MSC_VER >= 1800)
120+
#pragma warning(disable:4756)
121+
#endif
114122
float
115123
get_float4_infinity(void)
116124
{
117125
#ifdef INFINITY
118126
/* C99 standard way */
119127
return (float) INFINITY;
120128
#else
129+
#if (_MSC_VER >= 1800)
130+
#pragma warning(default:4756)
131+
#endif
121132

122133
/*
123134
* On some platforms, HUGE_VAL is an infinity, elsewhere it's just the

src/bin/pg_ctl/pg_ctl.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ static void print_msg(const char *msg);
135135
static void adjust_data_dir(void);
136136

137137
#if defined(WIN32) || defined(__CYGWIN__)
138+
#if (_MSC_VER >= 1800)
139+
#include <versionhelpers.h>
140+
#else
141+
static bool IsWindowsXPOrGreater(void);
142+
static bool IsWindows7OrGreater(void);
143+
#endif
138144
static bool pgwin32_IsInstalled(SC_HANDLE);
139145
static char *pgwin32_CommandLine(bool);
140146
static void pgwin32_doRegister(void);
@@ -1227,6 +1233,29 @@ do_kill(pgpid_t pid)
12271233

12281234
#if defined(WIN32) || defined(__CYGWIN__)
12291235

1236+
#if (_MSC_VER < 1800)
1237+
static bool
1238+
IsWindowsXPOrGreater(void)
1239+
{
1240+
OSVERSIONINFO osv;
1241+
osv.dwOSVersionInfoSize = sizeof(osv);
1242+
1243+
/* Windows XP = Version 5.1 */
1244+
return (!GetVersionEx(&osv) || /* could not get version */
1245+
osv.dwMajorVersion > 5 || (osv.dwMajorVersion == 5 && osv.dwMinorVersion >= 1));
1246+
}
1247+
1248+
static bool IsWindows7OrGreater(void)
1249+
{
1250+
OSVERSIONINFO osv;
1251+
osv.dwOSVersionInfoSize = sizeof(osv);
1252+
1253+
/* Windows 7 = Version 6.0 */
1254+
return (!GetVersionEx(&osv) || /* could not get version */
1255+
osv.dwMajorVersion > 6 || (osv.dwMajorVersion == 6 && osv.dwMinorVersion >= 0));
1256+
}
1257+
#endif
1258+
12301259
static bool
12311260
pgwin32_IsInstalled(SC_HANDLE hSCM)
12321261
{
@@ -1656,12 +1685,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
16561685
* IsProcessInJob() is not available on < WinXP, so there is no need
16571686
* to log the error every time in that case
16581687
*/
1659-
OSVERSIONINFO osv;
1660-
1661-
osv.dwOSVersionInfoSize = sizeof(osv);
1662-
if (!GetVersionEx(&osv) || /* could not get version */
1663-
(osv.dwMajorVersion == 5 && osv.dwMinorVersion > 0) || /* 5.1=xp, 5.2=2003, etc */
1664-
osv.dwMajorVersion > 5) /* anything newer should have the API */
1688+
if (IsWindowsXPOrGreater())
16651689

16661690
/*
16671691
* Log error if we can't get version, or if we're on WinXP/2003 or
@@ -1693,7 +1717,6 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
16931717
JOBOBJECT_BASIC_LIMIT_INFORMATION basicLimit;
16941718
JOBOBJECT_BASIC_UI_RESTRICTIONS uiRestrictions;
16951719
JOBOBJECT_SECURITY_LIMIT_INFORMATION securityLimit;
1696-
OSVERSIONINFO osv;
16971720

16981721
ZeroMemory(&basicLimit, sizeof(basicLimit));
16991722
ZeroMemory(&uiRestrictions, sizeof(uiRestrictions));
@@ -1709,10 +1732,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
17091732

17101733
if (as_service)
17111734
{
1712-
osv.dwOSVersionInfoSize = sizeof(osv);
1713-
if (!GetVersionEx(&osv) ||
1714-
osv.dwMajorVersion < 6 ||
1715-
(osv.dwMajorVersion == 6 && osv.dwMinorVersion == 0))
1735+
if (!IsWindows7OrGreater())
17161736
{
17171737
/*
17181738
* On Windows 7 (and presumably later),

src/include/pg_config.h.win32

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@
307307
/* #undef HAVE_READLINK */
308308

309309
/* Define to 1 if you have the `rint' function. */
310-
/*#define HAVE_RINT 1*/
310+
#if (_MSC_VER >= 1800)
311+
#define HAVE_RINT 1
312+
#endif
313+
311314

312315
/* Define to 1 if you have the global variable
313316
'rl_completion_append_character'. */

src/include/port/win32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,10 @@ typedef unsigned short mode_t;
427427
#define W_OK 2
428428
#define R_OK 4
429429

430+
#if (_MSC_VER < 1800)
430431
#define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
431432
#define isnan(x) _isnan(x)
433+
#endif
432434

433435
/* Pulled from Makefile.port in mingw */
434436
#define DLSUFFIX ".dll"

src/tools/msvc/MSBuildProject.pm

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sub _new
1818
bless($self, $classname);
1919

2020
$self->{filenameExtension} = '.vcxproj';
21+
$self->{ToolsVersion} = '4.0';
2122

2223
return $self;
2324
}
@@ -28,7 +29,7 @@ sub WriteHeader
2829

2930
print $f <<EOF;
3031
<?xml version="1.0" encoding="Windows-1252"?>
31-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
32+
<Project DefaultTargets="Build" ToolsVersion="$self->{ToolsVersion}" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3233
<ItemGroup Label="ProjectConfigurations">
3334
EOF
3435
$self->WriteConfigurationHeader($f, 'Debug');
@@ -414,6 +415,7 @@ sub new
414415
bless($self, $classname);
415416

416417
$self->{vcver} = '11.00';
418+
$self->{PlatformToolset} = 'v110';
417419

418420
return $self;
419421
}
@@ -434,9 +436,32 @@ sub WriteConfigurationPropertyGroup
434436
<UseOfMfc>false</UseOfMfc>
435437
<CharacterSet>MultiByte</CharacterSet>
436438
<WholeProgramOptimization>$p->{wholeopt}</WholeProgramOptimization>
437-
<PlatformToolset>v110</PlatformToolset>
439+
<PlatformToolset>$self->{PlatformToolset}</PlatformToolset>
438440
</PropertyGroup>
439441
EOF
440442
}
441443

444+
package VC2013Project;
445+
446+
#
447+
# Package that encapsulates a Visual C++ 2013 project file
448+
#
449+
450+
use strict;
451+
use warnings;
452+
use base qw(VC2012Project);
453+
454+
sub new
455+
{
456+
my $classname = shift;
457+
my $self = $classname->SUPER::_new(@_);
458+
bless($self, $classname);
459+
460+
$self->{vcver} = '12.00';
461+
$self->{PlatformToolset} = 'v120';
462+
$self->{ToolsVersion} = '12.0';
463+
464+
return $self;
465+
}
466+
442467
1;

src/tools/msvc/Mkvcbuild.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ sub mkvcbuild
7070
erand48.c snprintf.c strlcat.c strlcpy.c dirmod.c exec.c noblock.c path.c
7171
pgcheckdir.c pg_crc.c pgmkdirp.c pgsleep.c pgstrcasecmp.c pqsignal.c
7272
qsort.c qsort_arg.c quotes.c
73-
sprompt.c tar.c thread.c wait_error.c getopt.c getopt_long.c dirent.c rint.c win32env.c
74-
win32error.c win32setlocale.c);
73+
sprompt.c tar.c thread.c wait_error.c getopt.c getopt_long.c dirent.c
74+
win32env.c win32error.c win32setlocale.c);
75+
76+
push(@pgportfiles, 'rint.c') if ($vsVersion < '12.00');
7577

7678
our @pgcommonallfiles = qw(
7779
relpath.c);

src/tools/msvc/Solution.pm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ sub _new
1919
options => $options,
2020
numver => '',
2121
strver => '',
22+
VisualStudioVersion => undef,
23+
MinimumVisualStudioVersion => undef,
2224
vcver => undef,
2325
platform => undef, };
2426
bless($self, $classname);
@@ -59,6 +61,11 @@ sub _new
5961
return $self;
6062
}
6163

64+
sub GetAdditionalHeaders
65+
{
66+
return '';
67+
}
68+
6269
sub DeterminePlatform
6370
{
6471
my $self = shift;
@@ -545,6 +552,8 @@ Microsoft Visual Studio Solution File, Format Version $self->{solutionFileVersio
545552
# $self->{visualStudioName}
546553
EOF
547554

555+
print SLN $self->GetAdditionalHeaders();
556+
548557
foreach my $fld (keys %{ $self->{projects} })
549558
{
550559
foreach my $proj (@{ $self->{projects}->{$fld} })
@@ -727,4 +736,39 @@ sub new
727736
return $self;
728737
}
729738

739+
package VS2013Solution;
740+
741+
#
742+
# Package that encapsulates a Visual Studio 2013 solution file
743+
#
744+
745+
use Carp;
746+
use strict;
747+
use warnings;
748+
use base qw(Solution);
749+
750+
sub new
751+
{
752+
my $classname = shift;
753+
my $self = $classname->SUPER::_new(@_);
754+
bless($self, $classname);
755+
756+
$self->{solutionFileVersion} = '12.00';
757+
$self->{vcver} = '12.00';
758+
$self->{visualStudioName} = 'Visual Studio 2013';
759+
$self->{VisualStudioVersion} = '12.0.21005.1',
760+
$self->{MinimumVisualStudioVersion} = '10.0.40219.1',
761+
762+
return $self;
763+
}
764+
765+
sub GetAdditionalHeaders
766+
{
767+
my ($self, $f) = @_;
768+
769+
return qq|VisualStudioVersion = $self->{VisualStudioVersion}
770+
MinimumVisualStudioVersion = $self->{MinimumVisualStudioVersion}
771+
|;
772+
}
773+
730774
1;

src/tools/msvc/VSObjectFactory.pm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ sub CreateSolution
4545
{
4646
return new VS2012Solution(@_);
4747
}
48+
elsif ($visualStudioVersion eq '12.00')
49+
{
50+
return new VS2013Solution(@_);
51+
}
4852
else
4953
{
5054
croak "The requested Visual Studio version is not supported.";
@@ -76,6 +80,10 @@ sub CreateProject
7680
{
7781
return new VC2012Project(@_);
7882
}
83+
elsif ($visualStudioVersion eq '12.00')
84+
{
85+
return new VC2013Project(@_);
86+
}
7987
else
8088
{
8189
croak "The requested Visual Studio version is not supported.";
@@ -115,11 +123,11 @@ sub DetermineVisualStudioVersion
115123
sub _GetVisualStudioVersion
116124
{
117125
my ($major, $minor) = @_;
118-
if ($major > 11)
126+
if ($major > 12)
119127
{
120128
carp
121129
"The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
122-
return '11.00';
130+
return '12.00';
123131
}
124132
elsif ($major < 6)
125133
{

0 commit comments

Comments
 (0)