From 8be67d500828a8d54abbd7c81579e4145955b1f2 Mon Sep 17 00:00:00 2001 From: Alexis Date: Mon, 20 Aug 2018 17:20:02 +0200 Subject: [PATCH] chore: optional deps --- include/factory.hpp | 6 ++++++ meson.build | 40 +++++++++++++++++++++++++++++++++++----- src/factory.cpp | 6 ++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/include/factory.hpp b/include/factory.hpp index 7ea8c2c..ce5627c 100644 --- a/include/factory.hpp +++ b/include/factory.hpp @@ -2,13 +2,19 @@ #include #include "modules/clock.hpp" +#ifdef HAVE_SWAY #include "modules/sway/workspaces.hpp" #include "modules/sway/window.hpp" +#endif #include "modules/battery.hpp" #include "modules/memory.hpp" #include "modules/cpu.hpp" +#ifdef HAVE_LIBNL #include "modules/network.hpp" +#endif +#ifdef HAVE_LIBPULSE #include "modules/pulseaudio.hpp" +#endif #include "modules/custom.hpp" namespace waybar { diff --git a/meson.build b/meson.build index b2e5501..43d6c03 100644 --- a/meson.build +++ b/meson.build @@ -31,14 +31,44 @@ wlroots = dependency('wlroots', fallback: ['wlroots', 'wlroots']) gtkmm = dependency('gtkmm-3.0') jsoncpp = dependency('jsoncpp') sigcpp = dependency('sigc++-2.0') -libnl = dependency('libnl-3.0') -libnlgen = dependency('libnl-genl-3.0') -libpulse = dependency('libpulse') +libnl = dependency('libnl-3.0', required: false) +libnlgen = dependency('libnl-genl-3.0', required: false) +libpulse = dependency('libpulse', required: false) + +src_files = files( + 'src/factory.cpp', + 'src/ALabel.cpp', + 'src/modules/memory.cpp', + 'src/modules/battery.cpp', + 'src/modules/clock.cpp', + 'src/modules/custom.cpp', + 'src/modules/cpu.cpp', + 'src/main.cpp', + 'src/bar.cpp', + 'src/client.cpp' +) + +if find_program('sway').found() + add_project_arguments('-DHAVE_SWAY', language: 'cpp') + src_files += [ + 'src/modules/sway/ipc/client.cpp', + 'src/modules/sway/window.cpp', + 'src/modules/sway/workspaces.cpp' + ] +endif + +if libnl.found() and libnlgen.found() + add_project_arguments('-DHAVE_LIBNL', language: 'cpp') + src_files += 'src/modules/network.cpp' +endif + +if libpulse.found() + add_project_arguments('-DHAVE_LIBPULSE', language: 'cpp') + src_files += 'src/modules/pulseaudio.cpp' +endif subdir('protocol') -src_files = run_command('find', './src', '-name', '*.cpp').stdout().strip().split('\n') - executable( 'waybar', src_files, diff --git a/src/factory.cpp b/src/factory.cpp index 1a190f2..ca35c0e 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -10,9 +10,11 @@ waybar::IModule* waybar::Factory::makeModule(const std::string &name) const if (name == "battery") { return new waybar::modules::Battery(config_[name]); } + #ifdef HAVE_SWAY if (name == "sway/workspaces") { return new waybar::modules::sway::Workspaces(bar_, config_[name]); } + #endif if (name == "sway/window") { return new waybar::modules::sway::Window(bar_, config_[name]); } @@ -25,12 +27,16 @@ waybar::IModule* waybar::Factory::makeModule(const std::string &name) const if (name == "clock") { return new waybar::modules::Clock(config_[name]); } + #ifdef HAVE_LIBNL if (name == "network") { return new waybar::modules::Network(config_[name]); } + #endif + #ifdef HAVE_LIBPULSE if (name == "pulseaudio") { return new waybar::modules::Pulseaudio(config_[name]); } + #endif if (name.compare(0, 7, "custom/") == 0 && name.size() > 7) { return new waybar::modules::Custom(name.substr(7), config_[name]); }