build: use cc.links() to check for static libcap

Fixes: #4144
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2022-06-13 11:04:17 +02:00 committed by Christian Brauner (Microsoft)
parent f5420c9d3f
commit de4543d8f8
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -382,7 +382,16 @@ if want_capabilities
# Compat with Ubuntu 14.04 which ships libcap w/o .pc file
libcap_static = cc.find_library('cap', required: false, static: true)
endif
srcconf.set10('HAVE_STATIC_LIBCAP', libcap_static.found())
code = '''
int main(int argc, char *argv[]) { return 0; };
'''
if libcap_static.found()
libcap_static_linkable = cc.links(code, args: '-static', dependencies: libcap_static)
srcconf.set10('HAVE_STATIC_LIBCAP', libcap_static_linkable)
else
srcconf.set10('HAVE_STATIC_LIBCAP', false)
endif
else
srcconf.set10('HAVE_LIBCAP', false)
srcconf.set10('HAVE_STATIC_LIBCAP', false)