372 Commits

Author SHA1 Message Date
Avi Kivity
e27cc20bd9
Format enums annotated with fmt::as_identifiers (requires C++26 reflection) (#4885)
* Format enums annotated with fmt::as_identifiers (requires C++26 reflection)

Format an enum as the identifier of the matching enumerator if the enum is
annotated with fmt::as_identifiers:

  enum class [[=fmt::as_identifiers]] color { red, green, blue };
  fmt::format("{}", color::green);  // "green"

Values that don't match any enumerator are represented as their underlying
value in decimal before applying string formatting.

Identifiers are retrieved via C++26 reflection (P2996) and the annotation
via P3394. FMT_USE_REFLECTION is autodetected and can be overridden by the
user; without reflection the header is empty.

The header is also part of the fmt module, but, unlike with headers, whether
it provides anything is decided when the module is compiled, so the module
build detects reflection and enables it if the configured standard allows.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Look up enum identifiers by index when the values are dense

The formatter for enums annotated with fmt::as_identifiers did a linear
search over all enumerators. Build a table indexed by the distance from
the smallest enumerator value instead, with empty string views in the
holes, which reduces the lookup to a bounds check and one load.

The table is only used if at least 70% of its elements are identifiers,
limiting its size to 10/7 of the number of enumerators. Sparser enums
keep using the linear search. Distances are computed in uint64_t so that
enums with negative values and values spanning the whole range of the
underlying type are handled without overflow.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Suppress -Wsfinae-incomplete in format-test on GCC 16

GCC 16 warns when a type is completed after it failed to be complete in a
SFINAE context. format-test does this deliberately to check that formatting
of incomplete types works, so the warning is a false positive there and
breaks the build with -Werror.

* Test GCC 16 on CI

GCC 16 is the first compiler with C++26 reflection support, which is needed
by fmt/enum.h, so add a job that builds with it in C++26 mode. It comes from
the ubuntu-toolchain-r/test PPA since Ubuntu 24.04 only ships GCC 14.

Also report when reflection is not detected to make it visible that
enum-test was skipped.

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 09:31:28 -07:00
Ferdinand Bachmann
488c3b9628
Add pkgconfig file for fmt-c library (#4887) 2026-08-23 07:50:04 -07:00
illusiony
a245c6de99
Write run-msbuild.bat to bindir (#4875) 2026-08-03 09:17:14 -07:00
Aaron Gokaslan
c0330b7466
Do not optin into CPP modules without SCAN_DEPS on Clang (#4867) 2026-07-29 11:08:57 -07:00
Victor Zverovich
4e5ff510f8 Simplify build-tree export and rename INSTALL_TARGETS
Rename INSTALL_TARGETS to FMT_TARGETS since the list is now used for both
installation and the build-tree export, and move INSTALL_FILE_SET into the
FMT_INSTALL block as only install(TARGETS) uses it.

Replace the export-test static library and export-lib.cc with an INTERFACE
library, which reproduces the same CMake export dependency check (#4806).
2026-07-22 11:24:25 -07:00
hexonal
a749e9d880
Generate CMake export set regardless of FMT_INSTALL (#4850)
export() was scoped inside if (FMT_INSTALL), so projects that pull in
fmt via add_subdirectory()/FetchContent without installing it had no
way to get the exported fmt::* targets. If such a project tries to
export its own targets that depend on fmt, CMake fails with "target
... requires target fmt that is not in any export set".

Hoist the target list/export name and the export() call itself out of
the FMT_INSTALL guard so the build-tree export file is always
generated; the install()-only pieces (config/version files, pkgconfig,
install(EXPORT ...)) stay behind the guard and installed behavior is
unchanged.

Fixes #4806

Co-authored-by: flink <w741069229@gmail.com>
2026-07-20 15:09:34 -07:00
Soumik15630m
81516a20d9
Skip VERSION/SOVERSION/DEBUG_POSTFIX on the header-only INTERFACE target (#4830)
* Skip VERSION/SOVERSION/DEBUG_POSTFIX on the header-only INTERFACE target

* Lint check fixed
2026-06-28 08:38:06 -07:00
Jan Engelhardt
719823cc64
Turn libfmt-c into a shared library (#4812)
Linux distros don't like having static archives. Set fmt-c to shared
just like the main fmt library.
2026-06-26 06:55:44 -07:00
Victor Zverovich
5ea06b13fe Exclude the build tree from the source package
The .gitignore-derived `build/` pattern does not actually prune the build
directory or its contents from the CPack source package, so an empty build/
(and, once docs were built in CI, build/doc-html) leaked into the zip. Ignore
the whole build tree in CPACK_SOURCE_IGNORE_FILES.
2026-06-16 07:04:03 +02:00
Victor Zverovich
7aabdcf0ba Workaround apt-add-repository timeouts 2026-05-03 07:25:47 -07:00
Victor Zverovich
879463ecad Apply cmake-format 2026-03-14 14:24:09 -07:00
Victor Chernyakin
245e4d9723
Clean up a couple of CMake includes (#4710)
CMakeParseArguments is a no-op since CMake 3.5 and the
minimum version {fmt} supports is 3.8:
    https://cmake.org/cmake/help/latest/module/CMakeParseArguments.html

GNUInstallDirs is already unconditionally included
earlier in the file.
2026-03-11 06:32:04 -07:00
Mathew Benson
2b4eb7df47
Update Check for module support to include compiler versions (#4709)
- We need to confirm compiler support for module scanning before
  creating the CXX_MODULE FILE_SET using the `target_sources` command
- This is especially relevant for compilers that have module support but
  do not support the module scanning such as g++13, clang15. For these
    we can use the older way of creating the fmt-module target

Co-authored-by: Mathew Benson <mathew@benson.co.ke>
2026-03-09 15:37:46 -07:00
Ferdinand Bachmann
e2bf61cdf8
Fix fmt-c.h not being installed with fmt-c library (#4694)
Signed-off-by: Ferdinand Bachmann <ferdinand.bachmann@yrlf.at>
2026-03-03 16:43:53 -08:00
Victor Zverovich
e090e3ffad Apply cmake-format 2026-03-03 15:49:40 -08:00
Victor Zverovich
011b24123b Cleanup module test 2026-03-03 12:30:54 -08:00
Victor Zverovich
43d4810ba9 Cleanup CMake config more 2026-03-03 11:40:10 -08:00
Victor Zverovich
e3a149f23c Cleanup CMake config 2026-03-03 09:51:56 -08:00
Mathew Benson
4e1b170b44
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>
2026-03-02 09:11:31 -08:00
Victor Zverovich
dc97113ca1 Cleanup the C API 2026-02-21 17:15:19 -08:00
Soumik15630m
1dc644e021
Add C11 API with type-safe formatting (#4663) (#4671) 2026-02-16 07:06:32 -08:00
torsten48
f99d530247
Add include_guard (GLOBAL) to allow usage in multiple submodules (#4672) 2026-02-08 10:36:43 -08:00
crueter
da97ba2914
[cmake] fix MASTER_PROJECT heuristic; only enable install if master project (#4536)
SOURCE vs CURRENT_SOURCE is unreliable. `DEFINED PROJECT_NAME` is a much more portable way of determination.

Also, installation shouldn't default to on if it is a subproject.
2025-09-10 11:01:25 -07:00
autoantwort
a0ecfe3e1c
msvc + ninja + modules: Fix build when consuming fmtlib while using a Ninja generator (#4495)
Co-authored-by: Leander Schulten <Leander.Schulten@tetys.de>
2025-07-13 10:28:00 -07:00
n-stein
55a8f6a4be
Change component prefix for NSIS compatibility (#4442) 2025-05-09 12:09:18 -07:00
rlalik
2d0518b5f7
Fix cmake error in pedantic mode (#4426)
Suppresses error:
CMake Error (dev) at build/coverage/_deps/fmt-src/CMakeLists.txt:208 (set):
  uninitialized variable 'CMAKE_MODULE_PATH'
This error is for project developers. Use -Wno-error=dev to suppress it.
2025-04-24 11:41:33 -07:00
Thomas Khyn
ed27df5760
Replace forward slashes by backslashes in BMI path for MSVC. (#4344)
* Fix slashes in BMI path for MSVC builds
* Fix BMI path for MSVC builds when building with Ninja generator
2025-02-10 00:18:33 -08:00
Rafał Lalik
01a5b56f0d Fix error of unitialized variable FMT_HEADERS
This happens when using e.g. pedantic mode in cmake-init.
2025-01-25 08:41:49 -08:00
Victor Zverovich
c43da35701 Workaround an ICE when using modules with gcc 14.2 and earlier 2025-01-12 08:57:43 -08:00
Victor Zverovich
d57040f949 Prefix components 2025-01-10 19:51:55 -08:00
Carl Smedstad
5fa4bdd758
Define CMake components to allow docs to be installed separately (#4276)
Define two components, core and doc, which can be installed separately.
This facilitates packagers who want to package docs in a separate
package.

After this change it's possible to install only core files with:

     cmake --install build --component core

And only install documentation with:

     cmake --install build --component doc

When no component is specified, the behaviour is unchanged, i.e. if
documentation was built, it will be installed.
2024-12-26 07:13:01 -08:00
Amin Yahyaabadi
f924d16e47 fix: pass /utf-8 only if the compiler is MSVC at build time 2024-09-11 08:21:07 -07:00
Vladislav Shchapov
6870e4b06b Workaround for GCC regression: false positive null-dereference in vector.resize
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2024-09-05 09:40:55 -07:00
cdzhan
fb07b37c5b
Prioritize using the header files of self (#4116) 2024-08-13 10:50:49 -07:00
Victor Zverovich
e50c8b6bd8 Fix disabling Unicode support 2024-07-04 07:27:22 -07:00
Victor Zverovich
6f68c62cb5 Ignore doxygen files 2024-06-30 08:42:34 -07:00
Victor Zverovich
d059fe42a8 Ignore vagrant files 2024-06-30 08:33:37 -07:00
Victor Zverovich
43c5b34749 Fix package build 2024-06-30 08:23:25 -07:00
Victor Zverovich
0fae326c42 Update site dir 2024-06-29 08:32:24 -07:00
Victor Zverovich
8b1fcf5cc1 Update doc dir 2024-06-29 08:18:24 -07:00
Victor Zverovich
98dd673cf8 Cleanup cmake 2024-06-14 08:04:11 -07:00
LoveSy
c4ea903250
Only install FILE_SET when needed (#4013) 2024-06-13 12:17:46 -07:00
ChristianGebhardt
077e4ae746
Added generator expression to /utf-8 compile option (#3995)
Do not pass the compile options in the project to other compilers such as nvcc
2024-06-09 13:05:17 -07:00
Victor Zverovich
b5c8fd783c Fix doc build 2024-06-09 11:37:18 -07:00
Victor Zverovich
e6d4f927cc Improve docs 2024-06-09 11:17:32 -07:00
Victor Zverovich
8de3e87da1 Add a CMake option to control Unicode support 2024-06-09 11:16:13 -07:00
LoveSy
46d2acb3ba
Don't add os.cc to sources with FMT_MODULE (#4004)
It will be included by `fmt.cc`
2024-06-09 11:00:12 -07:00
LoveSy
0f6e716548
Fix missing includes in fmt.cc (#3994)
This causes duplicated std definitions in the fmt module
2024-06-08 13:50:29 -07:00
Victor Zverovich
21372bc0b2 Update cmake config 2024-06-08 08:21:18 -07:00
LoveSy
fcc0b49978
Fix FMT_INSTALL with FMT_MODULE (#3998) 2024-06-08 07:26:53 -07:00