Skip to content

Judge CMake code: formatted (gersemi, cmake-format) and linted (cmake-lint, cmakelint) - #378

Open
leftibot wants to merge 2 commits into
cpp-best-practices:mainfrom
leftibot:cmake-format
Open

leftibot wants to merge 2 commits into
cpp-best-practices:mainfrom
leftibot:cmake-format

Conversation

@leftibot

@leftibot leftibot commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

CMake code (CMakeLists.txt, *.cmake) is now judged: formatted and linted, as a format of its own beside the language it builds.

Until now, CMake was read only as a build system. Its flags, targets, presets and build types fed the C and C++ checks, but the CMake code itself was asked nothing. So fmt's cmake-format job was invisible, and a project that never formats or lints its CMake wasn't told.

What is judged

A new CMake profile, a format (as Docker's is):

  • Recognition: CMakeLists.txt and *.cmake. The C profile no longer accounts for .cmake files itself.
  • code-formatting:
    • gersemi: --check or --diff, with its style in .gersemirc;
    • cmake-format: --check, with its style in .cmake-format.yaml (or .cmake-format, .yml, .json, .py);
    • -i alone enforces nothing, unless a later step fails on the diff;
    • their pre-commit hooks count where CI runs them.
  • static-analysis: cmake-lint (cmakelang, configured as cmake-format is) or cmakelint (.cmakelintrc).
  • warnings-as-errors: CMake's own warnings about the project's code (deprecated commands, policy warnings) must fail CI. That means cmake -Werror=dev on a configure line in CI, or a configure preset's "errors": {"dev": true} in CMakePresets.json. Without either, it FAILs. This is deliberately strict for now and can be revisited.
  • Auxiliary CMake: CMake only in tooling or test code (Arcade's eng/common/cross/toolchain.cmake) is auxiliary under A language present only in auxiliary files (fixtures, tooling, docs assets, editor dotfiles) becomes a product ecosystem and its FAILs decide the project #182, so it warns.

Reading CMake as the C/C++ build system is unchanged.

Tests

  • Layout helpers: the C and C++ check tests are about their languages. The layout helpers now leave out of the compared result the formats a run's layouts bring through their own files, such as a CMake layout's CMakeLists.txt. The layout model already describes a layout's formats as "those the layout is about".
  • Fixtures: the C, C++ and Fortran well-configured fixtures run gersemi --check and cmake-lint. The C and C++ ones configure with -Werror=dev, and the Fortran one uses a preset with "errors": {"dev": true}. New bare and well-configured CMake fixtures, a layout, and a docs page are added.
  • The profile's own tests: they cover recognition, each formatter's check and apply forms, the hooks, both linters, and a C++ project's CMake judged beside its C++. Each was checked against a mutant of the profile, and every mutant was caught.
  • Corpus: fmt and cmake_template stand for CMake.

Corpus

19 of the 235 projects have CMake code:

  • Formatting it: fmt, with cmake-format. No project lints it.
  • Auxiliary only: four keep it only in tooling or test code (dotnet/command-line-api, bat, hledger, treefmt-nix), so it only warns.
  • Neither formatting nor linting it: the other fourteen, including Catch2, googletest, glfw, llama.cpp, nlohmann/json, simdjson, neovim and cmake_template. cmake_template has a .cmake-format.yaml that CI never runs.

Formatting and linting change only two overall statuses, because those projects already failed these checks for other reasons.

No corpus project configures with -Werror=dev. So warnings-as-errors now FAILs for five projects whose C/C++ warnings had been enough: cmake_template and glfw (from PASS), and fmt, googletest and uber/h3 (from WARN). The other CMake projects already failed it. No other check changes.

Gates

pytest, ruff, ruff format, mypy, lizard, coverage, jscpd and strict self-validation: all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

CMake was read only as a build system: its flags, targets and presets fed the C and C++ checks,
but the CMake code itself (CMakeLists.txt, *.cmake) was asked nothing, so fmt's and
cmake_template's CMake formatting jobs were invisible, and a project that never formats or
lints its CMake was not told.

CMake code is now a format of its own (a CMake profile), recognised by `CMakeLists.txt` and
`*.cmake` and judged beside the language it builds, as Dockerfiles are:
- code-formatting: gersemi (`--check`, `--diff`; `.gersemirc`) or cmake-format (`--check`;
  `.cmake-format.yaml` and its other names); `-i` alone enforces nothing, and their pre-commit
  hooks count where CI runs them;
- static-analysis: cmake-lint (cmakelang) or cmakelint (`.cmakelintrc`).
The C profile no longer accounts for `.cmake` files itself.

Every CMake project now has a CMake place in those two checks. The tests of the C and C++
checks are about their languages: a layout's results leave out the formats its own files
bring (a CMake layout's CMakeLists.txt), as the layout model already says. The C, C++ and
Fortran well-configured fixtures format and lint their CMake; fmt and cmake_template stand
for CMake in the corpus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.53%. Comparing base (ce8e13c) to head (1750079).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #378   +/-   ##
=======================================
  Coverage   99.53%   99.53%           
=======================================
  Files         318      319    +1     
  Lines       20953    20969   +16     
  Branches     2509     2509           
=======================================
+ Hits        20856    20872   +16     
  Misses         97       97           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ror=dev

CMake's warnings about the project's own code (deprecated commands, policy warnings meant for
the project) should fail CI, as a compiler's do. CMake code now has a warnings-as-errors
practice: the `cmake` that configures the build has `-Werror=dev`, or the configure preset in
CMakePresets.json says `"errors": {"dev": true}`. Without either it fails.

The C, C++ and CMake well-configured fixtures configure with -Werror=dev, and the Fortran one
has a preset that does; the per-language flags tests of C and C++ leave out the CMake place,
which is the format's, not a language's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

This branch has not been deployed

No deployments
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.

1 participant