[gnome-remote-desktop] build: Make enabled backends a build time option



commit 976902f519e4798deb5a2c14f1ca5af559d25f1d
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Feb 17 10:09:57 2021 +0100

    build: Make enabled backends a build time option
    
    This replaces the 'unicode' meson option, with two global 'vnc' and
    'rdp' options that fully turns off either one of the backends if wanted.
    One cannot turn off both at the same time.

 config.h.meson        |  7 ++--
 meson.build           | 62 ++++++++++++++++++++++++++-------
 meson_options.txt     |  9 +++--
 src/grd-daemon.c      | 40 +++++++++++++++++++---
 src/grd-session-rdp.c | 22 ------------
 src/meson.build       | 94 +++++++++++++++++++++++++++------------------------
 tests/meson.build     | 36 ++++++++++----------
 7 files changed, 166 insertions(+), 104 deletions(-)
---
diff --git a/config.h.meson b/config.h.meson
index 672449d..dd1b26e 100644
--- a/config.h.meson
+++ b/config.h.meson
@@ -6,5 +6,8 @@
 /* The prefix for our gettext translation domains. */
 #mesondefine GETTEXT_PACKAGE
 
-/* Defined if RDP unicode input is enabled */
-#mesondefine HAS_RDP_UNICODE_INPUT
+/* Defined if RDP backend enabled */
+#mesondefine HAVE_RDP
+
+/* Defined if VNC backend is enabled */
+#mesondefine HAVE_VNC
diff --git a/meson.build b/meson.build
index cdfdcad..abef01d 100644
--- a/meson.build
+++ b/meson.build
@@ -10,30 +10,40 @@ xkbcommon_req = '>= 1.0.0'
 gnome = import('gnome')
 
 cairo_dep = dependency('cairo')
-freerdp_dep = dependency('freerdp2', version: freerdp_req)
-freerdp_client_dep = dependency('freerdp-client2', version: freerdp_req)
-freerdp_server_dep = dependency('freerdp-server2', version: freerdp_req)
 glib_dep = dependency('glib-2.0')
 gio_dep = dependency('gio-2.0')
 gio_unix_dep = dependency('gio-unix-2.0')
 pipewire_dep = dependency('libpipewire-0.3', version: '>= 0.3.0')
 systemd_dep = dependency('systemd')
-libvncserver_dep = dependency('libvncserver')
-libvncclient_dep = dependency('libvncclient')
 libsecret_dep = dependency('libsecret-1')
 libnotify_dep = dependency('libnotify')
-winpr_dep = dependency('winpr2', version: freerdp_req)
 
-cdata = configuration_data()
-cdata.set_quoted('GETTEXT_PACKAGE', 'gnome-remote-desktop')
-cdata.set_quoted('VERSION', meson.project_version())
+have_rdp = get_option('rdp')
+have_vnc = get_option('vnc')
 
-has_rdp_unicode_input = get_option('rdp_unicode_input')
-if has_rdp_unicode_input
+if not have_rdp and not have_vnc
+  error('Must enable at least one backend')
+endif
+
+if have_rdp
+  freerdp_dep = dependency('freerdp2', version: freerdp_req)
+  freerdp_client_dep = dependency('freerdp-client2', version: freerdp_req)
+  freerdp_server_dep = dependency('freerdp-server2', version: freerdp_req)
+  winpr_dep = dependency('winpr2', version: freerdp_req)
   xkbcommon_dep = dependency('xkbcommon', version: xkbcommon_req)
 endif
 
