Skip to content

Commit f9dead5

Browse files
committed
Install shared libraries to bin/ in Windows under MSVC
Since commit cb4a3b0 we were already doing this for the Cygwin/mingw toolchains, but MSVC had not been updated to do it. At Install.pm time, the Makefile (or GNUmakefile) is inspected, and if a line matching SO_MAJOR_VERSION is found (indicating a shared library is being built), then files with the .dll extension are set to be installed in bin/ rather than lib/, while files with .lib extension are installed in lib/. This makes the MSVC toolchain up to date with cygwin/mingw. This removes ad-hoc hacks that were copying files into bin/ or lib/ manually (libpq.dll in particular was already being copied into bin). So while this is a rather ugly kludge, it's still cleaner than what was there before. Author: Michael Paquier Reviewed by: Asif Naeem
1 parent b8d226b commit f9dead5

File tree

1 file changed

+57
-24
lines changed

1 file changed

+57
-24
lines changed

src/tools/msvc/Install.pm

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ sub Install
9191
}
9292

9393
CopySolutionOutput($conf, $target);
94-
lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
9594
my $sample_files = [];
9695
my @top_dir = ("src");
9796
@top_dir = ("src\\bin", "src\\interfaces") if ($insttype eq "client");
@@ -106,14 +105,8 @@ sub Install
106105
CopyFiles(
107106
'Import libraries',
108107
$target . '/lib/',
109-
"$conf\\",
110-
"postgres\\postgres.lib",
111-
"libpq\\libpq.lib",
112-
"libecpg\\libecpg.lib",
113-
"libpgcommon\\libpgcommon.lib",
114-
"libpgport\\libpgport.lib",
115-
"libpgtypes\\libpgtypes.lib",
116-
"libecpg_compat\\libecpg_compat.lib");
108+
"$conf\\", "postgres\\postgres.lib", "libpgcommon\\libpgcommon.lib",
109+
"libpgport\\libpgport.lib");
117110
CopyContribFiles($config, $target);
118111
CopyIncludeFiles($target);
119112

@@ -236,8 +229,14 @@ sub CopySolutionOutput
236229
while ($sln =~ $rem)
237230
{
238231
my $pf = $1;
239-
my $dir;
240-
my $ext;
232+
233+
# Hash-of-arrays listing where to install things. For each
234+
# subdirectory there's a hash key, and the value is an array
235+
# of file extensions to install in that subdirectory. Example:
236+
# { 'bin' => [ 'dll', 'lib' ],
237+
# 'lib' => [ 'lib' ] }
238+
my %install_list;
239+
my $is_sharedlib = 0;
241240

242241
$sln =~ s/$rem//;
243242

@@ -247,22 +246,45 @@ sub CopySolutionOutput
247246

248247
my $proj = read_file("$pf.$vcproj")
249248
|| croak "Could not open $pf.$vcproj\n";
249+
250+
# Check if this project uses a shared library by looking if
251+
# SO_MAJOR_VERSION is defined in its Makefile, whose path
252+
# can be found using the resource file of this project.
253+
if (( $vcproj eq 'vcxproj'
254+
&& $proj =~ qr{ResourceCompile\s*Include="([^"]+)"})
255+
|| ( $vcproj eq 'vcproj'
256+
&& $proj =~ qr{File\s*RelativePath="([^\"]+)\.rc"}))
257+
{
258+
my $projpath = dirname($1);
259+
my $mfname =
260+
-e "$projpath/GNUmakefile"
261+
? "$projpath/GNUmakefile"
262+
: "$projpath/Makefile";
263+
my $mf = read_file($mfname) || croak "Could not open $mfname\n";
264+
265+
$is_sharedlib = 1 if ($mf =~ /^SO_MAJOR_VERSION\s*=\s*(.*)$/mg);
266+
}
267+
250268
if ($vcproj eq 'vcproj' && $proj =~ qr{ConfigurationType="([^"]+)"})
251269
{
252270
if ($1 == 1)
253271
{
254-
$dir = "bin";
255-
$ext = "exe";
272+
push(@{ $install_list{'bin'} }, "exe");
256273
}
257274
elsif ($1 == 2)
258275
{
259-
$dir = "lib";
260-
$ext = "dll";
276+
push(@{ $install_list{'lib'} }, "dll");
277+
if ($is_sharedlib)
278+
{
279+
push(@{ $install_list{'bin'} }, "dll");
280+
push(@{ $install_list{'lib'} }, "lib");
281+
}
261282
}
262283
else
263284
{
264285

265-
# Static lib, such as libpgport, only used internally during build, don't install
286+
# Static libraries, such as libpgport, only used internally
287+
# during build, don't install.
266288
next;
267289
}
268290
}
@@ -271,27 +293,38 @@ sub CopySolutionOutput
271293
{
272294
if ($1 eq 'Application')
273295
{
274-
$dir = "bin";
275-
$ext = "exe";
296+
push(@{ $install_list{'bin'} }, "exe");
276297
}
277298
elsif ($1 eq 'DynamicLibrary')
278299
{
279-
$dir = "lib";
280-
$ext = "dll";
300+
push(@{ $install_list{'lib'} }, "dll");
301+
if ($is_sharedlib)
302+
{
303+
push(@{ $install_list{'bin'} }, "dll");
304+
push(@{ $install_list{'lib'} }, "lib");
305+
}
281306
}
282307
else # 'StaticLibrary'
283308
{
284-
285-
# Static lib, such as libpgport, only used internally during build, don't install
309+
# Static lib, such as libpgport, only used internally
310+
# during build, don't install.
286311
next;
287312
}
288313
}
289314
else
290315
{
291316
croak "Could not parse $pf.$vcproj\n";
292317
}
293-
lcopy("$conf\\$pf\\$pf.$ext", "$target\\$dir\\$pf.$ext")
294-
|| croak "Could not copy $pf.$ext\n";
318+
319+
# Install each element
320+
foreach my $dir (keys %install_list)
321+
{
322+
foreach my $ext (@{ $install_list{$dir} })
323+
{
324+
lcopy("$conf\\$pf\\$pf.$ext", "$target\\$dir\\$pf.$ext")
325+
|| croak "Could not copy $pf.$ext\n";
326+
}
327+
}
295328
lcopy("$conf\\$pf\\$pf.pdb", "$target\\symbols\\$pf.pdb")
296329
|| croak "Could not copy $pf.pdb\n";
297330
print ".";

0 commit comments

Comments
 (0)