Skip to content

Commit

Permalink
meson: first try dependency(), then fallback to find_library()
Browse files Browse the repository at this point in the history
This also drops the fallback for libacl, libcap, libcrypt, and libgcrypt,
as recent Ubuntu (at least, 20.04 LTS and newer) and Debian (at least, buster
and newer) have relevant .pc files.

Fixes #28161.

(cherry picked from commit d625f71)
  • Loading branch information
yuwata authored and bluca committed Jul 7, 2023
1 parent abbd24e commit 49fa773
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,8 @@ threads = dependency('threads')
librt = cc.find_library('rt')
libm = cc.find_library('m')
libdl = cc.find_library('dl')
libcrypt = cc.find_library('crypt')
libcrypt = dependency('libcrypt')
libcap = dependency('libcap')

# On some architectures, libatomic is required. But on some installations,
# it is found, but actual linking fails. So let's try to use it opportunistically.
Expand All @@ -1060,12 +1061,6 @@ foreach ident : [
conf.set10('HAVE_' + ident[0].to_upper(), have)
endforeach

libcap = dependency('libcap', required : false)
if not libcap.found()
# Compat with Ubuntu 14.04 which ships libcap w/o .pc file
libcap = cc.find_library('cap')
endif

want_bpf_framework = get_option('bpf-framework')
bpf_compiler = get_option('bpf-compiler')
bpf_framework_required = want_bpf_framework == 'true'
Expand Down Expand Up @@ -1244,7 +1239,7 @@ conf.set10('ENABLE_POLKIT', install_polkit)

want_acl = get_option('acl')
if want_acl != 'false' and not skip_deps
libacl = cc.find_library('acl', required : want_acl == 'true')
libacl = dependency('libacl', required : want_acl == 'true')
have = libacl.found()
else
have = false
Expand Down Expand Up @@ -1301,8 +1296,15 @@ conf.set10('HAVE_XENCTRL', have)

want_pam = get_option('pam')
if want_pam != 'false' and not skip_deps
libpam = cc.find_library('pam', required : want_pam == 'true')
libpam_misc = cc.find_library('pam_misc', required : want_pam == 'true')
libpam = dependency('pam', required : false)
if not libpam.found()
# Debian older than bookworm and Ubuntu older than 22.10 do not provide the .pc file.
libpam = cc.find_library('pam', required : want_pam == 'true')
endif
libpam_misc = dependency('pam_misc', required : false)
if not libpam_misc.found()
libpam_misc = cc.find_library('pam_misc', required : want_pam == 'true')
endif
have = libpam.found() and libpam_misc.found()
else
have = false
Expand Down Expand Up @@ -1431,8 +1433,12 @@ conf.set10('HAVE_QRENCODE', have)

want_gcrypt = get_option('gcrypt')
if want_gcrypt != 'false' and not skip_deps
libgcrypt = cc.find_library('gcrypt', required : want_gcrypt == 'true')
libgpg_error = cc.find_library('gpg-error', required : want_gcrypt == 'true')
libgcrypt = dependency('libgcrypt', required : want_gcrypt == 'true')
libgpg_error = dependency('gpg-error', required : false)
if not libgpg_error.found()
# CentOS 8 does not provide the .pc file.
libgpg_error = cc.find_library('gpg-error', required : want_gcrypt == 'true')
endif
have = libgcrypt.found() and libgpg_error.found()
else
have = false
Expand Down Expand Up @@ -1542,8 +1548,11 @@ conf.set10('HAVE_ZLIB', have)

want_bzip2 = get_option('bzip2')
if want_bzip2 != 'false' and not skip_deps
libbzip2 = cc.find_library('bz2',
required : want_bzip2 == 'true')
libbzip2 = dependency('bzip2', required : false)
if not libbzip2.found()
# Debian and Ubuntu do not provide the .pc file.
libbzip2 = cc.find_library('bz2', required : want_bzip2 == 'true')
endif
have = libbzip2.found()
else
have = false
Expand Down

0 comments on commit 49fa773

Please sign in to comment.