From: Lucas De Marchi Date: Wed, 4 Dec 2024 07:16:09 +0000 (-0600) Subject: meson: Simplify compression handling X-Git-Tag: v34~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be6302145c0f8c868eddd3d919a16a6d1e4b2518;p=thirdparty%2Fkmod.git meson: Simplify compression handling Move libs to a table, similarly to how other things are handled, so this logic can be more easily expanded in future for all compression types. Signed-off-by: Lucas De Marchi Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/262 --- diff --git a/meson.build b/meson.build index a5e84797..7a70996f 100644 --- a/meson.build +++ b/meson.build @@ -174,6 +174,7 @@ module_compressions = '' module_signatures = '' features = [] +dep_map = {} #------------------------------------------------------------------------------- # Directories @@ -287,26 +288,29 @@ endif # Compression support #------------------------------------------------------------------------------- -zstd = dependency('libzstd', version : '>= 1.4.4', required : get_option('zstd')) -if zstd.found() - module_compressions += 'zstd ' -endif -cdata.set10('ENABLE_ZSTD', zstd.found()) -features += ['@0@ZSTD'.format(zstd.found() ? '+' : '-')] +_compression = [ + ['zstd', 'libzstd', '>= 1.4.4'], + ['xz', 'liblzma', '>= 4.99'], + ['zlib', 'zlib', '>= 0'], +] -xz = dependency('liblzma', version : '>= 4.99', required : get_option('xz')) -if xz.found() - module_compressions += 'xz ' -endif -cdata.set10('ENABLE_XZ', xz.found()) -features += ['@0@XZ'.format(xz.found() ? '+' : '-')] +foreach tuple : _compression + opt = tuple[0] + pkg_dep = tuple[1] + pkg_dep_version = tuple[2] -zlib = dependency('zlib', required : get_option('zlib')) -if zlib.found() - module_compressions += 'zlib ' -endif -cdata.set10('ENABLE_ZLIB', zlib.found()) -features += ['@0@ZLIB'.format(zlib.found() ? '+' : '-')] + dep = dependency(pkg_dep, version : pkg_dep_version, required : get_option(opt)) + have = dep.found() + + cdata.set10('ENABLE_' + opt.to_upper(), have) + + if have + module_compressions += '@0@ '.format(opt) + endif + + features += ['@0@@1@'.format(have ? '+' : '-', opt.to_upper())] + dep_map += {opt : dep} +endforeach #------------------------------------------------------------------------------- # Signed modules @@ -370,19 +374,19 @@ libkmod_files = files( libkmod_deps = [] -if zstd.found() +if dep_map.get('zstd').found() libkmod_files += files('libkmod/libkmod-file-zstd.c') - libkmod_deps += zstd + libkmod_deps += dep_map['zstd'] endif -if xz.found() +if dep_map.get('xz').found() libkmod_files += files('libkmod/libkmod-file-xz.c') - libkmod_deps += xz + libkmod_deps += dep_map['xz'] endif -if zlib.found() +if dep_map.get('zlib').found() libkmod_files += files('libkmod/libkmod-file-zlib.c') - libkmod_deps += zlib + libkmod_deps += dep_map['zlib'] endif if crypto.found()