From c7e2ae30f0f3406f3d841d470be4ec81fb385534 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Wed, 24 Jul 2024 15:10:10 +0300 Subject: [PATCH] Add Meson option that allows selecting GFileMonitor's backend implementation The option defaults to 'auto' which keeps the current selection behavior, but also allows user to override the choice. Also make the chosen backend is reported to the code via CPP defines. --- gio/meson.build | 28 +++++++++++++++++++++++++--- meson.build | 1 + meson.options | 6 ++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gio/meson.build b/gio/meson.build index d49636d68..447ddd6b2 100644 --- a/gio/meson.build +++ b/gio/meson.build @@ -789,19 +789,41 @@ gioenumtypes_c = custom_target('gioenumtypes_c', gioenumtypes_dep = declare_dependency(sources : [gioenumtypes_h, glib_enumtypes_h, gio_visibility_h]) +file_monitor_backend = get_option('file_monitor_backend') +if file_monitor_backend == 'auto' + if glib_conf.has('HAVE_SYS_INOTIFY_H') and have_func_inotify_init1 + file_monitor_backend = 'inotify' + elif have_func_kqueue and have_func_kevent + file_monitor_backend = 'kqueue' + elif host_system == 'windows' + file_monitor_backend = 'win32' + endif +endif + # inotify -if glib_conf.has('HAVE_SYS_INOTIFY_H') and have_func_inotify_init1 +if file_monitor_backend == 'inotify' + glib_conf.set('FILE_MONITOR_BACKEND_INOTIFY', 1) + subdir('inotify') + internal_deps += [ inotify_lib ] +endif + +# libinotify-kqueue +# uses the same code as inotify, but changes some functions behavior via #ifdef's +if file_monitor_backend == 'libinotify-kqueue' + glib_conf.set('FILE_MONITOR_BACKEND_LIBINOTIFY_KQUEUE', 1) subdir('inotify') internal_deps += [ inotify_lib ] endif # kevent -if have_func_kqueue and have_func_kevent +if file_monitor_backend == 'kqueue' + glib_conf.set('FILE_MONITOR_BACKEND_KQUEUE', 1) subdir('kqueue') internal_deps += [ kqueue_lib ] endif -if host_system == 'windows' +if file_monitor_backend == 'win32' + glib_conf.set('FILE_MONITOR_BACKEND_WIN32', 1) subdir('win32') internal_deps += [ giowin32_lib ] endif diff --git a/meson.build b/meson.build index 2aa4239a9..c9f0404b4 100644 --- a/meson.build +++ b/meson.build @@ -2738,4 +2738,5 @@ summary({ 'libelf' : get_option('libelf'), 'multiarch' : get_option('multiarch'), 'introspection' : enable_gir, + 'file_monitor_backend' : get_option('file_monitor_backend'), }, section: 'Options') diff --git a/meson.options b/meson.options index 93207e0ed..b650eafc5 100644 --- a/meson.options +++ b/meson.options @@ -149,3 +149,9 @@ option('introspection', type: 'feature', value: 'auto', description: 'Enable generating introspection data (requires gobject-introspection)') + +option('file_monitor_backend', + type : 'combo', + choices : ['auto', 'inotify', 'kqueue', 'libinotify-kqueue', 'win32'], + value : 'auto', + description : 'The name of the system API to use as a GFileMonitor backend')