Skip to content

Getting Started

cmakefmt demo

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.

Generate a starter config in your repository root:

Terminal window
cmakefmt config init

Or dump the full default config to stdout:

Terminal window
cmakefmt config dump > .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, or browse the Formatting Cookbook for quick before/after examples of common formatting goals.

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 .

Install a pre-commit hook that checks formatting on every commit:

Terminal window
cmakefmt install-hook

This adds a git pre-commit hook that runs cmakefmt --check --staged. Commits with unformatted CMake files will be rejected until you run cmakefmt --in-place ..

For pre-commit framework integration, see the CI page.

For a brief summary of all flags:

Terminal window
cmakefmt -h

For an extended description of every flag with examples:

Terminal window
cmakefmt --help

Docs track main. For historical docs, check out a release tag in the repository and build docs/ locally.