CMake 3.24.0, released on August 4, 2022, adds --fresh for build maintainers who need to discard a build tree’s saved configuration. The option removes CMakeCache.txt and the associated CMakeFiles directory, then recreates them during configuration. It offers a way to reset that state without confusing the job with cleaning and rebuilding the project’s targets. [S1][S2][S3]

The cache stores choices that a team may want to keep. CMake uses CMakeCache.txt to preserve build-system options between runs, so resetting it also discards that record of deliberate settings. A value supplied on an earlier command line should not be expected to survive solely because the same build directory is reused. CMake’s -D option creates or updates a cache entry and takes priority over the project’s default value. [S2][S5]

Cleaning acts at a different stage. In the 3.24 command-line manual, --clean-first belongs to cmake --build: it runs the clean target and then builds. The --fresh option instead belongs to configuration and explicitly resets the cache and CMakeFiles. For a maintainer investigating an unwanted saved option, these are different operations. The documentation does not describe --fresh as deleting every file in the build tree, nor does it establish what a project-specific clean target might do. [S2][S3]

Before a reset, maintainers can inspect the cache with CMake’s -N view mode, which loads it without running configuration or generation. The -L listing option shows non-advanced cache variables; adding A includes advanced ones, and H adds their help text. Internal variables remain outside that listing. For an automated build, record the intended inputs in the configure invocation rather than rely on values left in a working directory. Repeated -D arguments can supply those cache entries again. [S2][S5]

A saved cache file is not interchangeable with a cache-initialization script. CMake’s -C option expects a CMake script containing set commands with CACHE, not a copy of CMakeCache.txt; entries loaded that way take priority over project defaults. If only selected entries need removal, -U accepts a glob pattern, including * and ?. That narrower operation still needs care: the manual warns that removing entries can leave the cache non-working. [S5]

Source documents

  1. CMake v3.24.0 release metadatahttps://api.github.com/repos/Kitware/CMake/releases/tags/v3.24.0
  2. CMake v3.24.0 command-line manualhttps://raw.githubusercontent.com/Kitware/CMake/v3.24.0/Help/manual/cmake.1.rst
  3. CMake 3.24 release notes at v3.24.0https://raw.githubusercontent.com/Kitware/CMake/v3.24.0/Help/release/3.24.rst
  4. CMake v3.24.0 common build optionshttps://raw.githubusercontent.com/Kitware/CMake/v3.24.0/Help/manual/OPTIONS_BUILD.txt