Where Does CMake Store Its Cache?
The CMakeCache.txt file at the top of every build tree, plus the per-user package registry on each OS.
Last updated
Every CMake build tree carries its configuration in a file called CMakeCache.txt at its top level. The first configure run creates it, and later runs read it back, which is why toggling an option sometimes seems to stick. The build directory itself is wherever you pointed CMake, so the cache path always starts with a folder you chose.
A second location matters when projects find each other. The user package registry records where built packages live: files under ~/.cmake/packages on Unix, registry keys under HKEY_CURRENT_USER on Windows. The export(PACKAGE) command writes these entries, and find_package cleans up the stale ones.
Where CMake stores this, by platform
<build-dir>\CMakeCache.txt
Sits at the top of whichever folder you configured as the build tree. Delete it plus the CMakeFiles directory for a fresh configure. The user package registry on this OS lives in the registry under HKEY_CURRENT_USER Software Kitware CMake Packages.
<build-dir>/CMakeCache.txt
Same build tree cache file as everywhere else. The user package registry is a folder tree at ~/.cmake/packages/<package>/ holding files whose contents point at package locations. Presets for sharing choices live in CMakePresets.json at the source root.
<build-dir>/CMakeCache.txt
Identical layout to macOS, including the ~/.cmake/packages registry. If a build keeps finding a deleted dependency, an orphaned registry entry is the likely cause. The -U flag removes variables from the cache without wiping the whole tree.
Frequently asked questions
how do I wipe the CMake cache and start over
Delete CMakeCache.txt and the CMakeFiles directory inside the build tree, then configure again from scratch. Editing the cache by hand is discouraged because entries hold absolute paths and the format can change. Prefer passing -D values on the command line.
where is the CMake user package registry
Look in ~/.cmake/packages/<name>/ on Unix, where export(PACKAGE) drops files pointing at build trees. On Windows the same entries live under HKEY_CURRENT_USER Software Kitware CMake Packages. Stale entries pointing at deleted trees get cleaned automatically.
can I copy CMakeCache.txt to another machine
No. The cache belongs to one build tree and is full of absolute paths, so copying it to another machine or directory causes confusing failures. Ship a CMakePresets.json or a -C initial cache script instead, which express the same choices portably.
Notice an outdated path? Let us know.