From 3290cdd47b0735b7375ff9f9c2e8ab415062e411 Mon Sep 17 00:00:00 2001 From: Itay Bookstein Date: Wed, 3 Jun 2026 23:14:50 +0300 Subject: [PATCH] Add CMake option to disable XCHAR support This is useful in some embedded scenarios where the libc's wchar_t support is disabled. --- CMakeLists.txt | 5 +++++ doc/api.md | 3 +++ src/fmt.cc | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1045f3ee..4b71f50d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,7 @@ option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT}) option(FMT_FUZZ "Generate the fuzz target." OFF) option(FMT_CUDA_TEST "Generate the cuda-test target." OFF) option(FMT_OS "Include OS-specific APIs." ON) +option(FMT_XCHAR "Include wchar_t and exotic character support" ON) option(FMT_MODULE "Build a module library." ${FMT_USE_CMAKE_MODULES}) option(FMT_SYSTEM_HEADERS "Expose headers with marking them as system." OFF) option(FMT_UNICODE "Enable Unicode support." ON) @@ -294,6 +295,10 @@ else () target_compile_definitions(fmt PRIVATE FMT_OS=0) endif () +if (NOT FMT_XCHAR) + target_compile_definitions(fmt PRIVATE FMT_XCHAR=0) +endif () + if (FMT_WERROR) target_compile_options(fmt PRIVATE ${WERROR_FLAG}) endif () diff --git a/doc/api.md b/doc/api.md index ff190383..f6a64303 100644 --- a/doc/api.md +++ b/doc/api.md @@ -725,6 +725,8 @@ configuring CMake. ### CMake Options - **`FMT_OS`**: When set to `OFF`, disables OS-specific APIs (`fmt/os.h`). +- **`FMT_XCHAR`**: When set to `OFF`, disables wchar_t and exotic character + support. - **`FMT_UNICODE`**: When set to `OFF`, disables Unicode support on Windows/MSVC. Unicode support is always enabled on other platforms. @@ -761,6 +763,7 @@ some features, you can use the following configuration: - CMake options: - `FMT_OS=OFF` + - `FMT_XCHAR=OFF` - Macros: - `FMT_BUILTIN_TYPES=0` - `FMT_OPTIMIZE_SIZE=2` diff --git a/src/fmt.cc b/src/fmt.cc index f319ce94..88374a29 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -121,6 +121,10 @@ extern "C++" { # define FMT_OS 1 #endif +#ifndef FMT_XCHAR +# define FMT_XCHAR 1 +#endif + // All library-provided declarations and definitions must be in the module // purview to be exported. #include "fmt/args.h" @@ -135,7 +139,9 @@ extern "C++" { #include "fmt/printf.h" #include "fmt/ranges.h" #include "fmt/std.h" -#include "fmt/xchar.h" +#if FMT_XCHAR +# include "fmt/xchar.h" +#endif #ifdef FMT_ATTACH_TO_GLOBAL_MODULE }