Add Separate CMake Target for C++20 Modules (#4685)

* Add Separate CMake Target for C++20 Modules

In the same vein as there is the `fmt::fmt-header-only`, `fmt::fmt` and
`fmt::fmt_c` targets, I propose the addition of a new target
`fmt::fmt-module` which will be for the compilation of the FMT_MODULE
library option.

The new target will have the properties requried for Compiling,
Installing and using the C++20 functionality in CMake

The `add_module_library` function is marked as deprecated as its
functionality is superseded.

Updated the logic for setting the FMT_USE_CMAKE_MODULE flag to check the
versions for Ninja and MSVC according the CMAKE Documents and setting
the FMT_MODULE flag based on this

* Add Separate CMake Target for C++20 Modules

In the same vein as there is the `fmt::fmt-header-only`, `fmt::fmt` and
`fmt::fmt_c` targets, I propose the addition of a new target
`fmt::fmt-module` which will be for the compilation of the FMT_MODULE
library option.

The new target will have the properties requried for Compiling,
Installing and using the C++20 functionality in CMake

Updated the logic for setting the FMT_USE_CMAKE_MODULE flag to check the
versions for Ninja and MSVC according the CMAKE Documents and setting
the FMT_MODULE flag based on this

Fixed the test/CMakeLists.txt file which used the FMT_MODULE flag to
separate the module and non-module library testing, in particular
disableing the module version.

The module testing still needs to be fixed, but the expected behavior of
testing the non-modular version is working.

---------

Co-authored-by: Mathew Benson <mathew@benson.co.ke>
Co-authored-by: ClausKlein <claus.klein@arcormail.de>
This commit is contained in:
Mathew Benson
2026-03-02 20:11:31 +03:00
committed by GitHub
parent fca0445565
commit 4e1b170b44
4 changed files with 126 additions and 54 deletions
+10 -3
View File
@@ -8,9 +8,10 @@ with CMake, while the [Build Systems](#build-systems) section covers the rest.
## CMake
{fmt} provides two CMake targets: `fmt::fmt` for the compiled library and
`fmt::fmt-header-only` for the header-only library. It is recommended to use
the compiled library for improved build times.
{fmt} provides three CMake targets: `fmt::fmt` for the standard compiled library,
`fmt::fmt-module` for the C++ modules 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.
There are three primary ways to use {fmt} with CMake:
@@ -40,6 +41,12 @@ There are three primary ways to use {fmt} with CMake:
add_subdirectory(fmt)
target_link_libraries(<your-target> fmt::fmt)
### Alternative Targets
In order to use the header-only target or the module target, simply substitute the
`fmt::fmt` in the above steps with `fmt::fmt-header-only` or `fmt::fmt-module`
accordingly.
## Installation
### Debian/Ubuntu