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.4.0, the geometric mean for five large projects was 1.31x cold, 2.21x with a warm probe cache, and 2.24x 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 runs independent literal compile probes in parallel. It saves eligible results and reuses them in later build trees after it checks the recorded inputs. It uses the compact binary journal at CMakeFiles/wefti/configure.v1.bin to replay unchanged directories when their inputs still match.
Wefti skips Ninja generation when all recorded generation inputs match. For eligible single-configuration Ninja builds, partial generation (F2) and the Ninja fragment cache (F3) are on by default in native mode. Wefti updates the affected parts of the manifest when its checks pass. If the partial generation checks fail, Wefti runs full generation.
Speed on LLVM, Qt, OpenCV, DuckDB, and Protobuf
These are the v0.4.0 results against CMake 4.5.1 on an Apple M1. Each phase used three runs. Each project speedup is the CMake median time divided by the Wefti median time.
| Project | Cold | Warm probe cache | Leaf edit |
|---|---|---|---|
| DuckDB v1.3.2 | 1.52x | 2.37x | 5.44x |
| OpenCV 4.12.0 | 1.74x | 3.85x | 1.13x |
| Protobuf v36.2 | 0.99x | 2.17x | 1.95x |
| Qt Base v6.8.3 | 1.24x | 1.58x | 2.47x |
| LLVM llvmorg-20.1.8 | 1.20x | 1.69x | 1.90x |
| Geometric mean | 1.31x | 2.21x | 2.24x |
Wefti was faster than CMake in 37 of 40 matched workloads. The ratios ranged from 0.97x to 138.17x. Cold configure was slower for the 100-target project (0.99x), nlohmann/json (0.97x), and Protobuf (0.99x).
A repeat configure of an unchanged 500-target project took 17.20 ms with Wefti and 2,376.55 ms with CMake (138.17x). A separate synthetic test used a new build directory with a warm probe cache and measured a 7.30x speedup. See the benchmark report for the full results.
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
Use wefti cache remote to check the remote cache connection. Use wefti cache pull to restore and verify a pack. Use wefti cache push to upload eligible probe and configure entries. See the CI cache guide for setup.
--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?
After configure, run wefti build build to compile and link with the built-in Ninja 1.13.2 executor.
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.4.0, the warm probe-cache speedups were 1.69x for LLVM, 1.58x for Qt Base, and 3.85x for OpenCV. After a leaf edit, the speedups were 1.90x, 2.47x, and 1.13x, in the same order.
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.