diff --git a/src/tools/msvc/Project.pm b/src/tools/msvc/Project.pm index 4ce0941..c152fd3 100644 --- a/src/tools/msvc/Project.pm +++ b/src/tools/msvc/Project.pm @@ -122,20 +122,25 @@ sub AddReference } } +# The parameter $slib is for sufixed run-time library. +# When available it will be added, if not it silently defaults to $lib. sub AddLibrary { - my ($self, $lib, $dbgsuffix) = @_; + my ($self, $lib, $slib) = @_; + my $libcfg = "MD"; + my $xlib = defined $slib ? $slib : ''; - if ($lib =~ m/\s/) + $xlib =~ s/\.lib$/$libcfg.lib/; + if ($xlib eq '' || ! -e $xlib) { - $lib = '"' . $lib . """; + push @{ $self->{libraries} }, $lib; } - - push @{ $self->{libraries} }, $lib; - if ($dbgsuffix) + else { - push @{ $self->{suffixlib} }, $lib; + push @{ $self->{libraries} }, $slib; + push @{ $self->{suffixlib} }, $slib; } + return; } sub AddIncludeDir diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 7e79920..fb7f3f5 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -177,7 +177,20 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY if ($self->{options}->{integer_datetimes}); print O "#define USE_LDAP 1\n" if ($self->{options}->{ldap}); print O "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib}); - print O "#define USE_OPENSSL 1\n" if ($self->{options}->{openssl}); + if ($self->{options}->{openssl}) + { + print O "#define USE_OPENSSL 1\n"; + # We need to know if we are using version 1.1.0 or above + my ($major, $minor, $fix) = $self->GetOpenSSLVersion(); + if ($major == 1 && $minor > 0) + { + print O "#define HAVE_BIO_GET_DATA 1\n"; + print O "#define HAVE_BIO_METH_NEW 1\n"; + print O "#define HAVE_OPENSSL_INIT_SSL 1\n"; + print O "#define HAVE_ASN1_STRING_GET0_DATA 1\n"; + print O "#define HAVE_RAND_OPENSSL 1\n"; + } + } print O "#define ENABLE_NLS 1\n" if ($self->{options}->{nls}); print O "#define BLCKSZ ", 1024 * $self->{options}->{blocksize}, "\n"; @@ -498,21 +511,39 @@ sub AddProject if ($self->{options}->{openssl}) { $proj->AddIncludeDir($self->{options}->{openssl} . '\include'); - if (-e "$self->{options}->{openssl}/lib/VC/ssleay32MD.lib") + my ($major, $minor, $fix) = $self->GetOpenSSLVersion(); + if ($major == 1 && $minor > 0) { - $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\VC\ssleay32.lib', 1); - $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\VC\libeay32.lib', 1); + # Starting at version 1.1.0 OpenSSL have changed their library names from: + # libeay to libcrypto + # ssleay to libssl + if ($self->{platform} eq 'Win32') + { + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\libssl.lib', + $self->{options}->{openssl} . '\lib\VC\libssl32.lib'); + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\libcrypto.lib', + $self->{options}->{openssl} . '\lib\VC\libcrypto32.lib'); + } + else + { + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\libssl.lib', + $self->{options}->{openssl} . '\lib\VC\libssl64.lib'); + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\libcrypto.lib', + $self->{options}->{openssl} . '\lib\VC\libcrypto64.lib'); + } } else { - # We don't expect the config-specific library to be here, - # so don't ask for it in last parameter $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\ssleay32.lib', 0); + $self->{options}->{openssl} . '\lib\ssleay32.lib', + $self->{options}->{openssl} . '\lib\VC\ssleay32.lib'); $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\libeay32.lib', 0); + $self->{options}->{openssl} . '\lib\libeay32.lib', + $self->{options}->{openssl} . '\lib\VC\libeay32.lib'); } } if ($self->{options}->{nls}) @@ -839,4 +870,25 @@ MinimumVisualStudioVersion = $self->{MinimumVisualStudioVersion} |; } +sub GetOpenSSLVersion +{ + my $self = shift; + + # Attempt to get OpenSSL version and location. + # Assume openssl.exe in specified dir. + my $opensslprog = '\bin\openssl.exe version 2>&1'; + my $opensslcmd = '"' . $self->{options}->{openssl} . '"' . $opensslprog; + my $sslout = `$opensslcmd`; + die "Unable to determine OpenSSL: The openssl.exe command was not found." if $?; + + if ($sslout =~ /(\d+)\.(\d+)\.(\d+)(\D)/m) + { + return ($1, $2, $3) + } + else + { + die "Unable to determine OpenSSL version: The openssl.exe version could not be determined."; + } +} + 1;