-cdata.set('HAS_RDP_UNICODE_INPUT', has_rdp_unicode_input)
+if have_vnc
+  libvncserver_dep = dependency('libvncserver')
+  libvncclient_dep = dependency('libvncclient')
+endif
+
+cdata = configuration_data()
+cdata.set_quoted('GETTEXT_PACKAGE', 'gnome-remote-desktop')
+cdata.set_quoted('VERSION', meson.project_version())
+
+cdata.set('HAVE_RDP', have_rdp)
+cdata.set('HAVE_VNC', have_vnc)
 
 configure_file(input: 'config.h.meson',
                output: 'config.h',
@@ -53,7 +63,35 @@ endif
 top_srcdir = meson.current_source_dir()
 builddir = meson.current_build_dir()
 
+prefix = get_option('prefix')
+libexecdir = join_paths(prefix, get_option('libexecdir'))
+datadir = join_paths(prefix, get_option('datadir'))
+schemadir = join_paths(datadir, 'glib-2.0', 'schemas')
+
 subdir('src')
 subdir('tests')
 
 meson.add_install_script('meson_post_install.py')
+
+output = [
+  '',
+  '',
+  '   GNOME Remote Desktop ' + meson.project_version(),
+  '  ============================',
+  '',
+  '    Prefix....................... ' + prefix,
+  '    libexecdir................... ' + libexecdir,
+  '    datadir...................... ' + datadir,
+  '    systemd user unit dir........ ' + servicedir,
+  '    GSettings schema dir......... ' + schemadir,
+  '',
+  '    Backends:',
+  '',
+  '        RDP...................... ' + have_rdp.to_string(),
+  '        VNC...................... ' + have_vnc.to_string(),
+  '',
+  '  Now type \'ninja -C ' + meson.build_root() + '\' to build ' + meson.project_name(),
+  '',
+  '',
+]
+message('\n'.join(output))
diff --git a/meson_options.txt b/meson_options.txt
index 6e9d799..ca2908b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,7 +1,12 @@
-option('rdp_unicode_input',
+option('rdp',
        type: 'boolean',
        value: true,
-       description: 'Unicode input for the RDP backend')
+       description: 'Enable the RDP backend')
+
+option('vnc',
+       type: 'boolean',
+       value: true,
+       description: 'Enable the VNC backend')
 
 option('systemd_user_unit_dir',
        type: 'string',
diff --git a/src/grd-daemon.c b/src/grd-daemon.c
index c7b381b..576cb4b 100644
--- a/src/grd-daemon.c
+++ b/src/grd-daemon.c
@@ -47,8 +47,12 @@ struct _GrdDaemon
 
   GrdContext *context;
 
+#ifdef HAVE_RDP
   GrdRdpServer *rdp_server;
+#endif
+#ifdef HAVE_VNC
   GrdVncServer *vnc_server;
+#endif
 };
 
 G_DEFINE_TYPE (GrdDaemon, grd_daemon, G_TYPE_APPLICATION)
@@ -63,14 +67,12 @@ is_daemon_ready (GrdDaemon *daemon)
   return TRUE;
 }
 
+#ifdef HAVE_RDP
 static void
