Colleagues, I've encountered some problems trying to enable gss support in MSVC build of Postgres (I've experemented with REL_10_STABLE branch, but code in question seems to be same in all supported releases, including master).
As it is recommended in the documentation, I've downloaded MIT Kerberos from http://web.mit.edu/Kerberos/dist/index.html They distribute latest version (4.1) of Kerberos as .msi installer which installs into C:\Program Files. (32-bit version probably would install into C:\Program Files(x86), but I've not tried it yet). Here comes first problem. Project->AddLibrary unconditionally quotes paths with spaces. But some contrib modules which depends on PL language, use Mkvcbuild::AddTransformModule for generating dependences. It gets list of (already quoted) librariy name from dependency project and adds them to the current project. I haven't investigate whether adding kerberos, xml, icu etc libraries three times to linker command line does any good, but it works. And double quoting filename with quotes definitely breaks things. Fix is quite simple: diff --git a/src/tools/msvc/Project.pm b/src/tools/msvc/Project.pm index 9817b94..3749c17 100644 --- a/src/tools/msvc/Project.pm +++ b/src/tools/msvc/Project.pm @@ -126,7 +126,7 @@ sub AddLibrary { my ($self, $lib, $dbgsuffix) = @_; - if ($lib =~ m/\s/) + if ($lib =~ m/\s/ && !$lib =~m/^\".*\"$/) { $lib = '"' . $lib . """; } I suppose this would help with any 3-rd party library installed into directory with spaces in the names, not just Kerberos. Second problem is that names of 32-bit libraries and library directories are hard-coded into Solution.pm $self->{options}->{gss} . '\lib\i386\krb5_32.lib' And for 64-bit build '\lib\amd64\krb5_64.lib' is needed (at least for this MIT Kerberos 4.1) There is similar platform differences with other libraries, such as ICU, and check if ($self->{platform} eq 'Win32') is used for them. But there is no such thing for gss libraries. And third problem is that Solution.pm expect includes in $self->{options}->{gss}.'\inc\krb5' but for Kerberos 4.1 $self->{options}->{gss}.'\include" is needed. I haven't dig into computer archeology and havent checked when this change occured, just check if directore '\include' exist and use it if so. Attached patch fixes these problems. Regrards, Victor. --
diff --git a/src/tools/msvc/Project.pm b/src/tools/msvc/Project.pm index 9817b94..3749c17 100644 --- a/src/tools/msvc/Project.pm +++ b/src/tools/msvc/Project.pm @@ -126,7 +126,7 @@ sub AddLibrary { my ($self, $lib, $dbgsuffix) = @_; - if ($lib =~ m/\s/) + if ($lib =~ m/\s/ && !$lib =~/^\".*\"$/) { $lib = '"' . $lib . """; } diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index ad75478..2adaafd 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -591,10 +591,22 @@ sub AddProject } if ($self->{options}->{gss}) { - $proj->AddIncludeDir($self->{options}->{gss} . '\inc\krb5'); - $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\krb5_32.lib'); - $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\comerr32.lib'); - $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\gssapi32.lib'); + if ( -d $self->{options}->{gss}.'\include') { + $proj->AddIncludeDir($self->{options}->{gss} . '\include'); + } else { + $proj->AddIncludeDir($self->{options}->{gss} . '\inc\krb5'); + } + my ($gss_libdir,$suffix); + if ($self->{platform} eq 'Win32') { + $gss_libdir = $self->{options}->{gss}.'\lib\i386'; + $suffix='32'; + } else { + $gss_libdir = $self->{options}->{gss}.'\lib\amd64'; + $suffix='64'; + } + $proj->AddLibrary("$gss_libdir\\krb5_$suffix.lib"); + $proj->AddLibrary("$gss_libdir\\comerr$suffix.lib"); + $proj->AddLibrary("$gss_libdir\\gssapi$suffix.lib"); } if ($self->{options}->{iconv}) {