Skip to content

cmakefmt

Automatically format your CMake files — consistent style, zero manual effort.
cmake-format, reimagined.

Up-to-date specs

Built-in specs for 150+ commands, audited against CMake 4.3. cmake-format hasn't been updated since 2021 and misses many modern commands and arguments.

Whole-project, instant

Recursive discovery and parallel formatting by default. Point it at your project root — no file lists, no wrapper scripts.

Zero dependencies

One binary. No Python, no virtualenv, no dependency drift. Drop it in CI and forget about it.

Editor-ready

Built-in LSP server, VS Code extension, format-on-save for Neovim, Helix, Zed, and Emacs — plus config autocomplete via SchemaStore.

Built for workflows

--check, --diff, --staged, --explain, Git-aware file selection, semantic verification, JSON reporting — all first-class.

One-command migration

Already using cmake-format? cmakefmt config convert translates your existing config — no manual rewriting.

macOS
brew install cmakefmt/cmakefmt/cmakefmt
Cargo
cargo install cmakefmt-rust
pip
pip install cmakefmt

Or download a pre-built binary from GitHub Releases.

Then — just point it at your project. It discovers all CMake files recursively and formats them in parallel:

Terminal window
cmakefmt config init # generate a starter .cmakefmt.yaml
cmakefmt --check . # dry-run: just show which files would change
cmakefmt . # dry-run: preview formatted output; changed lines shown in blue
cmakefmt --diff . # dry-run: view a unified diff of what would change (like `git diff`)
cmakefmt --in-place . # apply formatting across the whole project
cmakefmt --staged --check # use in pre-commit hooks
cmakefmt --path-regex 'src/.*' . # format CMake files only under src/

Formatter Demo

Watch rough CMake settle into a stable layout.

The landing-page animation shows the kind of cleanup cmakefmt performs in one pass: casing becomes consistent, simple lists collapse, and larger calls wrap into a readable structure.

CMAKE_MINIMUM_REQUIRED(VERSION 3.20)
Project(myproject LANGUAGES CXX)

set(SOURCES src/main.cpp
src/utils.cpp
  src/parser.cpp)

target_link_libraries(mylib PUBLIC
Boost::filesystem Boost::system    fmt::fmt
  PRIVATE
    spdlog::spdlog)

IF(WIN32)
MESSAGE(STATUS "building on Windows")
ENDIF()
geometric-mean speedup over cmake-format across 11 real-world fixtures. On a 282-file repository: ~997× faster sequentially, ~2,853× faster with --parallel.

See Performance for the full methodology and benchmark environment.

Want to try it without installing? Open the Playground →

New to cmakefmt?

Migrating from cmake-format?

Embedding cmakefmt as a library?

Last updated:

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