@@ -614,33 +614,66 @@ gssapiopt = get_option('gssapi')
614614krb_srvtab= ''
615615have_gssapi= false
616616if 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+
620653if 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 ,
622655args : 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,
625658args : test_c_args,include_directories : postgres_inc)
626659 cdata.set(' HAVE_GSSAPI_H' ,1 )
627660else
628661 have_gssapi= false
629662endif
630663
631664if 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 ,
633666args : 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,
636669args : test_c_args,include_directories : postgres_inc)
637670 cdata.set(' HAVE_GSSAPI_EXT_H' ,1 )
638671else
639672 have_gssapi= false
640673endif
641674
642675if 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 ,
644677args : test_c_args,include_directories : postgres_inc)
645678 cdata.set(' ENABLE_GSS' ,1 )
646679
@@ -651,6 +684,11 @@ if not gssapiopt.disabled()
651684else
652685 have_gssapi= false
653686endif
687+
688+ if not have_gssapiand gssapiopt.enabled()
689+ error (' dependency lookup for gssapi failed' )
690+ endif
691+
654692endif
655693if not have_gssapi
656694 gssapi= not_found_dep