From 70fb21c35ba432bec86b61ef6e938d65629fde31 Mon Sep 17 00:00:00 2001 From: ayaka Date: Fri, 26 Mar 2021 23:28:37 +0800 Subject: [PATCH] backend: make DRM and libinput backends optional Co-authored-by: Simon Ser --- backend/backend.c | 25 +++++++++++++++++++++++-- backend/drm/meson.build | 2 ++ backend/libinput/meson.build | 19 +++++++++++++++++++ backend/meson.build | 21 ++++++++++++++++----- backend/x11/meson.build | 11 ++++------- include/wlr/config.h.in | 2 ++ meson.build | 4 ++-- meson_options.txt | 2 +- 8 files changed, 69 insertions(+), 17 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 8a7d69bd..dbf38214 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -6,10 +6,9 @@ #include #include #include -#include + #include #include -#include #include #include #include @@ -22,6 +21,14 @@ #include "render/allocator.h" #include "util/signal.h" +#if WLR_HAS_DRM_BACKEND +#include +#endif + +#if WLR_HAS_LIBINPUT_BACKEND +#include +#endif + #if WLR_HAS_X11_BACKEND #include #endif @@ -211,6 +218,7 @@ static struct wlr_backend *attempt_noop_backend(struct wl_display *display) { return backend; } +#if WLR_HAS_DRM_BACKEND static struct wlr_backend *attempt_drm_backend(struct wl_display *display, struct wlr_backend *backend, struct wlr_session *session) { struct wlr_device *gpus[8]; @@ -240,6 +248,7 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display, return primary_drm; } +#endif static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, struct wlr_backend *backend, struct wlr_session **session, @@ -265,9 +274,17 @@ static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, } if (strcmp(name, "libinput") == 0) { +#if WLR_HAS_LIBINPUT_BACKEND return wlr_libinput_backend_create(display, *session); +#else + return NULL; +#endif } else { +#if WLR_HAS_DRM_BACKEND return attempt_drm_backend(display, backend, *session); +#else + return NULL; +#endif } } @@ -355,6 +372,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } +#if WLR_HAS_LIBINPUT_BACKEND struct wlr_backend *libinput = wlr_libinput_backend_create(display, multi->session); if (!libinput) { @@ -364,7 +382,9 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } wlr_multi_backend_add(backend, libinput); +#endif +#if WLR_HAS_DRM_BACKEND struct wlr_backend *primary_drm = attempt_drm_backend(display, backend, multi->session); if (!primary_drm) { @@ -376,6 +396,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { } return backend; +#endif error: wlr_backend_destroy(backend); diff --git a/backend/drm/meson.build b/backend/drm/meson.build index ffddfdfc..b076b472 100644 --- a/backend/drm/meson.build +++ b/backend/drm/meson.build @@ -8,3 +8,5 @@ wlr_files += files( 'renderer.c', 'util.c', ) + +features += { 'drm-backend': true } diff --git a/backend/libinput/meson.build b/backend/libinput/meson.build index ff78d2f8..44bb57e1 100644 --- a/backend/libinput/meson.build +++ b/backend/libinput/meson.build @@ -1,3 +1,19 @@ +msg = ['Required for libinput backend support.'] +if 'libinput' in backends + msg += 'Install "libinput" or disable the libinput backend.' +endif + +libinput = dependency( + 'libinput', + version: '>=1.14.0', + required: 'libinput' in backends, + not_found_message: '\n'.join(msg), +) + +if not libinput.found() + subdir_done() +endif + wlr_files += files( 'backend.c', 'events.c', @@ -8,3 +24,6 @@ wlr_files += files( 'tablet_tool.c', 'touch.c', ) + +features += { 'libinput-backend': true } +wlr_deps += libinput diff --git a/backend/meson.build b/backend/meson.build index 3cd24b39..7fffc839 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -1,11 +1,22 @@ wlr_files += files('backend.c') -subdir('drm') -subdir('headless') -subdir('libinput') +all_backends = ['drm', 'libinput', 'x11'] +backends = get_option('backends') +if 'auto' in backends and get_option('auto_features').enabled() + backends = all_backends +elif 'auto' in backends and get_option('auto_features').disabled() + backends = [] +endif + +foreach backend : all_backends + if backend in backends or 'auto' in backends + subdir(backend) + endif +endforeach + subdir('multi') -subdir('noop') subdir('wayland') -subdir('x11') +subdir('noop') +subdir('headless') subdir('session') diff --git a/backend/x11/meson.build b/backend/x11/meson.build index 0c6ea73b..97b6d540 100644 --- a/backend/x11/meson.build +++ b/backend/x11/meson.build @@ -10,17 +10,14 @@ x11_required = [ 'xcb-xinput', ] -msg = [] -if get_option('x11-backend').enabled() - msg += 'Install "@0@" or pass "-Dx11-backend=disabled" to disable it.' -endif -if not get_option('x11-backend').disabled() - msg += 'Required for X11 backend support.' +msg = ['Required for X11 backend support.'] +if 'x11' in backends + msg += 'Install "@0@" or disable the X11 backend.' endif foreach lib : x11_required dep = dependency(lib, - required: get_option('x11-backend'), + required: 'x11' in backends, not_found_message: '\n'.join(msg).format(lib), ) if not dep.found() diff --git a/include/wlr/config.h.in b/include/wlr/config.h.in index 957609a6..f8e55149 100644 --- a/include/wlr/config.h.in +++ b/include/wlr/config.h.in @@ -1,6 +1,8 @@ #ifndef WLR_CONFIG_H #define WLR_CONFIG_H +#mesondefine WLR_HAS_DRM_BACKEND +#mesondefine WLR_HAS_LIBINPUT_BACKEND #mesondefine WLR_HAS_X11_BACKEND #mesondefine WLR_HAS_GLES2_RENDERER diff --git a/meson.build b/meson.build index fec67d82..894e61a9 100644 --- a/meson.build +++ b/meson.build @@ -86,7 +86,9 @@ else endif features = { + 'drm-backend': false, 'x11-backend': false, + 'libinput-backend': false, 'xwayland': false, 'gles2-renderer': false, } @@ -98,7 +100,6 @@ wayland_server = dependency('wayland-server', version: '>=1.19') wayland_client = dependency('wayland-client') drm = dependency('libdrm', version: '>=2.4.105') gbm = dependency('gbm', version: '>=17.1.0') -libinput = dependency('libinput', version: '>=1.14.0') xkbcommon = dependency('xkbcommon') udev = dependency('libudev') pixman = dependency('pixman-1') @@ -111,7 +112,6 @@ wlr_deps = [ wayland_client, drm, gbm, - libinput, xkbcommon, udev, pixman, diff --git a/meson_options.txt b/meson_options.txt index a40b06f6..7e4fd7bd 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,6 +1,6 @@ option('xcb-errors', type: 'feature', value: 'auto', description: 'Use xcb-errors util library') option('xwayland', type: 'feature', value: 'auto', yield: true, description: 'Enable support for X11 applications') -option('x11-backend', type: 'feature', value: 'auto', description: 'Enable X11 backend') option('examples', type: 'boolean', value: true, description: 'Build example applications') option('icon_directory', description: 'Location used to look for cursors (default: ${datadir}/icons)', type: 'string', value: '') option('renderers', type: 'array', choices: ['auto', 'gles2'], value: ['auto'], description: 'Select built-in renderers') +option('backends', type: 'array', choices: ['auto', 'drm', 'libinput', 'x11'], value: ['auto'], description: 'Select built-in backends')