A better CMake without a rewrite
wefti makes CMake easier to inspect and maintain, and your CMakeLists.txt files stay the same. The cmake command keeps CMake 4.5.1 compatibility. The wefti command adds tools that explain where flags come from, fix lint findings, format listfiles, find unused dependencies, and compare build trees.
Wefti adds developer tools to existing CMake projects without a rewrite. The native wefti command provides explain, lint --fix, fmt, unused, graph, diff-config, and doctor. The cmake command name keeps CMake 4.5.1 compatibility mode.
Two modes in one binary
wefti has two personas. The persona depends on the command name that starts the binary. Your CMakeLists.txt files stay the same in both modes.
- Compatibility mode
- Run the binary as
cmake,ccmake,ctest, orcpack, or setWEFTI_ORACLE_MODE=1. wefti follows CMake 4.5.1 commands, output, and diagnostics. It rejects the native subcommands and flags and writes no native metadata files. - Native mode
- Run the binary as
wefti. You get the probe cache, incremental replay, and the developer tools on this page. Build-time regeneration of a native build directory keeps the native persona.
To install the binary and the cmake alias, read the installation guide. To check your project before you switch, read the CMake replacement guide.
Which command answers which question
Each row starts from a common CMake problem. The commands read a configured build directory or evaluate the project in memory. Pass -B <dir> when the build directory is not the current directory.
| Problem | Command | Result |
|---|---|---|
| Where does a compiler flag come from? | wefti explain app -B build --flag -O2 | Each source of the flag across PRIVATE, PUBLIC, and INTERFACE usage chains |
| Where does a definition or include directory come from? | wefti explain app -B build --define USE_TLSwefti explain app -B build --include /opt/local/include | The listfile and usage chain that add the definition or directory |
| Why does a target link a library? | wefti explain app -B build --dep zlib --config Release | Link and order-only paths to the dependency, up to 16 paths and depth 32 |
| Which code sets a variable? | wefti explain CMAKE_CXX_FLAGS -B build --var | Every write across listfiles, functions, macros, cache entries, and -D options |
Why did find_package() fail? | wefti explain why-not Boost -B build --all-candidateswefti explain --find OpenSSL -B build | Rejected candidate config files with the reason for each, or the resolution of a found package |
| What does a generator expression return? | wefti explain --eval '$<$<CONFIG:Debug>:-DTRACE>' -B build --config Debug | The result and each intermediate step |
| Which targets does the project define? | wefti explain --targets -B build | Each target with its type and source directory |
| What does a preset resolve to? | wefti preset show dev -S . | The preset after includes, inheritance, macros, and conditions, with secrets hidden |
| Which listfiles have lint findings? | wefti lint --fixwefti lint --diff --unsafe-fixeswefti lint --sarif --deny-warnings | 12 rules, automatic fixes as concrete syntax tree edits, and SARIF 2.1.0 output for code scanning |
| Is the formatting consistent? | wefti fmtwefti fmt --check | Lossless formatting that changes only whitespace and optional command case |
| Which packages, links, or variables are unused? | wefti unused -B build --only packages,links,vars --deny | Unused packages, duplicate links, empty INTERFACE links, and unused variables |
Does the target graph have cycles or extra PUBLIC links? | wefti graph -B build --highlight-public-bloat --check-headers | Cycles found with Tarjan's algorithm and PUBLIC links that could be PRIVATE |
| Why do two build trees differ? | wefti diff-config build-main build-pr | Differences in targets, compile and link commands, toolchains, packages, and cache entries |
Is CMakeCache.txt stale? | wefti doctor -B build | Drift in recorded tool files and cache fields, without running compilers |
| Does wefti match CMake on my project? | wefti verify --oracle /path/to/cmake-4.5.1 -- -S . -G Ninja | A side-by-side check against CMake 4.5.1 in isolated copies of the source tree |
| Which part of configure is slow? | wefti -S . -B build --profile | flamegraph.html, trace.json, and stacks.folded |
| Does configure read undeclared inputs? | wefti -S . -B build --hermetic=strict | Rejected environment reads, file reads outside project and tool roots, child processes, and network access |
| Can FetchContent use pinned sources? | wefti -S . -B build --fetch-lock=frozen | Archive hashes and Git commits pinned in wefti-fetch.lock |
| Can a multi-config build export compile commands? | wefti -S . -B build -G "Ninja Multi-Config" --export-compile-commands | One compile_commands_<Config>.json file for each configuration, also for Xcode and Visual Studio |
| Is an error message hard to read? | wefti -S . -B build --diagnostics=rich | Source spans and suggested fixes in the terminal |
The native tools work only through the wefti command. The cmake alias keeps CMake 4.5.1 behavior and rejects these subcommands and flags.
How to inspect, clean, and check a CMake project
- Configure in native mode. Run wefti with your usual generator and options in a build directory. Use the same compiler and toolchain that you use with CMake.
wefti -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
- Find the source of a setting. Run wefti explain on a target with one filter, such as --flag, --define, --include, or --dep. Run wefti explain why-not for a package that find_package() did not find.
wefti explain app -B build --flag -O2 --config Release
wefti explain why-not Boost -B build --all-candidates
- Fix lint findings and format the listfiles. Run wefti lint --fix to apply safe fixes. Then run wefti fmt to format CMakeLists.txt and *.cmake files.
wefti lint --diff --unsafe-fixes
wefti lint --fix
wefti fmt
- Remove unused dependencies. Run wefti unused to find unused packages and links. Run wefti graph to find cycles and PUBLIC links that could be PRIVATE.
wefti unused -B build --only packages,links,vars
wefti graph -B build --highlight-public-bloat --check-headers
wefti graph -B build --target app --format mermaid -o app.mmd
- Add checks to CI. Run wefti fmt --check, wefti lint --deny-warnings, and wefti unused --deny in continuous integration. Upload the SARIF files to code scanning.
wefti fmt --check
wefti lint --deny-warnings --sarif > wefti-lint.sarif
wefti unused -B build --deny --sarif > wefti-unused.sarif
wefti diff-config --save snapshot.json build
To see these results in your editor, set up the wefti-lsp language server. It runs the same lint rules and formatter.
The 12 lint rules
A safe fix keeps the configure behavior or removes a command that has no effect. An unsafe fix can change the configure behavior. wefti lint --fix applies only safe fixes unless you add --unsafe-fixes. Use --dry-run to count the fixes without writing files.
| Rule | Default severity | What it finds | Automatic fix |
|---|---|---|---|
undefined-variable | warning | A variable reference that is unset or probably misspelled | unsafe: rename to the close match |
glob-without-configure-depends | warning | file(GLOB) for target sources without CONFIGURE_DEPENDS | safe: add CONFIGURE_DEPENDS |
single-config-condition | warning | A condition on CMAKE_BUILD_TYPE without a single-config generator guard | None |
unguarded-build-type | warning | An assignment or FORCE cache write that hides CMAKE_BUILD_TYPE | unsafe: remove FORCE |
directory-options | note | include_directories, link_libraries, or add_definitions that affect all targets in scope | None |
obsolete-command | warning | Obsolete or removed commands and unsupported cmake_minimum_required versions | unsafe: replacement command or higher version |
old-policy | warning | cmake_policy(SET CMPnnnn OLD) | unsafe: set to NEW |
fragile-if-expansion | warning | An unquoted expansion in if() that breaks with empty or list values | safe: quote the operand |
legacy-block-end-args | warning | Arguments repeated in else(), endif(), endforeach(), endwhile(), endfunction(), or endmacro() | safe: remove the arguments |
deprecated-link-scope | warning | LINK_PUBLIC or LINK_PRIVATE in target_link_libraries() (CMP0023) | safe or unsafe: replace with PUBLIC or PRIVATE |
redundant-fatal-error | note | FATAL_ERROR in cmake_minimum_required(), which CMake ignores | safe: remove FATAL_ERROR |
redundant-policy-pin | note | cmake_policy(SET CMPnnnn NEW) for a policy that the policy version already sets to NEW | safe: remove the command |
To suppress one rule on one command, put # wefti-lint: disable=<rule> on the line before the command. Run wefti lint --list-rules to print all rules.
Formatter and project settings
wefti fmt changes only whitespace and, if you select it, the case of ASCII command names. Before it writes a file, an independent check confirms that the syntax tree, protected tokens, and comment positions stay the same. Use --check in CI, --diff to preview, and --stdin for editor integration.
wefti fmt, wefti lint, and wefti-lsp read the nearest .wefti.toml file in the project. An unknown key is a configuration error.
exclude = ["third_party/**"]
[fmt]
indent_width = 2
line_width = 100
command_case = "lower"
[lint]
disable = ["directory-options"]
[lint.severity]
glob-without-configure-depends = "error"
For configure speed, read how to speed up CMake configure and the benchmark report. For a comparison with other build systems, read the CMake alternatives guide and wefti vs CMake, Meson, Bazel, and Ninja.
Frequently asked questions
How do I find where a compiler flag comes from in CMake?
Run wefti explain <target> -B build --flag <flag>. The command traces the flag through PRIVATE, PUBLIC, and INTERFACE usage chains and shows the listfile that adds it. It reads the build directory in memory and does not change files.
How do I debug a find_package() failure?
Run wefti explain why-not <package> -B build. The command shows the candidate config files that find_package() rejected and the reason for each. Run wefti explain --find <package> to see how a found package was resolved.
Does wefti include a CMake formatter and linter?
Yes. wefti fmt formats CMakeLists.txt and *.cmake files and changes only whitespace and optional command case. wefti lint checks 12 rules. wefti lint --fix applies safe fixes, and --unsafe-fixes also applies fixes that can change configure behavior.
How do I find unused dependencies in a CMake project?
Run wefti unused -B build. It reports packages that find_package() found but the project does not use, duplicate links, and empty INTERFACE links. Add --only vars for unused variables, --deny to fail CI, or --sarif for code scanning.
Do the wefti tools change my CMakeLists.txt files?
Only wefti fmt and wefti lint with --fix edit listfiles. wefti fmt verifies that the syntax tree stays the same before it writes. The explain, unused, graph, diff-config, and doctor commands do not edit listfiles.
How do I compare two CMake build directories?
Run wefti diff-config build-a build-b. It compares targets, compile and link commands, toolchains, packages, and cache entries from build trees made by wefti or cmake. Use --save to make a portable snapshot that you can compare on another machine.