Skip to content

Document C++20 module usage with CMake - #4891

Open
way4sahil wants to merge 2 commits into
fmtlib:mainfrom
way4sahil:docs/4237-cxx20-modules
Open

Document C++20 module usage with CMake#4891
way4sahil wants to merge 2 commits into
fmtlib:mainfrom
way4sahil:docs/4237-cxx20-modules

Conversation

@way4sahil

Copy link
Copy Markdown

Adds CMake guidance for using {fmt} as a C++20 module.

  • Enable FMT_MODULE before adding {fmt} as a subdirectory
  • Link against fmt::fmt
  • Use import fmt; in consumer source files
  • Document the CMake 3.28+ and Ninja requirement for GCC module dependency scanning

Fixes #4237.

@way4sahil
way4sahil requested a review from vitaut as a code owner August 23, 2026 09:59
@way4sahil
way4sahil force-pushed the docs/4237-cxx20-modules branch from 305e02e to d0d9ada Compare August 23, 2026 10:04

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

The documented example can fail because fmt::fmt-module is only defined when FMT_MODULE is enabled. Could you mention that FMT_MODULE needs to be enabled before adding fmt (or otherwise ensure modules are enabled via CMAKE_CXX_STANDARD)? This is already mentioned in the PR description but not in the documentation itself.

Also, the GCC/CMake/Ninja versions listed here seem to be requirements for CMake’s native module support rather than for fmt::fmt-module in general, since fmt also has the fallback path.

Comment thread doc/get-started.md
import fmt;

int main() {
fmt::print("Hello, world!\\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is extra \ here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

What is the proper way to use fmt as a C++ 20 module?

2 participants