| 2315 | }; |
| 2316 | |
| 2317 | int cmake::HandleDeleteCacheVariables(std::string const& var) |
| 2318 | { |
| 2319 | cmList argsSplit{ var, cmList::EmptyElements::Yes }; |
| 2320 | // erase the property to avoid infinite recursion |
| 2321 | this->State->SetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", ""); |
| 2322 | if (this->GetIsInTryCompile()) { |
| 2323 | return 0; |
| 2324 | } |
| 2325 | std::vector<SaveCacheEntry> saved; |
| 2326 | std::ostringstream warning; |
| 2327 | warning |
| 2328 | << "You have changed variables that require your cache to be deleted.\n" |
| 2329 | "Configure will be re-run and you may have to reset some variables.\n" |
| 2330 | "The following variables have changed:\n"; |
| 2331 | for (auto i = argsSplit.begin(); i != argsSplit.end(); ++i) { |
| 2332 | SaveCacheEntry save; |
| 2333 | save.key = *i; |
| 2334 | warning << *i << "= "; |
| 2335 | i++; |
| 2336 | if (i != argsSplit.end()) { |
| 2337 | save.value = *i; |
| 2338 | warning << *i << '\n'; |
| 2339 | } else { |
| 2340 | warning << '\n'; |
| 2341 | i -= 1; |
| 2342 | } |
| 2343 | cmValue existingValue = this->State->GetCacheEntryValue(save.key); |
| 2344 | if (existingValue) { |
| 2345 | save.type = this->State->GetCacheEntryType(save.key); |
| 2346 | if (cmValue help = |
| 2347 | this->State->GetCacheEntryProperty(save.key, "HELPSTRING")) { |
| 2348 | save.help = *help; |
| 2349 | } |
| 2350 | } else { |
| 2351 | save.type = cmStateEnums::CacheEntryType::UNINITIALIZED; |
| 2352 | } |
| 2353 | saved.push_back(std::move(save)); |
| 2354 | } |
| 2355 | |
| 2356 | // remove the cache |
| 2357 | this->DeleteCache(this->GetHomeOutputDirectory()); |
| 2358 | // load the empty cache |
| 2359 | this->LoadCache(); |
| 2360 | // restore the changed compilers |
| 2361 | for (SaveCacheEntry const& i : saved) { |
| 2362 | this->AddCacheEntry(i.key, i.value, i.help, i.type); |
| 2363 | } |
| 2364 | cmSystemTools::Message(warning.str()); |
| 2365 | // avoid reconfigure if there were errors |
| 2366 | if (!cmSystemTools::GetErrorOccurredFlag()) { |
| 2367 | // re-run configure |
| 2368 | return this->Configure(); |
| 2369 | } |
| 2370 | return 0; |
| 2371 | } |
| 2372 | |
| 2373 | int cmake::Configure() |
| 2374 | { |
no test coverage detected