MCPcopy Create free account
hub / github.com/Kitware/CMake / SaveCache

Method SaveCache

Source/cmCacheManager.cxx:221–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221bool cmCacheManager::SaveCache(std::string const& path, cmMessenger* messenger)
222{
223 std::string cacheFile = cmStrCat(path, "/CMakeCache.txt");
224 cmGeneratedFileStream fout(cacheFile);
225 fout.SetCopyIfDifferent(true);
226 if (!fout) {
227 cmSystemTools::Error(
228 cmStrCat("Unable to open cache file for save. ", std::move(cacheFile)));
229 cmSystemTools::ReportLastSystemError("");
230 return false;
231 }
232 // before writing the cache, update the version numbers
233 // to the
234 this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION",
235 std::to_string(cmVersion::GetMajorVersion()),
236 "Major version of cmake used to create the "
237 "current loaded cache",
238 cmStateEnums::INTERNAL);
239 this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION",
240 std::to_string(cmVersion::GetMinorVersion()),
241 "Minor version of cmake used to create the "
242 "current loaded cache",
243 cmStateEnums::INTERNAL);
244 this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION",
245 std::to_string(cmVersion::GetPatchVersion()),
246 "Patch version of cmake used to create the "
247 "current loaded cache",
248 cmStateEnums::INTERNAL);
249
250 // Let us store the current working directory so that if somebody
251 // Copies it, he will not be surprised
252 std::string currentcwd = path;
253 if (currentcwd[0] >= 'A' && currentcwd[0] <= 'Z' && currentcwd[1] == ':') {
254 // Cast added to avoid compiler warning. Cast is ok because
255 // value is guaranteed to fit in char by the above if...
256 currentcwd[0] = static_cast<char>(currentcwd[0] - 'A' + 'a');
257 }
258 cmSystemTools::ConvertToUnixSlashes(currentcwd);
259 this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd,
260 "This is the directory where this CMakeCache.txt"
261 " was created",
262 cmStateEnums::INTERNAL);
263
264 /* clang-format off */
265 fout << "# This is the CMakeCache file.\n"
266 "# For build in directory: " << currentcwd << "\n"
267 "# It was generated by CMake: "
268 << cmSystemTools::GetCMakeCommand()
269 << "\n"
270 "# You can edit this file to change values found and used by cmake."
271 "\n"
272 "# If you do not want to change any of the values, simply exit the "
273 "editor.\n"
274 "# If you do want to change a value, simply edit, save, and exit "
275 "the editor.\n"
276 "# The syntax for the file is as follows:\n"
277 "# KEY:TYPE=VALUE\n"
278 "# KEY is the name of a variable in the cache.\n"

Callers

nothing calls this directly

Calls 12

AddCacheEntryMethod · 0.95
WritePropertyEntriesMethod · 0.95
moveFunction · 0.85
to_stringFunction · 0.85
SetCopyIfDifferentMethod · 0.80
CloseMethod · 0.80
c_strMethod · 0.80
cmStrCatFunction · 0.70
ErrorClass · 0.70
GetPropertyMethod · 0.45
GetTypeMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected