Add CMake option to disable XCHAR support

This is useful in some embedded scenarios where the libc's wchar_t
support is disabled.
This commit is contained in:
Itay Bookstein 2026-06-03 23:14:50 +03:00
parent 9afcd929ba
commit 3290cdd47b
3 changed files with 15 additions and 1 deletions

View File

@ -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 ()

View File

@ -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`

View File

@ -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
}