I have written an initial prototype of
cmakefmt, a CMake files auto-formatter.
The source code is available on GitHub at (https://github.com/yamadapc/cmakefmt).
cargo install cmakefmt
These are interactive examples using a WASM version of the tool.
Long lines are broken-up into separate lines.
Arguments with all upper-case letters are grouped together with the next non-uppercase argument. So if there is space, upper-case arguments will be printed as key-value pairs as follows.
Nested blocks are indented by 2 spaces.
Condition nodes are grouped together.
cmakefmt is written in Rust using
pretty combinator libraries.
It parses the CMake document onto an AST using nom parser combinators
and then serialises it into a string using pretty, which are combinators in the same style of “A pretty-printer”.
Please try it out here or check-out the GitHub repository.