Skip to main content

cmakefmt/
lib.rs

1// SPDX-FileCopyrightText: Copyright 2026 Puneet Matharu
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! `cmakefmt` is a fast, configurable CMake formatter.
6//!
7//! # Quick start
8//!
9//! Format a CMake source string with the default configuration:
10//!
11//! ```
12//! use cmakefmt::{format_source, Config};
13//!
14//! let cmake = "CMAKE_MINIMUM_REQUIRED(VERSION 3.20)\n";
15//! let formatted = format_source(cmake, &Config::default()).unwrap();
16//! assert_eq!(formatted, "cmake_minimum_required(VERSION 3.20)\n");
17//! ```
18//!
19//! To customise formatting, modify [`Config`] fields before passing it in:
20//!
21//! ```
22//! use cmakefmt::{format_source, Config, CaseStyle};
23//!
24//! let mut config = Config::default();
25//! config.line_width = 100;
26//! config.command_case = CaseStyle::Upper;
27//!
28//! let cmake = "target_link_libraries(mylib PUBLIC dep1)\n";
29//! let formatted = format_source(cmake, &config).unwrap();
30//! assert_eq!(formatted, "TARGET_LINK_LIBRARIES(mylib PUBLIC dep1)\n");
31//! ```
32//!
33//! # Organisation
34//!
35//! | Module | Purpose |
36//! |--------|---------|
37//! | [`config`] | Runtime configuration types and config-file loading |
38//! | [`error`] | Error and result types |
39//! | [`formatter`] | Source-to-source formatting pipeline |
40//! | [`parser`] | CMake parser and AST definitions |
41//! | [`spec`] | Built-in and user-extensible command registry |
42
43/// Runtime formatter configuration and config-file loading.
44pub mod config;
45/// Shared error types used across parsing, config loading, and formatting.
46pub mod error;
47/// Source-to-source formatting pipeline.
48pub mod formatter;
49/// CMake parser and AST definitions.
50pub mod parser;
51/// Built-in and user-extensible command specification registry.
52pub mod spec;
53
54// Recursive CMake file-discovery helpers used by the CLI.  Not part of the
55// library embedding API; hidden from generated documentation.
56#[doc(hidden)]
57pub mod files;
58
59// ── Configuration ────────────────────────────────────────────────────────────
60
61pub use config::{
62    convert_legacy_config_files, default_config_template, default_config_template_for,
63    render_effective_config, CaseStyle, CommandConfig, Config, DangleAlign, DumpConfigFormat,
64    PerCommandConfig,
65};
66
67// ── Errors ───────────────────────────────────────────────────────────────────
68
69pub use error::{Error, Result};
70
71// ── Formatting ───────────────────────────────────────────────────────────────
72
73pub use formatter::{
74    format_file, format_source, format_source_with_debug, format_source_with_registry,
75    format_source_with_registry_debug,
76};
77
78// ── Registry ─────────────────────────────────────────────────────────────────
79
80pub use spec::registry::CommandRegistry;