From 6a1bd5b0c9be55d21c6e066a94fc6fd77fea96ce Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 10 Jun 2022 10:31:37 +1000 Subject: [PATCH] meson.build: check gtk targets before building We have two different dependencies on Wayland: GTK support and the wayland-protocols we use directly. If we have GTK support but wayland-protocols is not installed at meson configure time, our build fails. To avoid having multiple ifdefs in the code, let's define two new ones: HAVE_GTK_WAYLAND and HAVE_GTK_X11, both set if GTK supports that particular target (from pkgconfig) and we have the other support libraries we need. Signed-off-by: Peter Hutterer --- meson.build | 52 ++++++++++++++++++++++++++-------------------- tools/libinput-debug-gui.c | 22 ++++++++++---------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/meson.build b/meson.build index b8b9271..9b5927e 100644 --- a/meson.build +++ b/meson.build @@ -561,34 +561,42 @@ if get_option('debug-gui') config_h.set10('HAVE_GTK3', dep_gtk.found()) endif + gtk_targets = dep_gtk.get_pkgconfig_variable('targets') + have_gtk_wayland = gtk_targets.contains('wayland') + have_gtk_x11 = gtk_targets.contains('x11') + dep_cairo = dependency('cairo') dep_glib = dependency('glib-2.0') - dep_wayland_client = dependency('wayland-client', required : false) - dep_wayland_protocols = dependency('wayland-protocols', required : false) dep_x11 = dependency('x11', required : false) + config_h.set10('HAVE_GTK_X11', have_gtk_x11 and dep_x11.found()) debug_gui_sources = [ 'tools/libinput-debug-gui.c' ] - if dep_wayland_client.found() and dep_wayland_protocols.found() - wayland_scanner = find_program('wayland-scanner') - wlproto_dir = dep_wayland_protocols.get_pkgconfig_variable('pkgdatadir') - - proto_name = 'pointer-constraints-unstable-v1' - input = files(wlproto_dir / 'unstable' / 'pointer-constraints' / '@0@.xml'.format(proto_name)) - - wayland_headers = custom_target('@0@ client header'.format(proto_name), - input: input, - output: '@0@-client-protocol.h'.format(proto_name), - command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'], - ) - - wayland_sources = custom_target('@0@ source'.format(proto_name), - input: input, - output: '@0@-protocol.c'.format(proto_name), - command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'], - ) - - debug_gui_sources += [ wayland_headers, wayland_sources ] + if have_gtk_wayland + dep_wayland_client = dependency('wayland-client', required : false) + dep_wayland_protocols = dependency('wayland-protocols', required : false) + if dep_wayland_client.found() and dep_wayland_protocols.found() + wayland_scanner = find_program('wayland-scanner') + wlproto_dir = dep_wayland_protocols.get_pkgconfig_variable('pkgdatadir') + + proto_name = 'pointer-constraints-unstable-v1' + input = files(wlproto_dir / 'unstable' / 'pointer-constraints' / '@0@.xml'.format(proto_name)) + + wayland_headers = custom_target('@0@ client header'.format(proto_name), + input: input, + output: '@0@-client-protocol.h'.format(proto_name), + command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'], + ) + + wayland_sources = custom_target('@0@ source'.format(proto_name), + input: input, + output: '@0@-protocol.c'.format(proto_name), + command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'], + ) + + debug_gui_sources += [ wayland_headers, wayland_sources ] + config_h.set10('HAVE_GTK_WAYLAND', true) + endif endif deps_debug_gui = [ diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index b8685c8..309c045 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -48,7 +48,7 @@ #include "shared.h" -#ifdef GDK_WINDOWING_WAYLAND +#if HAVE_GTK_WAYLAND #include #include "pointer-constraints-unstable-v1-client-protocol.h" #if HAVE_GTK4 @@ -58,7 +58,7 @@ #endif #endif -#ifdef GDK_WINDOWING_X11 +#if HAVE_GTK_X11 #include #include #if HAVE_GTK4 @@ -120,7 +120,7 @@ struct window { struct { bool locked; -#ifdef GDK_WINDOWING_WAYLAND +#if HAVE_GTK_WAYLAND struct zwp_pointer_constraints_v1 *wayland_pointer_constraints; struct zwp_locked_pointer_v1 *wayland_locked_pointer; #endif @@ -207,7 +207,7 @@ struct window { struct libinput_device *devices[50]; }; -#ifdef GDK_WINDOWING_WAYLAND +#if HAVE_GTK_WAYLAND static void wayland_registry_global(void *data, struct wl_registry *registry, @@ -297,9 +297,9 @@ backend_is_wayland(void) { return GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()); } -#endif /* GDK_WINDOWING_WAYLAND */ +#endif /* HAVE_GTK_WAYLAND */ -#ifdef GDK_WINDOWING_X11 +#if HAVE_GTK_X11 static bool x_lock_pointer(struct window *w) { @@ -342,19 +342,19 @@ backend_is_x11(void) { return GDK_IS_X11_DISPLAY(gdk_display_get_default()); } -#endif /* GDK_WINDOWING_X11 */ +#endif /* HAVE_GTK_X11 */ static bool window_lock_pointer(struct window *w) { w->lock_pointer.locked = false; -#ifdef GDK_WINDOWING_WAYLAND +#if HAVE_GTK_WAYLAND if (backend_is_wayland()) w->lock_pointer.locked = wayland_lock_pointer(w); #endif -#ifdef GDK_WINDOWING_X11 +#if HAVE_GTK_X11 if (backend_is_x11()) w->lock_pointer.locked = x_lock_pointer(w); #endif @@ -370,12 +370,12 @@ window_unlock_pointer(struct window *w) w->lock_pointer.locked = false; -#ifdef GDK_WINDOWING_WAYLAND +#if HAVE_GTK_WAYLAND if (backend_is_wayland()) wayland_unlock_pointer(w); #endif -#ifdef GDK_WINDOWING_X11 +#if HAVE_GTK_X11 if (backend_is_x11()) x_unlock_pointer(w); #endif -- 2.7.4