CMake "generator ... does not match" - Stale Build Directory
CMake found an existing CMakeCache.txt in the build directory that was created with a different generator than the one you asked for now. A generator cannot be changed in place - the build directory must be regenerated.
What this error means
Configure aborts saying the requested generator does not match the one used previously for this build tree. It commonly appears when a cached build directory is restored in CI but the workflow now requests Ninja (or vice versa).
CMake Error: Error: generator : Ninja
Does not match the generator used previously: Unix Makefiles
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a
different binary directory.Common causes
Build directory reused across generators
A cached build/ was generated with Unix Makefiles but the current run passes -G Ninja (or the reverse). The cache pins the original generator, so configure refuses.
Cached CMakeCache.txt from a different machine
Restoring a build-directory cache built on a different image - with a different default generator or absolute paths - clashes with the current configure.
How to fix it
Delete the build directory and reconfigure
A generator change requires a fresh build tree.
rm -rf build
cmake -S . -B build -G NinjaKeep the generator consistent or scope the cache
- Pin one generator across local and CI so build dirs stay compatible.
- Key any build-directory cache on the generator and CMake version.
- Prefer caching only object/output caches (ccache) over the whole CMake build tree.
How to prevent it
- Use the same
-Ggenerator everywhere, or clean the build dir when it changes. - Do not restore a CMake build directory across different runner images.
- Cache
ccacherather than the configured CMake build tree.