meson.build: rework systemd related options

One issues is that the `systemd-{system,user}-service` feature options
do not anything without the `systemd` option. This makes it more
complicated to arrive at the desired build configuration since there
are 3^3 = 27 possible ways to set each of them, but if `systemd=disabled`,
then the other two are just ignored.

Secondly, the `systemd` option also influences whether or not libsystemd
will be used or not. This is not strictly necessary, since the "systemd"
and "libsystemd" pkg-config files might be split, and one might wish to
disable any kind of service file generation, but use libsystemd.

Solve the first issues by using the `systemd-{system,user}-service` options
when looking up the "systemd" dependency for generating service files. This
means that the corresponding option is in full control, no secondary options
are necessary. This means that the "systemd" dependency is looked up potentially
twice, but that should not be a significant issue since meson caches dependecy
lookups.

And solve the second issue by renaming the now unused `systemd` option to
`libsystemd` and using it solely to control whether or not libsystemd will
be used.

Furthermore, the default value of `systemd-user-service` is set to "auto" to
prevent the dependency lookup from failing on non-systemd systemd out of
the box. And the journal tests in "test-support" are extended to return "skip"
if `sd_journal_open()` returns `ENOSYS`, which is needed because "elogind"
ships the systemd pkg-config files and headers.
This commit is contained in:
Barnabás Pőcze 2025-05-10 17:43:28 +02:00 committed by Wim Taymans
parent 97996a6e20
commit f2c878a2c1
7 changed files with 25 additions and 17 deletions

View file

@ -277,11 +277,9 @@ endforeach
cdata.set('HAVE_PIDFD_OPEN', cdata.set('HAVE_PIDFD_OPEN',
cc.get_define('SYS_pidfd_open', prefix: '#include <sys/syscall.h>') != '') cc.get_define('SYS_pidfd_open', prefix: '#include <sys/syscall.h>') != '')
systemd = dependency('systemd', required: get_option('systemd')) systemd_dep = dependency('libsystemd', required: get_option('libsystemd'))
systemd_dep = dependency('libsystemd',required: get_option('systemd'))
summary({'systemd conf data': systemd.found()}, bool_yn: true)
summary({'libsystemd': systemd_dep.found()}, bool_yn: true) summary({'libsystemd': systemd_dep.found()}, bool_yn: true)
cdata.set('HAVE_SYSTEMD', systemd.found() and systemd_dep.found()) cdata.set('HAVE_SYSTEMD', systemd_dep.found())
logind_dep = dependency(get_option('logind-provider'), required: get_option('logind')) logind_dep = dependency(get_option('logind-provider'), required: get_option('logind'))
summary({'logind': logind_dep.found()}, bool_yn: true) summary({'logind': logind_dep.found()}, bool_yn: true)

View file

@ -30,8 +30,8 @@ option('gstreamer-device-provider',
description: 'Build GStreamer device provider plugin', description: 'Build GStreamer device provider plugin',
type: 'feature', type: 'feature',
value: 'auto') value: 'auto')
option('systemd', option('libsystemd',
description: 'Enable systemd integration', description: 'Enable code that depends on libsystemd',
type: 'feature', type: 'feature',
value: 'auto') value: 'auto')
option('logind', option('logind',
@ -48,9 +48,9 @@ option('systemd-system-service',
type: 'feature', type: 'feature',
value: 'disabled') value: 'disabled')
option('systemd-user-service', option('systemd-user-service',
description: 'Install systemd user service file (ignored without systemd)', description: 'Install systemd user service file',
type: 'feature', type: 'feature',
value: 'enabled') value: 'auto')
option('selinux', option('selinux',
description: 'Enable SELinux integration', description: 'Enable SELinux integration',
type: 'feature', type: 'feature',

View file

@ -161,6 +161,4 @@ custom_target('pipewire-uninstalled',
#endif #endif
subdir('filter-chain') subdir('filter-chain')
if systemd.found() subdir('systemd')
subdir('systemd')
endif

View file

@ -1,6 +1,2 @@
if get_option('systemd-system-service').allowed() subdir('system')
subdir('system') subdir('user')
endif
if get_option('systemd-user-service').allowed()
subdir('user')
endif

View file

@ -1,3 +1,8 @@
systemd = dependency('systemd', required : get_option('systemd-system-service'))
if not systemd.found()
subdir_done()
endif
systemd_system_services_dir = systemd.get_variable('systemdsystemunitdir', pkgconfig_define : [ 'rootprefix', prefix]) systemd_system_services_dir = systemd.get_variable('systemdsystemunitdir', pkgconfig_define : [ 'rootprefix', prefix])
if get_option('systemd-system-unit-dir') != '' if get_option('systemd-system-unit-dir') != ''
systemd_system_services_dir = get_option('systemd-system-unit-dir') systemd_system_services_dir = get_option('systemd-system-unit-dir')

View file

@ -1,3 +1,8 @@
systemd = dependency('systemd', required : get_option('systemd-user-service'))
if not systemd.found()
subdir_done()
endif
systemd_user_services_dir = systemd.get_variable('systemduserunitdir', pkgconfig_define : [ 'prefix', prefix]) systemd_user_services_dir = systemd.get_variable('systemduserunitdir', pkgconfig_define : [ 'prefix', prefix])
if get_option('systemd-user-unit-dir') != '' if get_option('systemd-user-unit-dir') != ''
systemd_user_services_dir = get_option('systemd-user-unit-dir') systemd_user_services_dir = get_option('systemd-user-unit-dir')

View file

@ -496,6 +496,9 @@ PWTEST(logger_journal)
pwtest_ptr_notnull(iface); pwtest_ptr_notnull(iface);
rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_CURRENT_USER); rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_CURRENT_USER);
if (rc == -ENOSYS)
return PWTEST_SKIP;
pwtest_neg_errno_ok(rc); pwtest_neg_errno_ok(rc);
sd_journal_seek_head(journal); sd_journal_seek_head(journal);
@ -565,6 +568,9 @@ PWTEST(logger_journal_chain)
pwtest_ptr_notnull(iface); pwtest_ptr_notnull(iface);
rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY); rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY);
if (rc == -ENOSYS)
return PWTEST_SKIP;
pwtest_neg_errno_ok(rc); pwtest_neg_errno_ok(rc);
sd_journal_seek_head(journal); sd_journal_seek_head(journal);
if (sd_journal_next(journal) == 0) { /* No entries? We don't have a journal */ if (sd_journal_next(journal) == 0) { /* No entries? We don't have a journal */