From cc9d9b3526e288939aa7c643509a573cdaf25f87 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Sat, 23 Sep 2023 05:20:23 +0200 Subject: [PATCH] meson option: with_spdlog --- disable_spdlog/spdlog/spdlog.h | 31 +++++++++++++++++++++++++++++++ meson.build | 26 ++++++++++++++++---------- meson_options.txt | 2 +- src/gl/gl_hud.cpp | 2 +- src/hud_elements.cpp | 2 +- src/meson.build | 3 --- src/overlay.cpp | 8 +++++++- 7 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 disable_spdlog/spdlog/spdlog.h diff --git a/disable_spdlog/spdlog/spdlog.h b/disable_spdlog/spdlog/spdlog.h new file mode 100644 index 00000000..57775065 --- /dev/null +++ b/disable_spdlog/spdlog/spdlog.h @@ -0,0 +1,31 @@ +// This header is a replacement for the real spdlog.h. +// In the case that we don't link with spdlog, we use this header instead +// allowing us to compile anyway + +#include +#ifdef SPDLOG_INFO + #undef SPDLOG_INFO +#endif +#define SPDLOG_INFO(...) + +#ifdef SPDLOG_DEBUG + #undef SPDLOG_DEBUG +#endif +#define SPDLOG_DEBUG(...) + +#ifdef SPDLOG_ERROR + #undef SPDLOG_ERROR +#endif +#define SPDLOG_ERROR(...) + +#ifdef SPDLOG_WARN + #undef SPDLOG_WARN +#endif +#define SPDLOG_WARN(...) + +#ifdef SPDLOG_TRACE + #undef SPDLOG_TRACE +#endif +#define SPDLOG_TRACE(...) + +#define SPDLOG_OFF \ No newline at end of file diff --git a/meson.build b/meson.build index 2050a8f3..f88c49fc 100644 --- a/meson.build +++ b/meson.build @@ -227,17 +227,23 @@ implot_dep = null_dep implot_lib = static_library('nulllib', []) endif -spdlog_dep = cpp.find_library('spdlog', required: get_option('use_system_spdlog')) -if not spdlog_dep.found() - spdlog_sp = subproject('spdlog', default_options: [ - 'default_library=static', - 'compile_library=true', - 'werror=false', - 'tests=false', - ]) - spdlog_dep = spdlog_sp.get_variable('spdlog_dep') +if get_option('with_spdlog').enabled() + pre_args += '-DSPDLOG' + spdlog_dep = cpp.find_library('spdlog', required: get_option('use_system_spdlog')) + if not spdlog_dep.found() + spdlog_sp = subproject('spdlog', default_options: [ + 'default_library=static', + 'compile_library=true', + 'werror=false', + 'tests=false', + ]) + spdlog_dep = spdlog_sp.get_variable('spdlog_dep') + else + spdlog_dep = dependency('spdlog', required: true) + endif else - spdlog_dep = dependency('spdlog', required: true) + inc_common += include_directories('disable_spdlog') + spdlog_dep = null_dep endif if ['windows', 'mingw'].contains(host_machine.system()) diff --git a/meson_options.txt b/meson_options.txt index a2551956..369b0a86 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -12,4 +12,4 @@ option('mangoapp', type: 'boolean', value : false) option('mangohudctl', type: 'boolean', value : false) option('mangoapp_layer', type: 'boolean', value : false) option('tests', type: 'feature', value: 'auto', description: 'Run tests') -option('with_notify', type: 'feature', value: 'enabled') +option('with_spdlog', type: 'feature', value: 'enabled') \ No newline at end of file diff --git a/src/gl/gl_hud.cpp b/src/gl/gl_hud.cpp index 3183fecc..df3d7702 100644 --- a/src/gl/gl_hud.cpp +++ b/src/gl/gl_hud.cpp @@ -117,7 +117,7 @@ void imgui_create(void *ctx, const gl_wsi plat) inited = true; if (!gladLoadGL()) - spdlog::error("Failed to initialize OpenGL context, crash incoming"); + SPDLOG_ERROR("Failed to initialize OpenGL context, crash incoming"); deviceName = (char*)glGetString(GL_RENDERER); // If we're running zink we want to rely on the vulkan loader for the hud instead. diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index ed3373ff..cc71bfb2 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -1364,7 +1364,7 @@ void HudElements::sort_elements(const std::pair& optio ordered_functions.push_back({graphs, value}); else { - spdlog::error("Unrecognized graph type: {}", value); + SPDLOG_ERROR("Unrecognized graph type: {}", value); } } } diff --git a/src/meson.build b/src/meson.build index 45fd3721..6572ea0a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -77,9 +77,6 @@ if is_unixy or cpp.get_id() == 'emscripten' if cpp.get_id() != 'emscripten' vklayer_files += 'real_dlsym.cpp' - endif - - if get_option('with_notify').enabled() vklayer_files += 'notify.cpp' endif diff --git a/src/overlay.cpp b/src/overlay.cpp index 36b1f8d5..9f6ae5c9 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -4,9 +4,12 @@ #include #include #include +// This will be set if we are not using the spdlog library +#ifndef SPDLOG_OFF #include #include #include +#endif #include // #include #include "overlay.h" @@ -55,6 +58,7 @@ int current_preset; void init_spdlog() { +#ifndef SPDLOG_OFF if (spdlog::get("MANGOHUD")) return; @@ -89,7 +93,7 @@ void init_spdlog() } } } - +#endif } void FpsLimiter(struct fps_limit& stats){ @@ -459,6 +463,7 @@ static float get_ticker_limited_pos(float pos, float tw, float& left_limit, floa #ifdef HAVE_DBUS void render_mpris_metadata(const struct overlay_params& params, mutexed_metadata& meta, uint64_t frame_timing) { +#ifndef SPDLOG_OFF static const float overflow = 50.f /* 3333ms * 0.5 / 16.6667 / 2 (to edge and back) */; if (meta.meta.valid) { @@ -519,6 +524,7 @@ void render_mpris_metadata(const struct overlay_params& params, mutexed_metadata //ImGui::PopFont(); ImGui::PopStyleVar(); } +#endif } #endif