mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-11 09:35:12 +00:00
cmake: Retain cache from presets and command line before re-configure
Triggering a cache reset and re-configure by changing the compiler or CMAKE_TOOLCHAIN_FILE should be a shortcut for cmake --fresh. Losing the cache variables from the command line and especially presets can have an unexpected effect. This commit restores the preset cache variables and reprocesses cache-affecting variables from the immediate command line. Fixes: #27899
This commit is contained in:
@@ -2192,6 +2192,9 @@ bool cmake::SetArgsFromPreset(cmCMakePresetsConfigureArgs const& args,
|
||||
this->SetTraceFile(expandedPreset->TraceRedirect);
|
||||
}
|
||||
|
||||
// Store preset variables in case of cache reset.
|
||||
this->InitialPresetVariables = this->UnprocessedPresetVariables;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2410,6 +2413,15 @@ int cmake::HandleDeleteCacheVariables(
|
||||
this->DeleteCache(this->GetHomeOutputDirectory());
|
||||
// load the empty cache
|
||||
this->LoadCache();
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
// Restore preset cache variables.
|
||||
this->UnprocessedPresetVariables = this->InitialPresetVariables;
|
||||
this->ProcessPresetVariables();
|
||||
#endif
|
||||
// Restore command line cache variables (from this invocation cmake only).
|
||||
bool resetArgsSuccess = this->SetCacheArgs(this->cmdArgs);
|
||||
assert(resetArgsSuccess);
|
||||
(void)resetArgsSuccess;
|
||||
// restore the changed compilers
|
||||
for (SaveCacheEntry const& i : saved) {
|
||||
this->AddCacheEntry(i.key, i.value, i.help, i.type);
|
||||
|
||||
@@ -806,6 +806,8 @@ private:
|
||||
UnprocessedPresetVariables;
|
||||
std::map<std::string, cm::optional<std::string>>
|
||||
UnprocessedPresetEnvironment;
|
||||
std::map<std::string, cm::optional<cmCMakePresetsGraph::CacheVariable>>
|
||||
InitialPresetVariables;
|
||||
#endif
|
||||
|
||||
#if !defined(CMAKE_BOOTSTRAP)
|
||||
|
||||
Reference in New Issue
Block a user