From 5e214f0c437a84e5927fbb8ccb0399ac8c5694a2 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 Oct 2025 09:24:58 -0700 Subject: [PATCH 1/7] Cleanup docs --- doc/api.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/api.md b/doc/api.md index 3083ff0b..a7d1552c 100644 --- a/doc/api.md +++ b/doc/api.md @@ -709,15 +709,17 @@ following differences: (ignoring redundant digits and sign in exponent) and may procude more decimal digits than necessary. -## Compile-Time Configuration +## Configuration Options -{fmt} provides configuration via CMake options and preprocessor macros to enable or disable features and to optimize for binary size. You can set CMake options when generating your build system (e.g. `-DFMT_OS=OFF`) and define macros or pass them to your compiler (e.g. `-DFMT_USE_EXCEPTIONS=0`). +{fmt} provides configuration via CMake options and preprocessor macros to +enable or disable features and to optimize for binary size. For example, you +can disable platform-specific APIs defined in `fmt/os.h` with `-DFMT_OS=OFF` +when configuring CMake. ### Available Options | Option | Type | Default | Description | | -------------------- | ------------ | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| Header-Only Mode | CMake target | `fmt::fmt` | Enable header-only usage by linking the `fmt::fmt-header-only` target. | | `FMT_HEADER_ONLY` | 0 / 1 | 0 | Enables header-only mode when set to 1 (CMake target `fmt::fmt-header-only` defines it); disable with 0 for library mode. | | `FMT_OS` | ON / OFF | ON | Enables OS-specific APIs (`fmt/os.h`); disable with OFF. | | `FMT_UNICODE` | ON / OFF | ON | Enables Unicode support; disable with OFF. | @@ -729,7 +731,8 @@ following differences: ### Size Optimization Recipe -To minimize your binary footprint, use the following CMake configuration and compile definitions: +To minimize your binary footprint, use the following CMake configuration and +compile definitions: ```cmake # Link to the header-only target From c4f70ab69e124c2d06c29a535dbfdaf949df2d03 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 Oct 2025 09:34:46 -0700 Subject: [PATCH 2/7] Cleanup docs --- doc/api.md | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/doc/api.md b/doc/api.md index a7d1552c..804a7ca1 100644 --- a/doc/api.md +++ b/doc/api.md @@ -713,23 +713,47 @@ following differences: {fmt} provides configuration via CMake options and preprocessor macros to enable or disable features and to optimize for binary size. For example, you -can disable platform-specific APIs defined in `fmt/os.h` with `-DFMT_OS=OFF` -when configuring CMake. +can disable OS-specific APIs defined in `fmt/os.h` with `-DFMT_OS=OFF` when +configuring CMake. ### Available Options -| Option | Type | Default | Description | -| -------------------- | ------------ | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| `FMT_HEADER_ONLY` | 0 / 1 | 0 | Enables header-only mode when set to 1 (CMake target `fmt::fmt-header-only` defines it); disable with 0 for library mode. | -| `FMT_OS` | ON / OFF | ON | Enables OS-specific APIs (`fmt/os.h`); disable with OFF. | -| `FMT_UNICODE` | ON / OFF | ON | Enables Unicode support; disable with OFF. | -| `FMT_USE_EXCEPTIONS` | 0 / 1 | 1 (0 if compiled with `-fno-exceptions`) | Enables exception-based error handling; disable with 0. | -| `FMT_BUILTIN_TYPES` | 0 / 1 | 1 | Enables built-in type formatters; disable with 0. | -| `FMT_OPTIMIZE_SIZE` | 0 / 1 / 2 | 0 | Controls size-optimized routines: 0 = off, 1 = size optimization, >1 = aggressive size optimization disabling format-string checks. | -| `FMT_USE_LOCALE` | 0 / 1 | 1 (0 when `FMT_OPTIMIZE_SIZE > 1`) | Enables locale-dependent formatting; disable with 0. | -| `FMT_THROW(x)` | macro | `throw x` (or `abort`) | Defines error handling via macro (not a toggle flag): if exceptions enabled, `throw x`; otherwise, `fmt::assert_fail(...)`. | +- **`FMT_HEADER_ONLY`** + Default: `0` + Enables header-only mode when set to `1` (CMake target `fmt::fmt-header-only` + defines it); disable with `0` for library mode. -### Size Optimization Recipe +- **`FMT_OS`** + Default: `ON` + Enables OS-specific APIs (`fmt/os.h`); disable with `OFF`. + +- **`FMT_UNICODE`** + Default: `ON` + Enables Unicode support; disable with `OFF`. + +- **`FMT_USE_EXCEPTIONS`** + Default: `1` (`0` if compiled with `-fno-exceptions`) + Enables exception-based error handling; disable with `0`. + +- **`FMT_BUILTIN_TYPES`** + Default: `1` + Enables built-in type formatters; disable with `0`. + +- **`FMT_OPTIMIZE_SIZE`** + Default: `0` + Controls size-optimized routines: `0` = off, `1` = size optimization, `>1` = + aggressive size optimization disabling format-string checks. + +- **`FMT_USE_LOCALE`** + Default: `1` (`0` when `FMT_OPTIMIZE_SIZE > 1`) + Enables locale-dependent formatting; disable with `0`. + +- **`FMT_THROW(x)`** + Default: ``throw x`` (or `abort`) + Defines error handling via macro (not a toggle flag): if exceptions enabled, + `throw x`; otherwise, `fmt::assert_fail(...)`. + +### Binary Size Optimization To minimize your binary footprint, use the following CMake configuration and compile definitions: From 41326207c7a270e098c32585c84cd93cd32a5acb Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 Oct 2025 10:18:45 -0700 Subject: [PATCH 3/7] Cleanup docs --- doc/api.md | 78 +++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 48 deletions(-) diff --git a/doc/api.md b/doc/api.md index 804a7ca1..b2e44f16 100644 --- a/doc/api.md +++ b/doc/api.md @@ -716,63 +716,45 @@ enable or disable features and to optimize for binary size. For example, you can disable OS-specific APIs defined in `fmt/os.h` with `-DFMT_OS=OFF` when configuring CMake. -### Available Options +### CMake Options -- **`FMT_HEADER_ONLY`** - Default: `0` - Enables header-only mode when set to `1` (CMake target `fmt::fmt-header-only` - defines it); disable with `0` for library mode. +- **`FMT_OS`**: When set to `OFF`, disables OS-specific APIs (`fmt/os.h`). +- **`FMT_UNICODE`**: When set of `OFF`, disables Unicode support on + Windows/MSVC. Unicode support is always enabled on other platforms. -- **`FMT_OS`** - Default: `ON` - Enables OS-specific APIs (`fmt/os.h`); disable with `OFF`. +### Macros -- **`FMT_UNICODE`** - Default: `ON` - Enables Unicode support; disable with `OFF`. +- **`FMT_HEADER_ONLY`**: Enables the header-only mode when set to `1` as an + alternative to using the `fmt::fmt-header-only` CMake target. Default: `0`. -- **`FMT_USE_EXCEPTIONS`** - Default: `1` (`0` if compiled with `-fno-exceptions`) - Enables exception-based error handling; disable with `0`. +- **`FMT_USE_EXCEPTIONS`**: Disables the use of exceptions when set to `0`. + Default: `1` (`0` if compiled with `-fno-exceptions`). -- **`FMT_BUILTIN_TYPES`** - Default: `1` - Enables built-in type formatters; disable with `0`. +- **`FMT_USE_LOCALE`**: When set to `0`, disables locale support. + Default: `1` (`0` when `FMT_OPTIMIZE_SIZE > 1`). -- **`FMT_OPTIMIZE_SIZE`** - Default: `0` - Controls size-optimized routines: `0` = off, `1` = size optimization, `>1` = - aggressive size optimization disabling format-string checks. +- **`FMT_CUSTOM_ASSERT_FAIL`**: When set to `1`, allows users to provide a + custom `fmt::assert_fail` function which is called on assertion failures and, + if exceptions are disabled, on runtime errors. Default: `0`. -- **`FMT_USE_LOCALE`** - Default: `1` (`0` when `FMT_OPTIMIZE_SIZE > 1`) - Enables locale-dependent formatting; disable with `0`. +- **`FMT_BUILTIN_TYPES`**: When set to `0`, disables built-in handling of + arithmetic and string types other than `int`. This reduces library size at + the cost of per-call overhead. Default: `1`. -- **`FMT_THROW(x)`** - Default: ``throw x`` (or `abort`) - Defines error handling via macro (not a toggle flag): if exceptions enabled, - `throw x`; otherwise, `fmt::assert_fail(...)`. +- **`FMT_OPTIMIZE_SIZE`**: Controls binary size optimizations: + - `0` - off (default) + - `1` - disables locale support and applies some optimizations + - `2` - disables some Unicode features, named arguments and applies more + aggresive optimizations ### Binary Size Optimization -To minimize your binary footprint, use the following CMake configuration and -compile definitions: +To minimize the binary footprint of {fmt} as much as possible at the cost of +some features, you can use the following configuration: -```cmake -# Link to the header-only target -target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt-header-only) -# Disable OS-specific APIs -set(FMT_OS OFF CACHE BOOL "" FORCE) -# Disable Unicode support -set(FMT_UNICODE OFF CACHE BOOL "" FORCE) -# Add compile definitions to your target -target_compile_definitions( - ${PROJECT_NAME} - PRIVATE - FMT_USE_EXCEPTIONS=0 - FMT_OS=0 - FMT_BUILTIN_TYPES=0 - FMT_OPTIMIZE_SIZE=2 - FMT_USE_LOCALE=0 -) -``` +- CMake options: + - `FMT_OS=OFF` +- Macros: + - `FMT_USE_EXCEPTIONS=0` + - `FMT_BUILTIN_TYPES=0` + - `FMT_OPTIMIZE_SIZE=2` From 491dc16a6d068a0a1384f1dfd48858933a9ec2d6 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 Oct 2025 10:33:05 -0700 Subject: [PATCH 4/7] Cleanup docs --- doc/api.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/api.md b/doc/api.md index b2e44f16..8eca209c 100644 --- a/doc/api.md +++ b/doc/api.md @@ -742,10 +742,10 @@ configuring CMake. the cost of per-call overhead. Default: `1`. - **`FMT_OPTIMIZE_SIZE`**: Controls binary size optimizations: - - `0` - off (default) - - `1` - disables locale support and applies some optimizations - - `2` - disables some Unicode features, named arguments and applies more - aggresive optimizations + - `0` - off (default) + - `1` - disables locale support and applies some optimizations + - `2` - disables some Unicode features, named arguments and applies more + aggresive optimizations ### Binary Size Optimization @@ -753,8 +753,8 @@ To minimize the binary footprint of {fmt} as much as possible at the cost of some features, you can use the following configuration: - CMake options: - - `FMT_OS=OFF` + - `FMT_OS=OFF` - Macros: - - `FMT_USE_EXCEPTIONS=0` - - `FMT_BUILTIN_TYPES=0` - - `FMT_OPTIMIZE_SIZE=2` + - `FMT_USE_EXCEPTIONS=0` + - `FMT_BUILTIN_TYPES=0` + - `FMT_OPTIMIZE_SIZE=2` From 81fe170849494f7edc61b42931d821a71d1a49fa Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 Oct 2025 10:42:12 -0700 Subject: [PATCH 5/7] Update docs --- doc/api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api.md b/doc/api.md index 8eca209c..be5ac2ad 100644 --- a/doc/api.md +++ b/doc/api.md @@ -724,8 +724,9 @@ configuring CMake. ### Macros -- **`FMT_HEADER_ONLY`**: Enables the header-only mode when set to `1` as an - alternative to using the `fmt::fmt-header-only` CMake target. Default: `0`. +- **`FMT_HEADER_ONLY`**: Enables the header-only mode when defined. Defining + this macro is an alternative to using the `fmt::fmt-header-only` CMake target. + Default: not defined. - **`FMT_USE_EXCEPTIONS`**: Disables the use of exceptions when set to `0`. Default: `1` (`0` if compiled with `-fno-exceptions`). @@ -755,6 +756,5 @@ some features, you can use the following configuration: - CMake options: - `FMT_OS=OFF` - Macros: - - `FMT_USE_EXCEPTIONS=0` - `FMT_BUILTIN_TYPES=0` - `FMT_OPTIMIZE_SIZE=2` From beefc1c14f742912f3f2d433f088c40d3a18736c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 Oct 2025 10:54:28 -0700 Subject: [PATCH 6/7] Tweak wording --- doc/api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api.md b/doc/api.md index be5ac2ad..9fbc9f2f 100644 --- a/doc/api.md +++ b/doc/api.md @@ -724,8 +724,8 @@ configuring CMake. ### Macros -- **`FMT_HEADER_ONLY`**: Enables the header-only mode when defined. Defining - this macro is an alternative to using the `fmt::fmt-header-only` CMake target. +- **`FMT_HEADER_ONLY`**: Enables the header-only mode when defined. It is an + alternative to using the `fmt::fmt-header-only` CMake target. Default: not defined. - **`FMT_USE_EXCEPTIONS`**: Disables the use of exceptions when set to `0`. From 8eebb4334bbf102b2e79e8c011c68c4fac124b08 Mon Sep 17 00:00:00 2001 From: LiangHu <32604055+LiangHuDream@users.noreply.github.com> Date: Mon, 13 Oct 2025 01:56:13 +0800 Subject: [PATCH 7/7] =?UTF-8?q?[fix]=20#4565=20When=20using=20MSVC=20to=20?= =?UTF-8?q?compile=20v12.0.0,=20many=20compilation=20warn=E2=80=A6=20(#457?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fmt/format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index a10470f2..5333eb51 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2507,7 +2507,7 @@ FMT_CONSTEXPR20 auto write_fixed(OutputIt out, const DecimalFP& f, auto grouping = Grouping(loc, specs.localized()); size += grouping.count_separators(exp); return write_padded( - out, specs, to_unsigned(size), [&](iterator it) { + out, specs, static_cast(size), [&](iterator it) { if (s != sign::none) *it++ = detail::getsign(s); it = write_significand(it, f.significand, significand_size, f.exponent, grouping);