]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
meson: Simplify compression handling
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Wed, 4 Dec 2024 07:16:09 +0000 (01:16 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 6 Dec 2024 21:06:42 +0000 (13:06 -0800)
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 <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
meson.build

index a5e84797e0b56c9463af22d3550a9c1ff977d82e..7a70996f7c45539e2acfb07f67f7d3d9245cd3c0 100644 (file)
@@ -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()