Getting Started
cmakefmt is a fast, workflow-first formatter for CMake files. This page gets you from
installation to a fully formatted repository in under a minute.
Install
Section titled “Install”Homebrew — recommended for macOS, no Rust toolchain needed:
brew install cmakefmt/cmakefmt/cmakefmtPre-built binaries — for Linux, macOS, and Windows, download the .zip / .tar.gz
from GitHub Releases,
extract, and place the binary on your PATH.
Cargo — for developers already using Rust, works on any platform:
cargo install cmakefmt-rustVerify the install:
cmakefmt --versionFor shell completions, editor setup, and more install options see the full Installation page.
Generate a Config
Section titled “Generate a Config”Dump a starter config to your repository root:
cmakefmt --dump-config > .cmakefmt.yamlYAML is the recommended format. Open the file and adjust options like
format.line_width and style.command_case to match your project’s style.
See the Config Reference for every available option.
Your First Run
Section titled “Your First Run”Check what would change across your whole repository without touching any files:
cmakefmt --check .If the output looks right, apply formatting:
cmakefmt --in-place .Pre-commit Hook
Section titled “Pre-commit Hook”Format only the files you’re about to commit:
cmakefmt --staged --checkThe repository ships a pre-commit configuration. Install it once:
pre-commit installWhat’s Next
Section titled “What’s Next”- Installation — full install options, shell completions, editor setup
- CLI Reference — every flag documented
- Config Reference — tune
cmakefmtfor your project - Formatter Behavior — understand what gets changed and why
- Migration From
cmake-format— coming from the Python tool?