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.
This commit is contained in:
Gleb Popov 2024-07-24 15:10:10 +03:00
parent 3936eaaa39
commit c7e2ae30f0
3 changed files with 32 additions and 3 deletions

View File

@ -789,19 +789,41 @@ gioenumtypes_c = custom_target('gioenumtypes_c',
gioenumtypes_dep = declare_dependency(sources : [gioenumtypes_h, glib_enumtypes_h, gio_visibility_h]) 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 # 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') subdir('inotify')
internal_deps += [ inotify_lib ] internal_deps += [ inotify_lib ]
endif endif
# kevent # kevent
if have_func_kqueue and have_func_kevent if file_monitor_backend == 'kqueue'
glib_conf.set('FILE_MONITOR_BACKEND_KQUEUE', 1)
subdir('kqueue') subdir('kqueue')
internal_deps += [ kqueue_lib ] internal_deps += [ kqueue_lib ]
endif endif
if host_system == 'windows' if file_monitor_backend == 'win32'
glib_conf.set('FILE_MONITOR_BACKEND_WIN32', 1)
subdir('win32') subdir('win32')
internal_deps += [ giowin32_lib ] internal_deps += [ giowin32_lib ]
endif endif

View File

@ -2738,4 +2738,5 @@ summary({
'libelf' : get_option('libelf'), 'libelf' : get_option('libelf'),
'multiarch' : get_option('multiarch'), 'multiarch' : get_option('multiarch'),
'introspection' : enable_gir, 'introspection' : enable_gir,
'file_monitor_backend' : get_option('file_monitor_backend'),
}, section: 'Options') }, section: 'Options')

View File

@ -149,3 +149,9 @@ option('introspection',
type: 'feature', type: 'feature',
value: 'auto', value: 'auto',
description: 'Enable generating introspection data (requires gobject-introspection)') 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')