diff --git a/src/btop.cpp b/src/btop.cpp index 5d44ae995..a640ae598 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -534,7 +534,7 @@ namespace Runner { //* Run collection and draw functions for all boxes try { - #ifdef GPU_SUPPORT +#if defined(GPU_SUPPORT) //? GPU data collection const bool gpu_in_cpu_panel = Gpu::gpu_names.size() > 0 and ( Config::getS("cpu_graph_lower").starts_with("gpu-") @@ -555,9 +555,7 @@ namespace Runner { if (Global::debug) debug_timer("gpu", collect_done); } auto& gpus_ref = gpus; - #else - vector gpus_ref{}; - #endif +#endif // GPU_SUPPORT //? CPU if (v_contains(conf.boxes, "cpu")) { @@ -578,7 +576,16 @@ namespace Runner { if (Global::debug) debug_timer("cpu", draw_begin); //? Draw box - if (not pause_output) output += Cpu::draw(cpu, gpus_ref, conf.force_redraw, conf.no_update); + if (not pause_output) { + output += Cpu::draw( + cpu, +#if defined(GPU_SUPPORT) + gpus_ref, +#endif // GPU_SUPPORT + conf.force_redraw, + conf.no_update + ); + } if (Global::debug) debug_timer("cpu", draw_done); } diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index b85eea1ac..be34a1359 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -537,7 +537,14 @@ namespace Cpu { vector gpu_temp_graphs; vector gpu_mem_graphs; - string draw(const cpu_info& cpu, const vector& gpus, bool force_redraw, bool data_same) { + string draw( + const cpu_info& cpu, +#if defined(GPU_SUPPORT) + const vector& gpus, +#endif // GPU_SUPPORT + bool force_redraw, + bool data_same + ) { if (Runner::stopping) return ""; if (force_redraw) redraw = true; bool show_temps = (Config::getB("check_temp") and got_sensors); @@ -545,14 +552,12 @@ namespace Cpu { auto single_graph = Config::getB("cpu_single_graph"); bool hide_cores = show_temps and (cpu_temp_only or not Config::getB("show_coretemp")); const int extra_width = (hide_cores ? max(6, 6 * b_column_size) : (b_columns == 1 && !show_temps) ? 8 : 0); - #ifdef GPU_SUPPORT +#if defined(GPU_SUPPORT) const auto& show_gpu_info = Config::getS("show_gpu_info"); const bool gpu_always = show_gpu_info == "On"; const bool gpu_auto = show_gpu_info == "Auto"; const bool show_gpu = (gpus.size() > 0 and (gpu_always or (gpu_auto and Gpu::shown < Gpu::count))); - #else - (void)gpus; - #endif +#endif // GPU_SUPPORT auto graph_up_field = Config::getS("cpu_graph_upper"); if (graph_up_field == "Auto" or not v_contains(Cpu::available_fields, graph_up_field)) graph_up_field = "total"; diff --git a/src/btop_shared.hpp b/src/btop_shared.hpp index b3b1d019f..e382e42b6 100644 --- a/src/btop_shared.hpp +++ b/src/btop_shared.hpp @@ -104,9 +104,9 @@ namespace Shared { #endif } +#if defined(GPU_SUPPORT) namespace Gpu { -#ifdef GPU_SUPPORT extern vector box; extern int width, total_height, min_width, min_height; extern vector x_vec, y_vec; @@ -189,13 +189,10 @@ namespace Gpu { //* Draw contents of gpu box using as source string draw(const gpu_info& gpu, unsigned long index, bool force_redraw, bool data_same); -#else - struct gpu_info { - bool supported = false; - }; -#endif } +#endif // GPU_SUPPORT + namespace Cpu { extern string box; extern int x, y, width, height, min_width, min_height; @@ -232,7 +229,14 @@ namespace Cpu { auto collect(bool no_update = false) -> cpu_info&; //* Draw contents of cpu box using as source - string draw(const cpu_info& cpu, const vector& gpu, bool force_redraw = false, bool data_same = false); + string draw( + const cpu_info& cpu, +#if defined(GPU_SUPPORT) + const vector& gpu, +#endif + bool force_redraw = false, + bool data_same = false + ); //* Parse /proc/cpu info for mapping of core ids auto get_core_mapping() -> std::unordered_map; diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index c4ac5fc2f..60169f891 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -132,9 +132,10 @@ namespace Cpu { std::unordered_map core_mapping; } +#if defined(GPU_SUPPORT) + namespace Gpu { vector gpus; -#ifdef GPU_SUPPORT //? NVIDIA data collection namespace Nvml { //? NVML defines, structs & typedefs @@ -254,9 +255,10 @@ namespace Gpu { template bool collect(gpu_info* gpus_slice); uint32_t device_count = 0; } -#endif } +#endif // GPU_SUPPORT + namespace Mem { double old_uptime; }