From a4aa6d79addfcc5f6b61a9aecd2b3a647e249622 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sat, 17 Oct 2020 09:50:40 -0400 Subject: [PATCH] meson: Use feature options for media and print backends This gracefully disable ffmpeg, gstreamer, cups and cloudprint optional dependencies when they are not available, while still giving full control to distributors using -Dauto_features=enabled. --- meson_options.txt | 26 +++++++--- modules/media/meson.build | 59 ++++++++++------------ modules/printbackends/meson.build | 81 ++++++++++--------------------- 3 files changed, 69 insertions(+), 97 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index ac50721ff8..24a61511d7 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -27,17 +27,27 @@ option('macos-backend', # Media backends -option('media', - type: 'string', - value: 'gstreamer', - description : 'Build the specified media engines (comma-separated list, "all", or "none")') +option('media-ffmpeg', + type: 'feature', + value: 'auto', + description : 'Build the ffmpeg media backend') + +option('media-gstreamer', + type: 'feature', + value: 'auto', + description : 'Build the gstreamer media backend') # Print backends -option('print', - type: 'string', - value: 'cups,file', - description : 'Build the specified print backends (comma-separated list, "all", or "none")') +option('print-cups', + type: 'feature', + value: 'auto', + description : 'Build the cups print backend') + +option('print-cloudprint', + type: 'feature', + value: 'auto', + description : 'Build the cloudprint print backend') # Optional features diff --git a/modules/media/meson.build b/modules/media/meson.build index 59124d3154..79df9c7769 100644 --- a/modules/media/meson.build +++ b/modules/media/meson.build @@ -1,27 +1,6 @@ -all_media_backends = [ - 'ffmpeg', - 'gstreamer' -] - -enabled_media_backends = get_option('media').split(',') - -if enabled_media_backends.contains('none') - media_backends = [] -elif enabled_media_backends.contains('all') - media_backends = all_media_backends -else - media_backends = [] - foreach b: enabled_media_backends - if all_media_backends.contains(b) - media_backends += b - else - error('No media backend named "@0@" exists.'.format (b)) - endif - endforeach -endif - media_subdir = 'gtk-4.0/@0@/media'.format(gtk_binary_version) media_install_dir = join_paths(get_option('libdir'), media_subdir) +media_backends = [] extra_c_args = [ '-DGTK_COMPILATION', @@ -30,15 +9,28 @@ extra_c_args = [ extra_c_args += common_cflags -if media_backends.contains('ffmpeg') - libavfilter_dep = dependency('libavfilter', version: '>= 6.47.100', required: true) - libavformat_dep = dependency('libavformat', version: '>= 57.41.100', required: true) - libavcodec_dep = dependency('libavcodec', version: '>= 57.48.101', required: true) - libavutil_dep = dependency('libavutil', version: '>= 55.28.100', required: true) - libswscale_dep = dependency('libswscale', version: '>= 4.6.100', required: true) - ffmpeg_deps = [libavfilter_dep, libavformat_dep, libavcodec_dep, libavutil_dep, libswscale_dep] - cdata.set('HAVE_FFMPEG', 1) +ffmpeg_opt = get_option('media-ffmpeg') +ffmpeg_versions = { + 'libavfilter': '>= 6.47.100', + 'libavformat': '>= 57.41.100', + 'libavcodec': '>= 57.48.101', + 'libavutil': '>= 55.28.100', + 'libswscale': '>= 4.6.100', +} +ffmpeg_deps = [] +ffmpeg_found = true +foreach name, version : ffmpeg_versions + dep = dependency(name, version: version, required: ffmpeg_opt) + ffmpeg_deps += dep + if not dep.found() + ffmpeg_found = false + break + endif +endforeach +if ffmpeg_found + media_backends += 'ffmpeg' + cdata.set('HAVE_FFMPEG', 1) shared_module('media-ffmpeg', 'gtkffmediafile.c', c_args: extra_c_args, @@ -47,10 +39,11 @@ if media_backends.contains('ffmpeg') install : true) endif -if media_backends.contains('gstreamer') - gstplayer_dep = dependency('gstreamer-player-1.0', version: '>= 1.12.3', required: true) +gstplayer_dep = dependency('gstreamer-player-1.0', version: '>= 1.12.3', + required: get_option('media-gstreamer')) +if gstplayer_dep.found() + media_backends += 'gstreamer' cdata.set('HAVE_GSTREAMER', 1) - shared_module('media-gstreamer', 'gtkgstmediafile.c', 'gtkgstpaintable.c', diff --git a/modules/printbackends/meson.build b/modules/printbackends/meson.build index 1cde173493..b60fdb202f 100644 --- a/modules/printbackends/meson.build +++ b/modules/printbackends/meson.build @@ -1,35 +1,4 @@ -all_print_backends = [ - 'cups', - 'cloudprint', -] - -enabled_print_backends = get_option('print').split(',') - -if enabled_print_backends.contains('none') - enabled_print_backends = [] -elif enabled_print_backends.contains('all') - enabled_print_backends = all_print_backends -endif - -# The 'file' print backend cannot be disabled -print_backends = ['file'] - -# Checks to see if we should compile with CUPS backend for GTK -enable_cups = enabled_print_backends.contains('cups') -if enable_cups - cups_dep = dependency('cups', version : '>=2.0', required: true) - print_backends += ['cups'] -endif - -# Checks to see if we should compile with cloudprint backend for GTK -enable_cloudprint = enabled_print_backends.contains('cloudprint') -if enable_cloudprint - rest_dep = dependency('rest-0.7', required : true) - json_glib_dep = dependency('json-glib-1.0', required : true) - if rest_dep.found() and json_glib_dep.found() - print_backends += ['cloudprint'] - endif -endif +print_backends = [] if not cc.has_header('cairo-pdf.h', dependencies : cairo_dep) error('Cannot find cairo-pdf.h. You must build Cairo with the pdf backend enabled.') @@ -44,11 +13,6 @@ if os_unix endif endif -# Automatic fall-back to the lpr backend -if not print_backends.contains('cups') - print_backends += ['lpr'] -endif - printbackends_subdir = 'gtk-4.0/@0@/printbackends'.format(gtk_binary_version) printbackends_install_dir = join_paths(get_option('libdir'), printbackends_subdir) @@ -61,7 +25,9 @@ printbackends_args = [ '-D_GLIB_EXTERN=@0@'.format(visibility_define), ] + common_cflags -if print_backends.contains('cups') +cups_dep = dependency('cups', version : '>=2.0', required: get_option('print-cups')) +if cups_dep.found() + print_backends += 'cups' shared_module('printbackend-cups', 'gtkprintbackendcups.c', 'gtkprintercups.c', @@ -71,9 +37,21 @@ if print_backends.contains('cups') dependencies: [libgtk_dep, cups_dep, colord_dep], install_dir: printbackends_install_dir, install : true) +else + # Automatic fall-back to the lpr backend + print_backends += 'lpr' + shared_module('printbackend-lpr', + 'gtkprintbackendlpr.c', + c_args: printbackends_args, + dependencies: libgtk_dep, + install_dir: printbackends_install_dir, + install : true) endif -if print_backends.contains('cloudprint') +rest_dep = dependency('rest-0.7', required : get_option('print-cloudprint')) +json_glib_dep = dependency('json-glib-1.0', required : get_option('print-cloudprint')) +if rest_dep.found() and json_glib_dep.found() + print_backends += ['cloudprint'] shared_module('printbackend-cloudprint', 'gtkprintbackendcloudprint.c', 'gtkprintercloudprint.c', @@ -84,20 +62,11 @@ if print_backends.contains('cloudprint') install : true) endif -if print_backends.contains('file') - shared_module('printbackend-file', - 'gtkprintbackendfile.c', - c_args: printbackends_args, - dependencies: libgtk_dep, - install_dir: printbackends_install_dir, - install : true) -endif - -if print_backends.contains('lpr') - shared_module('printbackend-lpr', - 'gtkprintbackendlpr.c', - c_args: printbackends_args, - dependencies: libgtk_dep, - install_dir: printbackends_install_dir, - install : true) -endif +# The 'file' print backend cannot be disabled +print_backends += 'file' +shared_module('printbackend-file', + 'gtkprintbackendfile.c', + c_args: printbackends_args, + dependencies: libgtk_dep, + install_dir: printbackends_install_dir, + install : true)