Why is CMake configure so slow?
A slow configure usually comes from the same few causes. Wefti removes some of them and gives you tools to find the rest.
CMake configure is slow when it repeats compiler checks in every new build tree, evaluates the whole project after a small edit, or regenerates Ninja files that did not change. The native wefti command shares a verified probe cache, replays unchanged directories, and skips unchanged Ninja generation. In v0.3.0, the geometric mean for five large projects was 1.35x cold, 2.17x with a warm probe cache, and 2.54x after a leaf edit.
The common causes
- Compiler probes such as
try_compile,check_include_file, andcheck_symbol_existsrun again in every new build tree, even with the same compiler. - A change to one
CMakeLists.txtmakes CMake evaluate every directory again. - Ninja generation runs again when nothing that it reads has changed.
- A
FetchContentdownload repeats because nothing pins its result. - A stale
CMakeCache.txtkeeps old facts about a compiler that has changed.
Wefti has a feature for each of the first three. It runs independent literal compile probes in parallel, saves each result with the SHA-256 digest of its inputs, and reuses it in later build trees. It replays directories that did not change from CMakeFiles/wefti/configure.v1.bin. It skips Ninja generation when all recorded inputs match. The skip first happens on the third configure of a new build tree.
Speed on LLVM, Qt, OpenCV, DuckDB, and Protobuf
These are the v0.3.0 results against CMake 4.5.1 on an Apple M1. Each number is the speedup of the median time.
| Project | Cold | Warm probe cache | Leaf edit |
|---|---|---|---|
| DuckDB v1.3.2 | 1.60x | 2.29x | 5.66x |
| OpenCV 4.12.0 | 1.91x | 4.38x | 3.35x |
| Protobuf v36.2 | 1.09x | 1.88x | 1.90x |
| Qt Base v6.8.3 | 1.15x | 1.51x | 2.51x |
| LLVM llvmorg-20.1.8 | 1.19x | 1.70x | 1.17x |
| Geometric mean | 1.35x | 2.17x | 2.54x |
Across all 40 workloads, Wefti was faster than CMake, from 1.09x to 39.81x. A synthetic project with 500 targets and a warm cache reached 39.81x. The full tables are on the benchmarks page.
Find and fix the slow part
Use these steps on a project that configures slowly. Each step adds one tool.
- Profile one configure. Run
wefti -S . -B build --profile. Openbuild/wefti-profile/flamegraph.htmlto see which commands take the time. - Run the same configure again. Repeat in the same build directory and in a new one. The probe cache and replay act on the repeats.
- Remove unused work. Run
wefti unused -B buildandwefti graph -B build --highlight-public-bloatto find packages that nothing uses andPUBLIClinks that can bePRIVATE. - Compare two build trees. Run
wefti diff-config build-before build-afterto see which flags, definitions, or packages changed. - Check for a stale cache. Run
wefti doctor -B buildto find a compiler, toolchain file, or prefix path that changed under the build tree.
wefti -S . -B build --profile
wefti unused -B build
wefti graph -B build --highlight-public-bloat
wefti diff-config build-before build-after --only compile,link
wefti doctor -B build
--profile writes trace.json, stacks.folded, and an interactive flamegraph.html into <build>/wefti-profile. Profile runs turn off incremental replay, so they measure a full configure.
Why did CMake rebuild?
Ninja prints the reason for each rebuild when you run ninja -d explain. If the reason is a changed command line, wefti diff-config shows which flag, definition, or include directory changed between two build trees. It reads the CMake File API replies, CMakeCache.txt, and compile_commands.json, and it never runs cmake.
wefti explain app -B build --flag -O2 then shows where one flag comes from, through PRIVATE, PUBLIC, and INTERFACE links. wefti graph --target app --reverse lists the targets that depend on a library, which shows how far one change spreads. To find dependencies that nothing needs, run wefti unused.
wefti diff-config build-main build-pr
wefti explain app -B build --flag -O2
wefti graph -B build --target zlib --reverse
Frequently asked questions
Why is CMake configure so slow?
The usual causes are repeated compiler probes, full re-evaluation after a small edit, repeated Ninja generation, and repeated downloads. Run wefti -S . -B build --profile to see which commands take the time.
Why is try_compile slow, and can I cache it?
Each try_compile builds a small program. Native Wefti runs independent probes in parallel and saves each result with the SHA-256 digest of its inputs, so later configures reuse it. Use wefti cache export and wefti cache import --sha256 to share results between runners.
How do I speed up CMake for LLVM, Qt, or OpenCV?
Configure with the native wefti command. In v0.3.0, the warm probe cache gave 1.70x on LLVM, 1.51x on Qt Base, and 4.38x on OpenCV. A leaf edit gave 1.17x, 2.51x, and 3.35x.
How do I find which dependencies my CMake project does not use?
Run wefti unused -B build. It reports packages that find_package() found and nothing uses, duplicate links, empty INTERFACE links, and unused variables. Use --deny to fail CI on findings.
How do I see the CMake target dependency graph?
Run wefti graph -B build. It prints a tree, or DOT, Mermaid, or JSON with --format. It finds cycles and marks PUBLIC links that can be PRIVATE.
Why did my CMake build rebuild everything?
Run ninja -d explain to see the reason. If a command line changed, run wefti diff-config on the two build trees to see the changed flags, definitions, and include directories.