Skip to content

Commit 49fa773

Browse files
yuwatabluca
authored andcommitted
meson: first try dependency(), then fallback to find_library()
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)
1 parent abbd24e commit 49fa773

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

meson.build

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,8 @@ threads = dependency('threads')
10361036
librt = cc.find_library('rt')
10371037
libm = cc.find_library('m')
10381038
libdl = cc.find_library('dl')
1039-
libcrypt = cc.find_library('crypt')
1039+
libcrypt = dependency('libcrypt')
1040+
libcap = dependency('libcap')
10401041

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

1063-
libcap = dependency('libcap', required : false)
1064-
if not libcap.found()
1065-
# Compat with Ubuntu 14.04 which ships libcap w/o .pc file
1066-
libcap = cc.find_library('cap')
1067-
endif
1068-
10691064
want_bpf_framework = get_option('bpf-framework')
10701065
bpf_compiler = get_option('bpf-compiler')
10711066
bpf_framework_required = want_bpf_framework == 'true'
@@ -1244,7 +1239,7 @@ conf.set10('ENABLE_POLKIT', install_polkit)
12441239

12451240
want_acl = get_option('acl')
12461241
if want_acl != 'false' and not skip_deps
1247-
libacl = cc.find_library('acl', required : want_acl == 'true')
1242+
libacl = dependency('libacl', required : want_acl == 'true')
12481243
have = libacl.found()
12491244
else
12501245
have = false
@@ -1301,8 +1296,15 @@ conf.set10('HAVE_XENCTRL', have)
13011296

13021297
want_pam = get_option('pam')
13031298
if want_pam != 'false' and not skip_deps
1304-
libpam = cc.find_library('pam', required : want_pam == 'true')
1305-
libpam_misc = cc.find_library('pam_misc', required : want_pam == 'true')
1299+
libpam = dependency('pam', required : false)
1300+
if not libpam.found()
1301+
# Debian older than bookworm and Ubuntu older than 22.10 do not provide the .pc file.
1302+
libpam = cc.find_library('pam', required : want_pam == 'true')
1303+
endif
1304+
libpam_misc = dependency('pam_misc', required : false)
1305+
if not libpam_misc.found()
1306+
libpam_misc = cc.find_library('pam_misc', required : want_pam == 'true')
1307+
endif
13061308
have = libpam.found() and libpam_misc.found()
13071309
else
13081310
have = false
@@ -1431,8 +1433,12 @@ conf.set10('HAVE_QRENCODE', have)
14311433

14321434
want_gcrypt = get_option('gcrypt')
14331435
if want_gcrypt != 'false' and not skip_deps
1434-
libgcrypt = cc.find_library('gcrypt', required : want_gcrypt == 'true')
1435-
libgpg_error = cc.find_library('gpg-error', required : want_gcrypt == 'true')
1436+
libgcrypt = dependency('libgcrypt', required : want_gcrypt == 'true')
1437+
libgpg_error = dependency('gpg-error', required : false)
1438+
if not libgpg_error.found()
1439+
# CentOS 8 does not provide the .pc file.
1440+
libgpg_error = cc.find_library('gpg-error', required : want_gcrypt == 'true')
1441+
endif
14361442
have = libgcrypt.found() and libgpg_error.found()
14371443
else
14381444
have = false
@@ -1542,8 +1548,11 @@ conf.set10('HAVE_ZLIB', have)
15421548

15431549
want_bzip2 = get_option('bzip2')
15441550
if want_bzip2 != 'false' and not skip_deps
1545-
libbzip2 = cc.find_library('bz2',
1546-
required : want_bzip2 == 'true')
1551+
libbzip2 = dependency('bzip2', required : false)
1552+
if not libbzip2.found()
1553+
# Debian and Ubuntu do not provide the .pc file.
1554+
libbzip2 = cc.find_library('bz2', required : want_bzip2 == 'true')
1555+
endif
15471556
have = libbzip2.found()
15481557
else
15491558
have = false

0 commit comments

Comments
 (0)