cmakefmt
CMake pretty-printer written in Rust
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).
Installing from source
Using cargo
:
cargo install cmakefmt
Examples
These are interactive examples using a WASM version of the tool.
Long commands
Long lines are broken-up into separate lines.
Key-value pair behaviour
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.
Indentation
Nested blocks are indented by 2 spaces.
Conditions
Condition nodes are grouped together.
Implementation
cmakefmt
is written in Rust using nom
and 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”.
Playground
Please try it out here or check-out the GitHub repository.