Document C++20 module usage with CMake (#4891)

* Document C++20 module usage with CMake

* Added Change log

* Addressed review comments

---------

Co-authored-by: Sahil Sinha <sahil.sinha@stryker.com>
This commit is contained in:
way4sahil 2026-08-30 22:47:00 +05:30 committed by GitHub
parent f87405f21d
commit b039e624c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 4 deletions

View File

@ -15,6 +15,10 @@
`fmt::ostream_formatter`) and `fmt::streamed` from the C++20 module
(https://github.com/fmtlib/fmt/pull/4861). Thanks @avikivity.
- Documented how to use the C++20 module with CMake, including the
`fmt::fmt-module` target and compiler requirements
(https://github.com/fmtlib/fmt/issues/4237).
- Optimized 128-bit integer formatting by reducing the value to 64-bit
chunks instead of doing repeated 128-bit division, giving a ~5x speedup
on full-range values.

View File

@ -8,10 +8,11 @@ with CMake, while the [Build Systems](#build-systems) section covers the rest.
## CMake
{fmt} provides three CMake targets: `fmt::fmt` for the standard compiled library,
`fmt::fmt-module` for the C++ module library and `fmt::fmt-header-only` for the
header-only library. It is recommended to use the compiled library or the module
library for improved build times.
{fmt} provides CMake targets: `fmt::fmt` for the standard compiled library,
`fmt::fmt-header-only` for the header-only library, and optionally
`fmt::fmt-module` for the C++ module library when the `FMT_MODULE` option is
enabled. It is recommended to use the compiled library or the module library for
improved build times.
There are three primary ways to use {fmt} with CMake:
@ -47,6 +48,29 @@ In order to use the header-only target or the module target, simply substitute t
`fmt::fmt` in the above steps with `fmt::fmt-header-only` or `fmt::fmt-module`
accordingly.
### Using the C++20 Module
The `fmt::fmt-module` target is only available when the `FMT_MODULE` CMake
option is enabled. Enable it by passing `-DFMT_MODULE=ON` when configuring your
project before adding {fmt}, or set `CMAKE_CXX_STANDARD` to at least 20 before
adding {fmt} which will enable module support automatically when supported by
the toolchain.
Link your target to `fmt::fmt-module` and import `fmt` instead of including a
{fmt} header:
target_link_libraries(<your-target> PRIVATE fmt::fmt-module)
import fmt;
int main() {
fmt::print("Hello, world!\n");
}
When using CMake's native C++ module support, you need CMake 3.28 or newer,
Ninja 1.11 or newer (with the Ninja generator), and GCC 15 or newer (with GCC).
{fmt} also provides a fallback build path for other toolchains.
## Installation
### Debian/Ubuntu