From 26e192a5f1b21449407adffbad73f648f4a18591 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 21 Dec 2020 21:24:35 +0000 Subject: [PATCH] build: rename logind-provider to sd-bus-provider Based on https://github.com/swaywm/sway/commit/fdbe98512a71 --- main.c | 26 +++++++++++++------------- meson.build | 37 ++++++++++++++++++++++++++++++------- meson_options.txt | 2 +- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/main.c b/main.c index dbbd6d38..4c5e1a04 100644 --- a/main.c +++ b/main.c @@ -18,9 +18,9 @@ #include "idle-client-protocol.h" #include "ext-idle-notify-v1-client-protocol.h" #include "log.h" -#if HAVE_SYSTEMD +#if HAVE_LIBSYSTEMD #include -#elif HAVE_ELOGIND +#elif HAVE_LIBELOGIND #include #endif @@ -179,7 +179,7 @@ static void cmd_exec(char *param) { } } -#if HAVE_SYSTEMD || HAVE_ELOGIND +#if HAVE_LOGIND #define DBUS_LOGIND_SERVICE "org.freedesktop.login1" #define DBUS_LOGIND_PATH "/org/freedesktop/login1" #define DBUS_LOGIND_MANAGER_INTERFACE "org.freedesktop.login1.Manager" @@ -610,7 +610,7 @@ static void enable_timeouts(void) { if (state.timeouts_enabled) { return; } -#if HAVE_SYSTEMD || HAVE_ELOGIND +#if HAVE_LOGIND if (get_logind_idle_inhibit()) { swayidle_log(LOG_INFO, "Not enabling timeouts: idle inhibitor found"); return; @@ -625,7 +625,7 @@ static void enable_timeouts(void) { } } -#if HAVE_SYSTEMD || HAVE_ELOGIND +#if HAVE_LOGIND static void disable_timeouts(void) { if (!state.timeouts_enabled) { return; @@ -646,7 +646,7 @@ static void disable_timeouts(void) { static void handle_idled(struct swayidle_timeout_cmd *cmd) { cmd->resume_pending = true; swayidle_log(LOG_DEBUG, "idle state"); -#if HAVE_SYSTEMD || HAVE_ELOGIND +#if HAVE_LOGIND if (cmd->idlehint) { set_idle_hint(true); } else @@ -662,7 +662,7 @@ static void handle_resumed(struct swayidle_timeout_cmd *cmd) { if (cmd->registered_timeout != cmd->timeout) { register_timeout(cmd, cmd->timeout); } -#if HAVE_SYSTEMD || HAVE_ELOGIND +#if HAVE_LOGIND if (cmd->idlehint) { set_idle_hint(false); } else @@ -760,7 +760,7 @@ static int parse_timeout(int argc, char **argv) { } static int parse_sleep(int argc, char **argv) { -#if !HAVE_SYSTEMD && !HAVE_ELOGIND +#if !HAVE_LOGIND swayidle_log(LOG_ERROR, "%s not supported: swayidle was compiled " "with neither systemd nor elogind support.", "before-sleep"); exit(-1); @@ -780,7 +780,7 @@ static int parse_sleep(int argc, char **argv) { } static int parse_resume(int argc, char **argv) { -#if !HAVE_SYSTEMD && !HAVE_ELOGIND +#if !HAVE_LOGIND swayidle_log(LOG_ERROR, "%s not supported: swayidle was compiled " "with neither systemd nor elogind support.", "after-resume"); exit(-1); @@ -800,7 +800,7 @@ static int parse_resume(int argc, char **argv) { } static int parse_lock(int argc, char **argv) { -#if !HAVE_SYSTEMD && !HAVE_ELOGIND +#if !HAVE_LOGIND swayidle_log(LOG_ERROR, "%s not supported: swayidle was compiled" " with neither systemd nor elogind support.", "lock"); exit(-1); @@ -820,7 +820,7 @@ static int parse_lock(int argc, char **argv) { } static int parse_unlock(int argc, char **argv) { -#if !HAVE_SYSTEMD && !HAVE_ELOGIND +#if !HAVE_LOGIND swayidle_log(LOG_ERROR, "%s not supported: swayidle was compiled" " with neither systemd nor elogind support.", "unlock"); exit(-1); @@ -840,7 +840,7 @@ static int parse_unlock(int argc, char **argv) { } static int parse_idlehint(int argc, char **argv) { -#if !HAVE_SYSTEMD && !HAVE_ELOGIND +#if !HAVE_LOGIND swayidle_log(LOG_ERROR, "%s not supported: swayidle was compiled" " with neither systemd nor elogind support.", "idlehint"); exit(-1); @@ -1126,7 +1126,7 @@ int main(int argc, char *argv[]) { } bool should_run = !wl_list_empty(&state.timeout_cmds); -#if HAVE_SYSTEMD || HAVE_ELOGIND +#if HAVE_LOGIND connect_to_bus(); setup_property_changed_listener(); if (state.before_sleep_cmd || state.after_resume_cmd) { diff --git a/meson.build b/meson.build index b7b283fd..961562a8 100644 --- a/meson.build +++ b/meson.build @@ -32,7 +32,6 @@ wayland_protos = dependency('wayland-protocols', version: '>=1.27') wayland_server = dependency('wayland-server') bash_comp = dependency('bash-completion', required: false) fish_comp = dependency('fish', required: false) -logind = dependency('lib' + get_option('logind-provider'), required: get_option('logind')) scdoc = find_program('scdoc', required: get_option('man-pages')) wayland_scanner = find_program('wayland-scanner') @@ -86,15 +85,39 @@ swayidle_deps = [ wayland_server, ] -conf_data = configuration_data() -conf_data.set10('HAVE_SYSTEMD', false) -conf_data.set10('HAVE_ELOGIND', false) +if get_option('sd-bus-provider') == 'auto' + if not get_option('logind').disabled() + assert(get_option('auto_features').auto(), 'sd-bus-provider must not be set to auto since auto_features != auto') + endif + sdbus = dependency('libsystemd', + required: false, + not_found_message: 'libsystemd not found, trying libelogind', + ) + if not sdbus.found() + sdbus = dependency('libelogind', + required: false, + ) + endif +else + sdbus = dependency(get_option('sd-bus-provider'), required: get_option('logind')) +endif + +logind_deps_found = sdbus.found() +if get_option('logind').enabled() and not logind_deps_found + error('Building with -Dlogind=enabled, but sd-bus has not been not found') +endif +have_logind = (not get_option('logind').disabled()) and logind_deps_found -if logind.found() - swayidle_deps += logind - conf_data.set10('HAVE_' + get_option('logind-provider').to_upper(), true) +if have_logind + swayidle_deps += sdbus endif +conf_data = configuration_data() + +conf_data.set10('HAVE_LIBSYSTEMD', sdbus.found() and sdbus.name() == 'libsystemd') +conf_data.set10('HAVE_LIBELOGIND', sdbus.found() and sdbus.name() == 'libelogind') +conf_data.set10('HAVE_LOGIND', have_logind) + configure_file(output: 'config.h', configuration: conf_data) executable( diff --git a/meson_options.txt b/meson_options.txt index d40de9cb..f96aba0e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,6 +1,6 @@ option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') option('logind', type: 'feature', value: 'auto', description: 'Enable support for logind') -option('logind-provider', type: 'combo', choices: ['systemd', 'elogind'], value: 'systemd', description: 'Provider of logind support library') +option('sd-bus-provider', type: 'combo', choices: ['auto', 'libsystemd', 'libelogind'], value: 'auto', description: 'Provider of the sd-bus library') option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.')