diff options
author | Jakob P. Liljenberg <admin@qvantnet.com> | 2024-02-11 16:39:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-11 16:39:59 +0100 |
commit | f1f37ad6af7e05b3a82133e55c4aa1381bef530c (patch) | |
tree | b490d32fe335c4f1d6756f6a0a9cae14a2fa89a1 | |
parent | 0bb1d4bf97297bf620441efea2bc0c6a55a892e7 (diff) | |
parent | 338aa72f6fb2beda1305bf524b9a450a0f6a3762 (diff) |
Merge branch 'main' into battery-power-2
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | README.md | 68 | ||||
-rw-r--r-- | cmake/Modules/Findkvm.cmake | 2 | ||||
-rw-r--r-- | src/btop.cpp | 1 | ||||
-rw-r--r-- | src/btop_draw.cpp | 5 | ||||
-rw-r--r-- | src/btop_tools.hpp | 8 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 2 |
8 files changed, 90 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cd39946..5039cdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,8 @@ if(APPLE) target_sources(btop PRIVATE src/osx/btop_collect.cpp src/osx/sensors.cpp src/osx/smc.cpp) elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") target_sources(btop PRIVATE src/freebsd/btop_collect.cpp) +elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") + target_sources(btop PRIVATE src/openbsd/btop_collect.cpp src/openbsd/sysctlbyname.cpp) elseif(LINUX) target_sources(btop PRIVATE src/linux/btop_collect.cpp) else() @@ -110,6 +112,7 @@ if(HAS_FCF_PROTECTION) endif() target_compile_definitions(btop PRIVATE + FMT_HEADER_ONLY _FILE_OFFSET_BITS=64 $<$<CONFIG:Debug>:_GLIBCXX_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS=1> # Only has an effect with optimizations enabled @@ -185,6 +188,12 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") find_package(kvm REQUIRED) target_link_libraries(btop elf::elf kvm::kvm) endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(btop PRIVATE -static-libstdc++) + endif() + find_package(kvm REQUIRED) + target_link_libraries(btop kvm::kvm) endif() install(TARGETS btop RUNTIME) @@ -143,7 +143,7 @@ else ifeq ($(PLATFORM_LC),macos) else ifeq ($(PLATFORM_LC),openbsd) PLATFORM_DIR := openbsd THREADS := $(shell sysctl -n hw.ncpu || echo 1) - override ADDFLAGS += -lkvm + override ADDFLAGS += -lkvm -static-libstdc++ export MAKE = gmake SU_GROUP := wheel else @@ -179,7 +179,7 @@ override GOODFLAGS := $(foreach flag,$(TESTFLAGS),$(strip $(shell echo "int main override REQFLAGS := -std=c++20 WARNFLAGS := -Wall -Wextra -pedantic OPTFLAGS := -O2 -ftree-vectorize -flto=$(LTO) -LDCXXFLAGS := -pthread -D_GLIBCXX_ASSERTIONS -D_FILE_OFFSET_BITS=64 $(GOODFLAGS) $(ADDFLAGS) +LDCXXFLAGS := -pthread -DFMT_HEADER_ONLY -D_GLIBCXX_ASSERTIONS -D_FILE_OFFSET_BITS=64 $(GOODFLAGS) $(ADDFLAGS) override CXXFLAGS += $(REQFLAGS) $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS) override LDFLAGS += $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS) INC := $(foreach incdir,$(INCDIRS),-isystem $(incdir)) -I$(SRCDIR) @@ -996,6 +996,74 @@ If you have an AMD GPU `rocm_smi_lib` is required, which may or may not be packa ``` </details> +<details> +<summary> + +### With CMake (Community maintained) +</summary> + +1. **Install build dependencies** + + Requires GCC, CMake, Ninja and Git + + _**Note:** LLVM's libc++ shipped with OpenBSD 7.4 is too old and cannot compile btop._ + + ```bash + pkg_add cmake g++%11 git ninja + ``` + +2. **Clone the repository** + + ```bash + git clone https://github.com/aristocratos/btop.git && cd btop + ``` + +3. **Compile** + + ```bash + # Configure + CXX=eg++ cmake -B build -G Ninja + # Build + cmake --build build + ``` + + This will automatically build a release version of btop. + + Some useful options to pass to the configure step: + + | Configure flag | Description | + |---------------------------------|-------------------------------------------------------------------------| + | `-DBTOP_LTO=<ON\|OFF>` | Enables link time optimization (ON by default) | + | `-DBTOP_USE_MOLD=<ON\|OFF>` | Use mold to link btop (OFF by default) | + | `-DBTOP_PEDANTIC=<ON\|OFF>` | Compile with additional warnings (OFF by default) | + | `-DBTOP_WERROR=<ON\|OFF>` | Compile with warnings as errors (OFF by default) | + | `-DBTOP_FORTIFY=<ON\|OFF>` | Detect buffer overflows with `_FORTIFY_SOURCE=3` (ON by default) | + | `-DCMAKE_INSTALL_PREFIX=<path>` | The installation prefix ('/usr/local' by default) | + + To force any other compiler, run `CXX=<compiler> cmake -B build -G Ninja` + +4. **Install** + + ```bash + cmake --install build + ``` + + May require root privileges + +5. **Uninstall** + + CMake doesn't generate an uninstall target by default. To remove installed files, run + ``` + cat build/install_manifest.txt | xargs rm -irv + ``` + +6. **Cleanup build directory** + + ```bash + cmake --build build -t clean + ``` + +</details> ## Installing the snap [![btop](https://snapcraft.io/btop/badge.svg)](https://snapcraft.io/btop) diff --git a/cmake/Modules/Findkvm.cmake b/cmake/Modules/Findkvm.cmake index a0847de..9e4d82b 100644 --- a/cmake/Modules/Findkvm.cmake +++ b/cmake/Modules/Findkvm.cmake @@ -3,7 +3,7 @@ # Find libkvm, the Kernel Data Access Library # -if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") +if(BSD) find_path(kvm_INCLUDE_DIR NAMES kvm.h) find_library(kvm_LIBRARY NAMES kvm) diff --git a/src/btop.cpp b/src/btop.cpp index 736854f..aac8e9c 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -53,6 +53,7 @@ tab-size = 4 #include "btop_draw.hpp" #include "btop_menu.hpp" #include "fmt/core.h" +#include "fmt/ostream.h" using std::atomic; using std::cout; diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index aebf145..bfd12ce 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -1364,6 +1364,7 @@ namespace Net { int x = 1, y, width = 20, height; int b_x, b_y, b_width, b_height, d_graph_height, u_graph_height; bool shown = true, redraw = true; + const int MAX_IFNAMSIZ = 15; string old_ip; std::unordered_map<string, Draw::Graph> graphs; string box; @@ -1384,7 +1385,7 @@ namespace Net { out.reserve(width * height); const string title_left = Theme::c("net_box") + Fx::ub + Symbols::title_left; const string title_right = Theme::c("net_box") + Fx::ub + Symbols::title_right; - const int i_size = min((int)selected_iface.size(), 10); + const int i_size = min((int)selected_iface.size(), MAX_IFNAMSIZ); const long long down_max = (net_auto ? safeVal(graph_max, "download"s) : ((long long)(Config::getI("net_download")) << 20) / 8); const long long up_max = (net_auto ? safeVal(graph_max, "upload"s) : ((long long)(Config::getI("net_upload")) << 20) / 8); @@ -1406,7 +1407,7 @@ namespace Net { //? Interface selector and buttons out += Mv::to(y, x+width - i_size - 9) + title_left + Fx::b + Theme::c("hi_fg") + "<b " + Theme::c("title") - + uresize(selected_iface, 10) + Theme::c("hi_fg") + " n>" + title_right + + uresize(selected_iface, MAX_IFNAMSIZ) + Theme::c("hi_fg") + " n>" + title_right + Mv::to(y, x+width - i_size - 15) + title_left + Theme::c("hi_fg") + (safeVal(net.stat, "download"s).offset + safeVal(net.stat, "upload"s).offset > 0 ? Fx::b : "") + 'z' + Theme::c("title") + "ero" + title_right; Input::mouse_mappings["b"] = {y, x+width - i_size - 8, 1, 3}; diff --git a/src/btop_tools.hpp b/src/btop_tools.hpp index 705a5eb..2502786 100644 --- a/src/btop_tools.hpp +++ b/src/btop_tools.hpp @@ -18,6 +18,10 @@ tab-size = 4 #pragma once +#if !defined(NDEBUG) +# define BTOP_DEBUG +#endif + #include <algorithm> // for std::ranges::count_if #include <array> #include <atomic> @@ -42,11 +46,9 @@ tab-size = 4 #define HOST_NAME_MAX 64 #endif #endif -#define FMT_HEADER_ONLY + #include "fmt/core.h" #include "fmt/format.h" -#include "fmt/ostream.h" -#include "fmt/ranges.h" using std::array; using std::atomic; diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 64f55f7..739d587 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -590,7 +590,7 @@ namespace Cpu { cpuhz += " GHz"; } else if (hz > 0) - cpuhz = to_string((int)round(hz)) + " MHz"; + cpuhz = to_string((int)hz) + " MHz"; } catch (const std::exception& e) { |