-maybe_enable_services (GrdDaemon *daemon)
+init_rdp_server (GrdDaemon *daemon)
 {
   GrdSettings *settings = grd_context_get_settings (daemon->context);
-  GError *error = NULL;
-
-  if (!is_daemon_ready (daemon))
-    return;
+  g_autoptr (GError) error = NULL;
 
   daemon->rdp_server = NULL;
   if (!g_access (grd_settings_get_rdp_server_cert (settings), F_OK) &&
@@ -86,6 +88,14 @@ maybe_enable_services (GrdDaemon *daemon)
     {
       g_message ("Didn't initialize RDP server: not configured");
     }
+}
+#endif /* HAVE_RDP */
+
+#ifdef HAVE_VNC
+static void
+init_vnc_server (GrdDaemon *daemon)
+{
+  g_autoptr (GError) error = NULL;
 
   daemon->vnc_server = grd_vnc_server_new (daemon->context);
   if (!grd_vnc_server_start (daemon->vnc_server, &error))
@@ -93,6 +103,22 @@ maybe_enable_services (GrdDaemon *daemon)
   else
     g_message ("Initialized VNC server");
 }
+#endif /* HAVE_VNC */
+
+static void
+maybe_enable_services (GrdDaemon *daemon)
+{
+  if (!is_daemon_ready (daemon))
+    return;
+
+#ifdef HAVE_RDP
+  init_rdp_server (daemon);
+#endif
+
+#ifdef HAVE_VNC
+  init_vnc_server (daemon);
+#endif
+}
 
 static void
 close_all_sessions (GrdDaemon *daemon)
@@ -111,8 +137,12 @@ static void
 disable_services (GrdDaemon *daemon)
 {
   close_all_sessions (daemon);
+#ifdef HAVE_RDP
   g_clear_object (&daemon->rdp_server);
+#endif
+#ifdef HAVE_VNC
   g_clear_object (&daemon->vnc_server);
+#endif
 }
 
 static void
diff --git a/src/grd-session-rdp.c b/src/grd-session-rdp.c
index 644a182..e679776 100644
--- a/src/grd-session-rdp.c
+++ b/src/grd-session-rdp.c
@@ -26,9 +26,7 @@
 #include <freerdp/peer.h>
 #include <gio/gio.h>
 #include <linux/input-event-codes.h>
-#ifdef HAS_RDP_UNICODE_INPUT
 #include <xkbcommon/xkbcommon.h>
-#endif
 
 #include "grd-clipboard-rdp.h"
 #include "grd-context.h"
@@ -87,9 +85,7 @@ struct _GrdSessionRdp
   uint16_t pointer_x;
   uint16_t pointer_y;
 
-#ifdef HAS_RDP_UNICODE_INPUT
   GHashTable *pressed_unicode_keys;
-#endif
 
   GrdRdpEventQueue *rdp_event_queue;
 
@@ -1086,7 +1082,6 @@ rdp_peer_refresh_region (freerdp_peer   *peer,
   ++rdp_peer_context->frame_id;
 }
 
-#ifdef HAS_RDP_UNICODE_INPUT
 static gboolean
 notify_keysym_released (gpointer key,
                         gpointer value,
@@ -1103,26 +1098,21 @@ notify_keysym_released (gpointer key,
 
   return TRUE;
 }
-#endif
 
 static BOOL
 rdp_input_synchronize_event (rdpInput *rdp_input,
                              uint32_t  flags)
 {
   RdpPeerContext *rdp_peer_context = (RdpPeerContext *) rdp_input->context;
-#ifdef HAS_RDP_UNICODE_INPUT
   GrdSessionRdp *session_rdp = rdp_peer_context->session_rdp;
   GrdSession *session = GRD_SESSION (session_rdp);
-#endif
 
   if (!is_rdp_peer_flag_set (rdp_peer_context, RDP_PEER_ACTIVATED))
     return TRUE;
 
-#ifdef HAS_RDP_UNICODE_INPUT
   g_hash_table_foreach_remove (session_rdp->pressed_unicode_keys,
                                notify_keysym_released,
                                session);
-#endif
 
   return TRUE;
 }
@@ -1260,18 +1250,15 @@ rdp_input_unicode_keyboard_event (rdpInput *rdp_input,
 {
   RdpPeerContext *rdp_peer_context = (RdpPeerContext *) rdp_input->context;
   GrdSessionRdp *session_rdp = rdp_peer_context->session_rdp;
-#ifdef HAS_RDP_UNICODE_INPUT
   GrdRdpEventQueue *rdp_event_queue = session_rdp->rdp_event_queue;
   uint32_t *code_utf32;
   xkb_keysym_t keysym;
   GrdKeyState key_state;
-#endif
 
   if (!is_rdp_peer_flag_set (rdp_peer_context, RDP_PEER_ACTIVATED) ||
       is_view_only (session_rdp))
     return TRUE;
 
-#ifdef HAS_RDP_UNICODE_INPUT
   code_utf32 = g_utf16_to_ucs4 (&code_utf16, 1, NULL, NULL, NULL);
   if (!code_utf32)
     return TRUE;
@@ -1297,7 +1284,6 @@ rdp_input_unicode_keyboard_event (rdpInput *rdp_input,
 
   grd_rdp_event_queue_add_input_event_keyboard_keysym (rdp_event_queue,
                                                        keysym, key_state);
-#endif
 
   return TRUE;
 }
@@ -1495,9 +1481,7 @@ init_rdp_session (GrdSessionRdp *session_rdp,
   rdp_settings->NSCodec = TRUE;
   rdp_settings->FrameMarkerCommandEnabled = TRUE;
   rdp_settings->SurfaceFrameMarkerEnabled = TRUE;
-#ifdef HAS_RDP_UNICODE_INPUT
   rdp_settings->UnicodeInput = TRUE;
-#endif
 
   peer->Capabilities = rdp_peer_capabilities;
   peer->PostConnect = rdp_peer_post_connect;
@@ -1688,11 +1672,9 @@ grd_session_rdp_stop (GrdSession *session)
   freerdp_peer_context_free (peer);
   freerdp_peer_free (peer);
 
-#ifdef HAS_RDP_UNICODE_INPUT
   g_hash_table_foreach_remove (session_rdp->pressed_unicode_keys,
                                notify_keysym_released,
                                session);
-#endif
   g_clear_object (&session_rdp->rdp_event_queue);
 
   g_clear_pointer (&session_rdp->last_frame, g_free);
@@ -1767,9 +1749,7 @@ grd_session_rdp_dispose (GObject *object)
 {
   GrdSessionRdp *session_rdp = GRD_SESSION_RDP (object);
 
-#ifdef HAS_RDP_UNICODE_INPUT
   g_clear_pointer (&session_rdp->pressed_unicode_keys, g_hash_table_unref);
-#endif
   g_clear_pointer (&session_rdp->pointer_cache, g_hash_table_unref);
 
   G_OBJECT_CLASS (grd_session_rdp_parent_class)->dispose (object);
@@ -1805,9 +1785,7 @@ static void
 grd_session_rdp_init (GrdSessionRdp *session_rdp)
 {
   session_rdp->pointer_cache = g_hash_table_new (NULL, are_pointer_bitmaps_equal);
-#ifdef HAS_RDP_UNICODE_INPUT
   session_rdp->pressed_unicode_keys = g_hash_table_new (NULL, NULL);
-#endif
 
   g_cond_init (&session_rdp->pending_jobs_cond);
   g_mutex_init (&session_rdp->pending_jobs_mutex);
diff --git a/src/meson.build b/src/meson.build
index b2ce5e6..04332a4 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,10 +1,16 @@
+deps = [
+  cairo_dep,
+  glib_dep,
+  gio_dep,
+  gio_unix_dep,
+  pipewire_dep,
+  libsecret_dep,
+  libnotify_dep,
+]
+
 daemon_sources = files([
   'grd-clipboard.c',
   'grd-clipboard.h',
-  'grd-clipboard-rdp.c',
-  'grd-clipboard-rdp.h',
-  'grd-clipboard-vnc.c',
-  'grd-clipboard-vnc.h',
   'grd-context.c',
   'grd-context.h',
   'grd-daemon.c',
@@ -18,41 +24,58 @@ daemon_sources = files([
   'grd-private.h',
   'grd-prompt.c',
   'grd-prompt.h',
-  'grd-rdp-event-queue.c',
-  'grd-rdp-event-queue.h',
-  'grd-rdp-pipewire-stream.c',
-  'grd-rdp-pipewire-stream.h',
-  'grd-rdp-sam.c',
-  'grd-rdp-sam.h',
-  'grd-rdp-server.c',
-  'grd-rdp-server.h',
   'grd-session.c',
   'grd-session.h',
-  'grd-session-rdp.c',
-  'grd-session-rdp.h',
-  'grd-session-vnc.c',
-  'grd-session-vnc.h',
   'grd-settings.c',
   'grd-settings.h',
   'grd-stream.c',
   'grd-stream.h',
   'grd-types.h',
-  'grd-vnc-cursor.c',
-  'grd-vnc-cursor.h',
-  'grd-vnc-pipewire-stream.c',
-  'grd-vnc-pipewire-stream.h',
-  'grd-vnc-server.c',
-  'grd-vnc-server.h',
 ])
 
-optional_deps = []
-
-if has_rdp_unicode_input
-  optional_deps += [
+if have_rdp
+  daemon_sources += files([
+    'grd-clipboard-rdp.c',
+    'grd-clipboard-rdp.h',
+    'grd-rdp-event-queue.c',
+    'grd-rdp-event-queue.h',
+    'grd-rdp-pipewire-stream.c',
+    'grd-rdp-pipewire-stream.h',
+    'grd-rdp-sam.c',
+    'grd-rdp-sam.h',
+    'grd-rdp-server.c',
+    'grd-rdp-server.h',
+    'grd-session-rdp.c',
+    'grd-session-rdp.h',
+  ])
+  deps += [
+    freerdp_dep,
+    freerdp_client_dep,
+    freerdp_server_dep,
+    winpr_dep,
     xkbcommon_dep,
   ]
 endif
 
+if have_vnc
+  daemon_sources += files([
+    'grd-clipboard-vnc.c',
+    'grd-clipboard-vnc.h',
+    'grd-session-vnc.c',
+    'grd-session-vnc.h',
+    'grd-vnc-cursor.c',
+    'grd-vnc-cursor.h',
+    'grd-vnc-pipewire-stream.c',
+    'grd-vnc-pipewire-stream.h',
+    'grd-vnc-server.c',
+    'grd-vnc-server.h',
+  ])
+
+  deps += [
+    libvncserver_dep,
+  ]
+endif
+
 gen_daemon_sources = []
 
 gen_daemon_sources += gnome.gdbus_codegen('grd-dbus-screen-cast',
@@ -70,24 +93,9 @@ control_sources = ([
   'grd-control.c'
 ])
 
-prefix = get_option('prefix')
-libexecdir = join_paths(prefix, get_option('libexecdir'))
-
 executable('gnome-remote-desktop-daemon',
            daemon_sources,
-           dependencies: [cairo_dep,
-                          freerdp_dep,
-                          freerdp_client_dep,
-                          freerdp_server_dep,
-                          glib_dep,
-                          gio_dep,
-                          gio_unix_dep,
-                          pipewire_dep,
-                          libvncserver_dep,
-                          libsecret_dep,
-                          libnotify_dep,
-                          optional_deps,
-                          winpr_dep],
+           dependencies: deps,
            include_directories: [configinc],
            install: true,
            install_dir: libexecdir)
@@ -106,8 +114,6 @@ configure_file(input: 'gnome-remote-desktop.service.in',
                configuration: service_config,
                install_dir: servicedir)
 
-datadir = join_paths(prefix, get_option('datadir'))
-schemadir = join_paths(datadir, 'glib-2.0', 'schemas')
 custom_target('gsettings-enums',
               input: 'grd-enums.h',
               output: 'org.gnome.desktop.remote-desktop.enums.xml',
diff --git a/tests/meson.build b/tests/meson.build
index e7e028a..978ae23 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,20 +1,22 @@
-test_client_vnc = executable(
-  'test-client-vnc',
-  files(['test-client-vnc.c']),
-  dependencies: [glib_dep,
-  libvncclient_dep],
-  include_directories: [configinc],
-  install: false)
+if have_vnc
+  test_client_vnc = executable(
+    'test-client-vnc',
+    files(['test-client-vnc.c']),
+    dependencies: [glib_dep,
+    libvncclient_dep],
+    include_directories: [configinc],
+    install: false)
 
-test_runner = find_program('vnc-test-runner.sh')
+  test_runner = find_program('vnc-test-runner.sh')
 
-test_env = environment()
-test_env.set('TEST_SRCDIR', top_srcdir)
-test_env.set('TEST_BUILDDIR', builddir)
-test_env.set('NO_AT_BRIDGE', '1')
+  test_env = environment()
+  test_env.set('TEST_SRCDIR', top_srcdir)
+  test_env.set('TEST_BUILDDIR', builddir)
+  test_env.set('NO_AT_BRIDGE', '1')
 
-test('gnome-remote-desktop/vnc', test_runner,
-  env: test_env,
-  is_parallel: false,
-  timeout: 10,
-)
+  test('gnome-remote-desktop/vnc', test_runner,
+    env: test_env,
+    is_parallel: false,
+    timeout: 10,
+  )
+endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]