Skip to content

Commit b49a97b

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) (cherry picked from commit 49fa773) (cherry picked from commit 07b7b5a)
1 parent 2f2fd26 commit b49a97b

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
@@ -998,7 +998,8 @@ threads = dependency('threads')
998998
librt = cc.find_library('rt')
999999
libm = cc.find_library('m')
10001000
libdl = cc.find_library('dl')
1001-
libcrypt = cc.find_library('crypt')
1001+
libcrypt = dependency('libcrypt')
1002+
libcap = dependency('libcap')
10021003

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

1025-
libcap = dependency('libcap', required : false)
1026-
if not libcap.found()
1027-
# Compat with Ubuntu 14.04 which ships libcap w/o .pc file
1028-
libcap = cc.find_library('cap')
1029-
endif
1030-
10311026
want_bpf_framework = get_option('bpf-framework')
10321027
bpf_framework_required = want_bpf_framework == 'true'
10331028

@@ -1178,7 +1173,7 @@ conf.set10('ENABLE_POLKIT', install_polkit)
11781173

11791174
want_acl = get_option('acl')
11801175
if want_acl != 'false' and not skip_deps
1181-
libacl = cc.find_library('acl', required : want_acl == 'true')
1176+
libacl = dependency('libacl', required : want_acl == 'true')
11821177
have = libacl.found()
11831178
else
11841179
have = false
@@ -1223,8 +1218,15 @@ conf.set10('HAVE_KMOD', have)
12231218

12241219
want_pam = get_option('pam')
12251220
if want_pam != 'false' and not skip_deps
1226-
libpam = cc.find_library('pam', required : want_pam == 'true')
1227-
libpam_misc = cc.find_library('pam_misc', required : want_pam == 'true')
1221+
libpam = dependency('pam', required : false)
1222+
if not libpam.found()
1223+
# Debian older than bookworm and Ubuntu older than 22.10 do not provide the .pc file.
1224+
libpam = cc.find_library('pam', required : want_pam == 'true')
1225+
endif
1226+
libpam_misc = dependency('pam_misc', required : false)
1227+
if not libpam_misc.found()
1228+
libpam_misc = cc.find_library('pam_misc', required : want_pam == 'true')
1229+
endif
12281230
have = libpam.found() and libpam_misc.found()
12291231
else
12301232
have = false
@@ -1350,8 +1352,12 @@ conf.set10('HAVE_QRENCODE', have)
13501352

13511353
want_gcrypt = get_option('gcrypt')
13521354
if want_gcrypt != 'false' and not skip_deps
1353-
libgcrypt = cc.find_library('gcrypt', required : want_gcrypt == 'true')
1354-
libgpg_error = cc.find_library('gpg-error', required : want_gcrypt == 'true')
1355+
libgcrypt = dependency('libgcrypt', required : want_gcrypt == 'true')
1356+
libgpg_error = dependency('gpg-error', required : false)
1357+
if not libgpg_error.found()
1358+
# CentOS 8 does not provide the .pc file.
1359+
libgpg_error = cc.find_library('gpg-error', required : want_gcrypt == 'true')
1360+
endif
13551361
have = libgcrypt.found() and libgpg_error.found()
13561362
else
13571363
have = false
@@ -1449,8 +1455,11 @@ conf.set10('HAVE_ZLIB', have)
14491455

14501456
want_bzip2 = get_option('bzip2')
14511457
if want_bzip2 != 'false' and not skip_deps
1452-
libbzip2 = cc.find_library('bz2',
1453-
required : want_bzip2 == 'true')
1458+
libbzip2 = dependency('bzip2', required : false)
1459+
if not libbzip2.found()
1460+
# Debian and Ubuntu do not provide the .pc file.
1461+
libbzip2 = cc.find_library('bz2', required : want_bzip2 == 'true')
1462+
endif
14541463
have = libbzip2.found()
14551464
else
14561465
have = false

0 commit comments

Comments
 (0)