From 896fe604610594f0947c403154bce0840c616cc1 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 28 May 2026 14:47:09 +0800 Subject: [PATCH] CMake: adds option `FF_ENABLE_WCWIDTH` --- CMakeLists.txt | 8 +++++++- src/common/wcwidth.h | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fae683a6..7aa83d306 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,7 @@ option(ENABLE_WORDEXP "Enable using of wordexp(3) if available, instead of glob( option(ENABLE_LUA "Enable lua scripting for format strings" ON) option(ENABLE_QUICKJS "Enable quickjs scripting for format strings" ON) option(ENABLE_LIBZFS "Enable libzfs" ON) +option(ENABLE_WCWIDTH "Detect wide-width characters with wcwidth when calculating logo and separator width. Disable for a smaller and slightly faster build, but logos containing CJK/emoji may be measured too narrow and render incorrectly. Such usecases are uncommon." ON) if(WIN32 AND NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") option(ENABLE_WIN81_COMPAT "Enable legacy Windows compatibility (Windows 8.1 and later; Windows 7 unsupported)" ON) endif() @@ -409,7 +410,6 @@ set(LIBFASTFETCH_SRC src/common/impl/path.c src/common/impl/FFPlatform.c src/common/impl/smbios.c - src/common/impl/wcwidth.c src/detection/bluetoothradio/bluetoothradio.c src/detection/bootmgr/bootmgr.c src/detection/chassis/chassis.c @@ -1363,6 +1363,9 @@ check_function_exists(memrchr HAVE_MEMRCHR) if(NOT HAVE_MEMRCHR) list(APPEND LIBFASTFETCH_SRC src/common/impl/memrchr.c) endif() +if(ENABLE_WCWIDTH) + list(APPEND LIBFASTFETCH_SRC src/common/impl/wcwidth.c) +endif() if(ENABLE_SYSTEM_YYJSON) find_package(yyjson) @@ -1766,6 +1769,9 @@ if(ENABLE_LIBZFS) ) endif() endif() +if(ENABLE_WCWIDTH) + target_compile_definitions(libfastfetch PRIVATE FF_ENABLE_WCWIDTH=1) +endif() if(NOT HAVE_MEMRCHR) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_CUSTOM_MEMRCHR=1) endif() diff --git a/src/common/wcwidth.h b/src/common/wcwidth.h index 7d4cbdbd5..8d093da52 100644 --- a/src/common/wcwidth.h +++ b/src/common/wcwidth.h @@ -2,4 +2,11 @@ #include +#if FF_ENABLE_WCWIDTH int mk_wcwidth(uint32_t wc); +#else +static inline int mk_wcwidth(uint32_t wc) { + (void) wc; + return 1; +} +#endif