cmakefmt
Configuration file for cmakefmt, a fast native CMake formatter
| Type | object |
|---|---|
| File match |
.cmakefmt.yaml
.cmakefmt.yml
.cmakefmt.toml
|
| Schema URL | https://catalog.lintel.tools/schemas/schemastore/cmakefmt/latest.json |
| Source | https://cmakefmt.dev/schemas/latest/schema.json |
Validate with Lintel
npx @lintel/lintel check
The user-config file structure for .cmakefmt.yaml, .cmakefmt.yml, and
.cmakefmt.toml.
All fields are optional — only specified values override the defaults.
Properties
Experimental formatting options gated behind --preview or the
[experimental] config section. All options default to false.
These may be promoted to stable defaults in a future release, changed incompatibly, or removed entirely.
This struct is re-exported at the crate root even when it contains no options so consumers can write forward-compatible initialisers:
use cmakefmt::{Config, Experimental};
let config = Config {
experimental: Experimental::default(),
..Config::default()
};
25 nested properties
Command names (lowercase) that must always use vertical layout regardless of line width.
Heuristically infer sortability for keyword sections without explicit annotation.
Output casing for command names: lower, upper, or unchanged.
How to indent continuation lines: same-indent or under-first-value.
Alignment strategy for a dangling ): prefix, open, or close.
Place the closing ) on its own line when a call wraps.
Disable formatting entirely and return the source unchanged.
Sort arguments in keyword sections marked sortable in the command spec.
How to handle fractional indentation when use_tabs is true: use-space or round-up.
Output casing for recognized keywords and flags: lower, upper, or unchanged.
Output line-ending style: unix (LF), windows (CRLF), or auto (detect from input).
Maximum rendered line width before cmakefmt wraps a call. Default: 80.
Maximum number of consecutive blank lines to preserve. Default: 1.
Maximum keyword/flag subgroups to keep in a hanging-wrap layout. Default: 2.
Maximum wrapped lines to tolerate before switching to a more vertical layout. Default: 2.
Maximum positional arguments to keep in a hanging-wrap layout. Default: 6.
Upper heuristic bound used when deciding between compact and wrapped layouts. Default: 10.
Maximum rows a hanging-wrap positional group may consume before nesting is forced. Default: 2.
Lower heuristic bound used when deciding between compact and wrapped layouts. Default: 4.
Return an error if any formatted output line exceeds line_width.
Insert a space before ( for control-flow commands such as if, foreach, while.
Insert a space before ( for function() and macro() definitions.
Number of spaces per indentation level when use_tabs is false. Default: 2.
Indent with tab characters instead of spaces.
Keep the first positional argument on the command line when wrapping.
10 nested properties
Preferred bullet character when normalizing markup lists. Default: *.
Normalize ruler comments when markup handling is enabled.
Enable markup-aware comment handling.
Preferred punctuation for numbered lists when normalizing markup. Default: ..
Regex pattern for inline comments explicitly trailing their preceding argument. Default: #<.
Regex describing fenced literal comment blocks.
Preserve the first comment block in a file literally.
Minimum ruler length before a hash-only line is treated as a ruler. Default: 10.
Regex for comments that should never be reflowed.
Regex describing ruler-style comments that should be treated specially.
Per-command configuration overrides keyed by lowercase command name.
{}
Definitions
How to normalise command/keyword casing.
How to indent continuation lines when a wrapped keyword section
overflows [Config::line_width].
Suppose PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ exceeds the line budget under a
PATTERN *.h subgroup:
# SameIndent — continuation wraps at the subkwarg indent:
PATTERN *.h
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
# UnderFirstValue — continuation aligns under the first value
# after the keyword:
PATTERN *.h
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
cmakefmt defaults to [ContinuationAlign::UnderFirstValue]: when
a subkwarg group overflows, continuation lands under the first
value column so the eye can tell continuation values apart from
sibling subkwargs. This also matches cmake-format's hanging-indent
style, easing migration. [ContinuationAlign::SameIndent] is
available for consumers who prefer continuation at the subkwarg's
own column — consistent with how flat keyword sections
(PUBLIC/PRIVATE/…) and positional lists wrap elsewhere in the
formatter.
How to align the dangling closing paren.
Only takes effect when [Config::dangle_parens] is true.
Controls where ) is placed when a call wraps onto multiple lines.
At the top level (block depth = 0) Prefix and Close both place
the ) at column 0 because the command sits there — the two
variants are visually identical in this case:
# Prefix / Close at top level — `)` at column 0:
target_link_libraries(
mylib PUBLIC dep1
)
# Open — `)` at the opening-paren column:
target_link_libraries(
mylib PUBLIC dep1
)
Inside a nested block (if/foreach/while/function/...) the
variants diverge: Prefix tracks the command-name indent (one
tab stop per nesting level), while Close places the ) at the
current indent level — one tab stop shallower than the command
name, i.e. flush with the enclosing block.
Experimental formatting options gated behind --preview or the
[experimental] config section. All options default to false.
These may be promoted to stable defaults in a future release, changed incompatibly, or removed entirely.
This struct is re-exported at the crate root even when it contains no options so consumers can write forward-compatible initialisers:
use cmakefmt::{Config, Experimental};
let config = Config {
experimental: Experimental::default(),
..Config::default()
};
Command names (lowercase) that must always use vertical layout regardless of line width.
Heuristically infer sortability for keyword sections without explicit annotation.
Output casing for command names: lower, upper, or unchanged.
How to indent continuation lines: same-indent or under-first-value.
Alignment strategy for a dangling ): prefix, open, or close.
Place the closing ) on its own line when a call wraps.
Disable formatting entirely and return the source unchanged.
Sort arguments in keyword sections marked sortable in the command spec.
How to handle fractional indentation when use_tabs is true: use-space or round-up.
Output casing for recognized keywords and flags: lower, upper, or unchanged.
Output line-ending style: unix (LF), windows (CRLF), or auto (detect from input).
Maximum rendered line width before cmakefmt wraps a call. Default: 80.
Maximum number of consecutive blank lines to preserve. Default: 1.
Maximum keyword/flag subgroups to keep in a hanging-wrap layout. Default: 2.
Maximum wrapped lines to tolerate before switching to a more vertical layout. Default: 2.
Maximum positional arguments to keep in a hanging-wrap layout. Default: 6.
Upper heuristic bound used when deciding between compact and wrapped layouts. Default: 10.
Maximum rows a hanging-wrap positional group may consume before nesting is forced. Default: 2.
Lower heuristic bound used when deciding between compact and wrapped layouts. Default: 4.
Return an error if any formatted output line exceeds line_width.
Insert a space before ( for control-flow commands such as if, foreach, while.
Insert a space before ( for function() and macro() definitions.
Number of spaces per indentation level when use_tabs is false. Default: 2.
Indent with tab characters instead of spaces.
Keep the first positional argument on the command line when wrapping.
How to handle fractional tab indentation when [Config::use_tabchars] is
true.
Output line-ending style.
Preferred bullet character when normalizing markup lists. Default: *.
Normalize ruler comments when markup handling is enabled.
Enable markup-aware comment handling.
Preferred punctuation for numbered lists when normalizing markup. Default: ..
Regex pattern for inline comments explicitly trailing their preceding argument. Default: #<.
Regex describing fenced literal comment blocks.
Preserve the first comment block in a file literally.
Minimum ruler length before a hash-only line is treated as a ruler. Default: 10.
Regex for comments that should never be reflowed.
Regex describing ruler-style comments that should be treated specially.
Per-command overrides. All fields are optional — only specified fields override the global config for that command.
YAML/TOML key names
Two fields use different names in config files than in this Rust struct (for historical reasons):
| Rust field | YAML/TOML key |
|---|---|
max_pargs_hwrap | max_hanging_wrap_positional_args |
max_subgroups_hwrap | max_hanging_wrap_groups |
All other fields use the same name in both.
Override the command casing rule for this command only.
Override the continuation-alignment rule for this command.
Override dangling paren alignment for this command only.
Override dangling paren placement for this command only.
Override the keyword casing rule for this command only.
Override the line width for this command only.
Override the hanging-wrap subgroup threshold for this command only.
Override the hanging-wrap positional argument threshold for this command only.
Override the indentation width for this command only.
Keep the first positional argument on the command line when wrapping.