Skip to content

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.

Homebrew — recommended for macOS, no Rust toolchain needed:

Terminal window
brew install cmakefmt/cmakefmt/cmakefmt

Pre-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:

Terminal window
cargo install cmakefmt-rust

Verify the install:

Terminal window
cmakefmt --version

For shell completions, editor setup, and more install options see the full Installation page.

Dump a starter config to your repository root:

Terminal window
cmakefmt --dump-config > .cmakefmt.yaml

YAML 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.

Check what would change across your whole repository without touching any files:

Terminal window
cmakefmt --check .

If the output looks right, apply formatting:

Terminal window
cmakefmt --in-place .

Format only the files you’re about to commit:

Terminal window
cmakefmt --staged --check

The repository ships a pre-commit configuration. Install it once:

Terminal window
pre-commit install