Skip to content

Commit 7ed2ce0

Browse files
committed
meson: Add support for detecting gss without pkg-config
This is required as MIT Kerberos does provide neither pkg-config nor cmake dependency information on windows. Reported-by: Dave Page <dpage@pgadmin.org> Reviewed-by: Tristan Partin <tristan@partin.io> Discussion: https://postgr.es/m/20240709065101.xhc74r3mdg2lmn4w@awork3.anarazel.de Backpatch: 16-, where meson support was added
1 parent c3dafaa commit 7ed2ce0

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

meson.build

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,33 +614,66 @@ gssapiopt = get_option('gssapi')
614614
krb_srvtab = ''
615615
have_gssapi = false
616616
if not gssapiopt.disabled()
617-
gssapi = dependency('krb5-gssapi', required: gssapiopt)
617+
gssapi = dependency('krb5-gssapi', required: false)
618618
have_gssapi = gssapi.found()
619619

620+
if have_gssapi
621+
gssapi_deps = [gssapi]
622+
elif not have_gssapi
623+
# Hardcoded lookup for gssapi. This is necessary as gssapi on windows does
624+
# not install neither pkg-config nor cmake dependency information.
625+
if host_system == 'windows'
626+
is_64 = cc.sizeof('void *', args: test_c_args) == 8
627+
if is_64
628+
gssapi_search_libs = ['gssapi64', 'krb5_64', 'comerr64']
629+
else
630+
gssapi_search_libs = ['gssapi32', 'krb5_32', 'comerr32']
631+
endif
632+
else
633+
gssapi_search_libs = ['gssapi_krb5']
634+
endif
635+
636+
gssapi_deps = []
637+
foreach libname : gssapi_search_libs
638+
lib = cc.find_library(libname, dirs: test_lib_d, required: false)
639+
if lib.found()
640+
have_gssapi = true
641+
gssapi_deps += lib
642+
endif
643+
endforeach
644+
645+
if have_gssapi
646+
# Meson before 0.57.0 did not support using check_header() etc with
647+
# declare_dependency(). Thus the tests below use the library looked up
648+
# above. Once we require a newer meson version, we can simplify.
649+
gssapi = declare_dependency(dependencies: gssapi_deps)
650+
endif
651+
endif
652+
620653
if not have_gssapi
621-
elif cc.check_header('gssapi/gssapi.h', dependencies: gssapi, required: false,
654+
elif cc.check_header('gssapi/gssapi.h', dependencies: gssapi_deps, required: false,
622655
args: test_c_args, include_directories: postgres_inc)
623656
cdata.set('HAVE_GSSAPI_GSSAPI_H', 1)
624-
elif cc.check_header('gssapi.h', dependencies: gssapi, required: gssapiopt,
657+
elif cc.check_header('gssapi.h', dependencies: gssapi_deps, required: gssapiopt,
625658
args: test_c_args, include_directories: postgres_inc)
626659
cdata.set('HAVE_GSSAPI_H', 1)
627660
else
628661
have_gssapi = false
629662
endif
630663

631664
if not have_gssapi
632-
elif cc.check_header('gssapi/gssapi_ext.h', dependencies: gssapi, required: false,
665+
elif cc.check_header('gssapi/gssapi_ext.h', dependencies: gssapi_deps, required: false,
633666
args: test_c_args, include_directories: postgres_inc)
634667
cdata.set('HAVE_GSSAPI_GSSAPI_EXT_H', 1)
635-
elif cc.check_header('gssapi_ext.h', dependencies: gssapi, required: gssapiopt,
668+
elif cc.check_header('gssapi_ext.h', dependencies: gssapi_deps, required: gssapiopt,
636669
args: test_c_args, include_directories: postgres_inc)
637670
cdata.set('HAVE_GSSAPI_EXT_H', 1)
638671
else
639672
have_gssapi = false
640673
endif
641674

642675
if not have_gssapi
643-
elif cc.has_function('gss_store_cred_into', dependencies: gssapi,
676+
elif cc.has_function('gss_store_cred_into', dependencies: gssapi_deps,
644677
args: test_c_args, include_directories: postgres_inc)
645678
cdata.set('ENABLE_GSS', 1)
646679

@@ -651,6 +684,11 @@ if not gssapiopt.disabled()
651684
else
652685
have_gssapi = false
653686
endif
687+
688+
if not have_gssapi and gssapiopt.enabled()
689+
error('dependency lookup for gssapi failed')
690+
endif
691+
654692
endif
655693
if not have_gssapi
656694
gssapi = not_found_dep

0 commit comments

Comments
 (0)