Installation
Get cmakefmt running, wire it into your project, and never think about CMake
formatting again.
Current Installation Options
Section titled “Current Installation Options”Homebrew
Section titled “Homebrew”Recommended for macOS users — no Rust toolchain needed:
brew install cmakefmt/cmakefmt/cmakefmtReference install path for developers already using Rust, works on any platform:
cargo install cmakefmt-rustVerify the binary is on your path:
cmakefmt --versioncmakefmt --helpYou can also install from a local checkout — for development, benchmarking, or reviewing changes:
cargo install --path .Pre-built Binaries
Section titled “Pre-built Binaries”Native binaries for Linux, macOS, and Windows are published to
GitHub Releases.
Download the .zip / .tar.gz for your platform, extract, and place the
binary on your PATH.
Build From Source
Section titled “Build From Source”git clone https://github.com/cmakefmt/cmakefmtcd cmakefmtcargo build --release./target/release/cmakefmt --helpThis is the right path if you are actively developing cmakefmt, reviewing
changes, or benchmarking local modifications.
Support Levels
Section titled “Support Levels”The release plan separates channels into explicit support levels so users know what to trust:
| Channel | Support level | Notes |
|---|---|---|
Homebrew (cmakefmt/cmakefmt) | Officially maintained | Recommended for macOS users. Ships completions and man page. |
cargo install cmakefmt-rust | Officially maintained | Reference install path for developers already using Rust. |
| GitHub Releases binaries | Officially maintained | Native binaries for Linux, macOS, and Windows. |
| Docs site / CLI reference | Officially maintained | Stays in lock-step with each tagged release. |
winget / Scoop | Officially maintained | Planned first-party Windows package-manager channels. |
| Additional package managers (AUR, Nix, containers, etc.) | Automated or best-effort | Useful channels, but not the first rollout priority. |
Shell Completions
Section titled “Shell Completions”Release archives include shell completion scripts for the supported shells:
cmakefmt.bashfor Bash_cmakefmtfor Zshcmakefmt.fishfor Fish
The Zsh file intentionally uses the conventional completion-function name
_cmakefmt rather than a .zsh suffix.
You can also generate the completion files yourself from any installed binary:
cmakefmt --generate-completion bash > cmakefmt.bashcmakefmt --generate-completion zsh > _cmakefmtcmakefmt --generate-completion fish > cmakefmt.fishSource the file from your .bashrc or .bash_profile:
cmakefmt --generate-completion bash > ~/.local/share/bash-completion/completions/cmakefmtOr for a system-wide install (requires write access):
cmakefmt --generate-completion bash | sudo tee /etc/bash_completion.d/cmakefmt > /dev/nullPlace the file somewhere on your fpath and reload completions:
cmakefmt --generate-completion zsh > ~/.zfunc/_cmakefmtThen add the following to your .zshrc if ~/.zfunc is not already on fpath:
fpath=(~/.zfunc $fpath)autoload -Uz compinit && compinitFish looks for completions in a fixed directory — just drop the file there:
cmakefmt --generate-completion fish > ~/.config/fish/completions/cmakefmt.fishFish picks up the new file automatically without a shell restart.
First Project Setup
Section titled “First Project Setup”Dump a starter config into your repo root:
cmakefmt --dump-config > .cmakefmt.yamlWhy YAML by default? For larger configs, YAML requires less punctuation and is
more readable with nested custom-command specs. TOML is still available via
--dump-config toml if you prefer it.
Do a dry run — check your whole project without rewriting a single file:
cmakefmt --check .When you are happy with what you see, apply the formatting:
cmakefmt --in-place .Typical Local Workflow
Section titled “Typical Local Workflow”The commands you will reach for every day:
cmakefmt --check .cmakefmt --in-place .cmakefmt --verify CMakeLists.txtcmakefmt --cache --check .cmakefmt --require-pragma --check .cmakefmt --staged --checkcmakefmt --changed --since origin/main --checkWhat each one does:
--check .: CI-safe validation for a repository or directory--in-place .: rewrite all discovered CMake files, with semantic verification by default--verify CMakeLists.txt: do a safe stdout-format run when you want the extra parse-tree check--cache --check .: speed up repeated whole-repo checks when your config is stable--require-pragma --check .: roll formatting out gradually, only touching opted-in files--staged --check: pre-commit guard — only touches staged files--changed --since origin/main --check: PR-scoped check for branch-only changes
CI-Friendly Shell Usage
Section titled “CI-Friendly Shell Usage”The simplest CI baseline:
cmakefmt --check .For quieter CI logs:
cmakefmt --check --quiet .For machine-readable output that scripts or dashboards can consume:
cmakefmt --check --report-format json .Editor And Stdin Workflows
Section titled “Editor And Stdin Workflows”Many editor integrations pipe a buffer through stdin rather than passing a real
file path. Use --stdin-path to give config discovery and diagnostics the
on-disk context they need:
cat src/CMakeLists.txt | cmakefmt - --stdin-path src/CMakeLists.txtThis is also the right pattern for ad-hoc scripts and custom editor commands.
Config Bootstrap Tips
Section titled “Config Bootstrap Tips”If your project uses many custom CMake functions or macros:
- start from
--dump-config - keep the file as
.cmakefmt.yaml - define command syntax under
commands: - use
per_command_overrides:only for layout and style tweaks
If you are debugging config discovery:
cmakefmt --show-config-path src/CMakeLists.txtcmakefmt --show-config src/CMakeLists.txtcmakefmt --explain-configUpgrade And Uninstall
Section titled “Upgrade And Uninstall”Upgrade a Homebrew install
Section titled “Upgrade a Homebrew install”brew updatebrew upgrade cmakefmtRemove a Homebrew install
Section titled “Remove a Homebrew install”brew uninstall cmakefmtbrew untap cmakefmt/cmakefmtUpgrade a local source install
Section titled “Upgrade a local source install”git pull --ff-onlycargo install --path . --forceRemove a Cargo-installed binary
Section titled “Remove a Cargo-installed binary”cargo uninstall cmakefmt-rustPin a specific release in CI later
Section titled “Pin a specific release in CI later”Once release tags exist, prefer explicit version pins:
cargo install cmakefmt-rust --version <tagged-version>The release docs and release notes will also publish SHA-256 sums for release artifacts so non-Cargo installs can verify downloads.
Troubleshooting Install Issues
Section titled “Troubleshooting Install Issues”cmakefmt is not found after cargo install
Section titled “cmakefmt is not found after cargo install”Make sure Cargo’s install bin directory is on your PATH.
The formatter is using the wrong config
Section titled “The formatter is using the wrong config”cmakefmt --show-config-path path/to/CMakeLists.txtcmakefmt --explain-configA hook or script only sees stdin and ignores my project config
Section titled “A hook or script only sees stdin and ignores my project config”Pass --stdin-path with the buffer’s real project-relative path.
I want TOML instead of YAML
Section titled “I want TOML instead of YAML”cmakefmt --dump-config toml > .cmakefmt.tomlYAML is the recommended default because it is more readable for larger configurations with nested custom command specs.