From 5df704664843fb6d30bca632bdc009950799acc6 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig.ringer@enterprisedb.com>
Date: Tue, 13 Jul 2021 14:48:42 +1000
Subject: [PATCH v1 2/2] Support extra preprocessor definitions in config.pl

Add a new 'defines' option in config.pl. This accepts an array of NAME
or NAME=VALUE preprocessor definitions to apply to all projects being
compiled, like somewhat like CPPFLAGS on *nix.

Unlike CPPFLAGS, you cannot pass arbitrary preprocessor, compiler or
linker flags using this method, only actual preprocessor definitions.
---
 src/tools/msvc/Solution.pm       | 9 +++++++++
 src/tools/msvc/config_default.pl | 9 ++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a13ca6e02e..15701ab03b 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -1045,6 +1045,15 @@ sub AddProject
 		$proj->AddIncludeDir($self->{options}->{uuid} . '\include');
 		$proj->AddLibrary($self->{options}->{uuid} . '\lib\uuid.lib');
 	}
+	if ($self->{options}->{defines}) {
+		if (ref $self->{options}->{defines} eq "ARRAY") {
+			foreach my $definition (@{$self->{options}->{defines}}) {
+				$proj->AddDefine($definition);
+			}
+		} else {
+			die "Key 'defines' in config.pl must have an array value like [\"def1\", \"def2=val\"]."
+		}
+	}
 	return $proj;
 }
 
diff --git a/src/tools/msvc/config_default.pl b/src/tools/msvc/config_default.pl
index 2ef2cfc4e9..1479ea5a9b 100644
--- a/src/tools/msvc/config_default.pl
+++ b/src/tools/msvc/config_default.pl
@@ -1,4 +1,7 @@
 # Configuration arguments for vcbuild.
+#
+# Overridden by any values set in config.pl if it exists.
+#
 use strict;
 use warnings;
 
@@ -21,7 +24,11 @@ our $config = {
 	xml       => undef,    # --with-libxml=<path>
 	xslt      => undef,    # --with-libxslt=<path>
 	iconv     => undef,    # (not in configure, path to iconv)
-	zlib      => undef     # --with-zlib=<path>
+	zlib      => undef,     # --with-zlib=<path>
+	# extra preprocessor definitions in "DEFNAME" or "DEFNAME=VALUE" form.
+	# Does not accept arbitrary compiler flags. e.g.
+	#     ["WINVER=0x0601", "_WIN32_WINNT=0x0601"]
+	defines	  => []
 };
 
 1;
-- 
2.31.1

