Skip to content

Comparison

There are three CMake formatters in active use: cmakefmt, cmake-format, and gersemi. This page summarises the key differences to help you choose.

Featurecmakefmtcmake-formatgersemi
LanguageRustPythonPython
InstallHomebrew, cargo, binarypippip
Config fileYAML or TOMLPython, YAML, or JSONNone
Config discoveryWalks up the directory treeDirectory-basedNone
Migrate existing config--convert-legacy-config
Check mode--check--check-only--check
Diff output--diff
Stdin formatting--stdin-path <path> -via --via stdin
Range formatting--lines
GitHub Actioncmakefmt/cmakefmt-action@v1
CI annotations--report-format github
VS Code extensionFirst-partyFirst-party
Active maintenanceYesMinimalYes
LicenseMIT OR Apache-2.0Apache-2.0MIT

cmakefmt is a native binary with no interpreter startup overhead. On a cold invocation it formats a typical CMakeLists.txt in under 5 ms. Python tools (cmake-format, gersemi) typically spend 200–500 ms just starting the interpreter before any file is touched — noticeable on every save in an editor.

For large repositories cmakefmt also ships a content-addressed cache (--cache) so unchanged files are not re-parsed between runs.

cmakefmt supports YAML and TOML config files (.cmakefmt.yaml, .cmakefmt.toml) with a structured, documented schema. Config is discovered automatically by walking up from the file being formatted to the filesystem root, mirroring how tools like rustfmt and ruff work.

cmake-format supports a wider variety of config formats (Python files, YAML, JSON) but discovery is less structured. gersemi has no config file at all — its formatting is entirely opinionated.

cmakefmt ships a first-party VS Code extension (cmakefmt.vscode-cmakefmt) with format-on-save support. It works in Neovim via conform.nvim, Helix, Zed, and Emacs via apheleia — see the Editor Integration page.

cmake-format has a widely-used VS Code extension with over 500k installs. gersemi has no editor integration.

cmakefmt ships a first-party GitHub Action (cmakefmt/cmakefmt-action) that installs the right binary for the runner OS in one uses: line. It also outputs GitHub Actions annotations via --report-format github, Checkstyle XML, JUnit XML, and SARIF JSON for downstream tooling.

Neither cmake-format nor gersemi ship a GitHub Action.

cmake-format last released in 2021 and is in maintenance-only mode. The Python 3 ecosystem has moved on and there are known compatibility issues with newer Python versions. gersemi is actively maintained. cmakefmt is under active development with frequent releases.

cmakefmt can convert your existing cmake-format config automatically:

Terminal window
cmakefmt --convert-legacy-config .cmake-format.yaml > .cmakefmt.yaml

See the Migration Guide for a full walkthrough.