From 7b7d927caedd14460beeed7b620ddfb8597b3552 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 21 Dec 2020 11:23:14 +0000 Subject: [PATCH] build: introduce sd-bus-provider option Based on https://github.com/emersion/mako/commit/67f2ed1862a9 --- include/xdpw.h | 4 ++-- meson.build | 25 ++++++++++++++++++------- meson_options.txt | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/xdpw.h b/include/xdpw.h index 3dfb47a..2408a5e 100644 --- a/include/xdpw.h +++ b/include/xdpw.h @@ -2,9 +2,9 @@ #define XDPW_H #include -#ifdef HAVE_SYSTEMD +#ifdef HAVE_LIBSYSTEMD #include -#elif HAVE_ELOGIND +#elif HAVE_LIBELOGIND #include #endif diff --git a/meson.build b/meson.build index 76a9d7f..14d6f3c 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,7 @@ project( 'c', version: '0.1.0', license: 'MIT', - meson_version: '>=0.47.0', + meson_version: '>=0.50.0', default_options: [ 'c_std=c11', 'warning_level=2', @@ -27,13 +27,24 @@ pipewire = dependency('libpipewire-0.3', version: '>= 0.3.2') wayland_client = dependency('wayland-client') wayland_protos = dependency('wayland-protocols', version: '>=1.14') -logind = dependency('libsystemd', required: false) -if logind.found() - add_project_arguments('-DHAVE_SYSTEMD=1', language: 'c') +if get_option('sd-bus-provider') == 'auto' + assert(get_option('auto_features').auto(), 'sd-bus-provider must not be set to auto since auto_features != auto') + sdbus = dependency('libsystemd', + required: false, + not_found_message: 'libsystemd not found, trying libelogind', + ) + if not sdbus.found() + sdbus = dependency('libelogind', + required: false, + ) + endif + if not sdbus.found() + error('Neither libsystemd, nor libelogind was found') + endif else - logind = dependency('libelogind') - add_project_arguments('-DHAVE_ELOGIND=1', language: 'c') + sdbus = dependency(get_option('sd-bus-provider')) endif +add_project_arguments('-DHAVE_' + sdbus.name().to_upper() + '=1', language: 'c') subdir('protocols') @@ -53,7 +64,7 @@ executable( dependencies: [ wayland_client, wlr_protos, - logind, + sdbus, pipewire, rt, ], diff --git a/meson_options.txt b/meson_options.txt index 5303abc..0021a1b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ +option('sd-bus-provider', type: 'combo', choices: ['auto', 'libsystemd', 'libelogind'], value: 'auto', description: 'Provider of the sd-bus library') option('systemd', type: 'feature', value: 'auto', description: 'Install systemd user service unit')