diff options
author | Brad King <brad.king@kitware.com> | 2015-04-09 15:32:36 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2015-04-09 15:32:36 (GMT) |
commit | 26d6c095d6117d7f9cb02378acb74d86efe59d0b (patch) | |
tree | 2b35636c949b7e1450eaf1a6f88839fba16cfdb9 /Source/cmake.cxx | |
parent | 81f627d53bd3bdb50379eb3e1b9cd87bb0ff0bbc (diff) | |
parent | ba404938a202b51bb82bff8692ed08e53b061ad4 (diff) | |
download | CMake-26d6c095d6117d7f9cb02378acb74d86efe59d0b.zip CMake-26d6c095d6117d7f9cb02378acb74d86efe59d0b.tar.gz CMake-26d6c095d6117d7f9cb02378acb74d86efe59d0b.tar.bz2 |
Merge topic 'refactor-cache-api'
ba404938 cmCacheManager: Port consumers to non-iterator API.
f3922a9a Port QtDialog to non-iterator cache API.
3e6a76e4 Port CursesDialog to non-iterator cache API.
9e641567 cmMakefile: Port away from CacheEntry.Initialized.
1e2dbfce cmCacheManager: Add non-iterator-based API.
60a62a91 cmCacheManager: Return a C string from GetValue.
77f2807c cmCacheManager: Rename GetCacheValue to GetInitializedCacheValue.
14973054 Add API for cache loading, deleting and saving to the cmake class.
1f2c12eb cmMakefile: Remove cache version accessors.
97c50a8d cmMakefile: Simplify GetDefinitions implementation.
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 166 |
1 files changed, 101 insertions, 65 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 05cfea8..7595155 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -344,7 +344,8 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) std::string cachedValue; if(this->WarnUnusedCli) { - if(const char *v = this->CacheManager->GetCacheValue(var)) + if(const char *v = this->CacheManager + ->GetInitializedCacheValue(var)) { haveValue = true; cachedValue = v; @@ -357,7 +358,8 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) if(this->WarnUnusedCli) { if (!haveValue || - cachedValue != this->CacheManager->GetCacheValue(var)) + cachedValue != this->CacheManager + ->GetInitializedCacheValue(var)) { this->WatchUnusedCli(var); } @@ -401,17 +403,18 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) cmsys::Glob::PatternToRegex(entryPattern, true, true).c_str()); //go through all cache entries and collect the vars which will be removed std::vector<std::string> entriesToDelete; - cmCacheManager::CacheIterator it = - this->CacheManager->GetCacheIterator(); - for ( it.Begin(); !it.IsAtEnd(); it.Next() ) + std::vector<std::string> cacheKeys = + this->CacheManager->GetCacheEntryKeys(); + for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); + it != cacheKeys.end(); ++it) { - cmCacheManager::CacheEntryType t = it.GetType(); + cmCacheManager::CacheEntryType t = + this->CacheManager->GetCacheEntryType(*it); if(t != cmCacheManager::STATIC) { - std::string entryName = it.GetName(); - if (regex.find(entryName.c_str())) + if (regex.find(it->c_str())) { - entriesToDelete.push_back(entryName); + entriesToDelete.push_back(*it); } } } @@ -915,16 +918,18 @@ void cmake::SetDirectoriesFromFile(const char* arg) // If there is a CMakeCache.txt file, use its settings. if(!cachePath.empty()) { - cmCacheManager* cachem = this->GetCacheManager(); - cmCacheManager::CacheIterator it = cachem->NewIterator(); - if(cachem->LoadCache(cachePath) && - it.Find("CMAKE_HOME_DIRECTORY")) + if(this->LoadCache(cachePath)) { - this->SetHomeOutputDirectory(cachePath); - this->SetStartOutputDirectory(cachePath); - this->SetHomeDirectory(it.GetValue()); - this->SetStartDirectory(it.GetValue()); - return; + const char* existingValue = + this->CacheManager->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"); + if (existingValue) + { + this->SetHomeOutputDirectory(cachePath); + this->SetStartOutputDirectory(cachePath); + this->SetHomeDirectory(existingValue); + this->SetStartDirectory(existingValue); + return; + } } } @@ -1203,10 +1208,10 @@ int cmake::DoPreConfigureChecks() } // do a sanity check on some values - if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY")) + if(this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY")) { std::string cacheStart = - this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"); + this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"); cacheStart += "/CMakeLists.txt"; std::string currentStart = this->GetHomeDirectory(); currentStart += "/CMakeLists.txt"; @@ -1355,9 +1360,9 @@ int cmake::ActualConfigure() if(!this->GlobalGenerator) { const char* genName = - this->CacheManager->GetCacheValue("CMAKE_GENERATOR"); + this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"); const char* extraGenName = - this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR"); + this->CacheManager->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR"); if(genName) { std::string fullName = cmExternalMakefileProjectGenerator:: @@ -1435,7 +1440,8 @@ int cmake::ActualConfigure() } } - const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR"); + const char* genName = this->CacheManager + ->GetInitializedCacheValue("CMAKE_GENERATOR"); if(genName) { if(!this->GlobalGenerator->MatchesGeneratorName(genName)) @@ -1451,7 +1457,7 @@ int cmake::ActualConfigure() return -2; } } - if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR")) + if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR")) { this->CacheManager->AddCacheEntry("CMAKE_GENERATOR", this->GlobalGenerator->GetName().c_str(), @@ -1464,7 +1470,7 @@ int cmake::ActualConfigure() } if(const char* platformName = - this->CacheManager->GetCacheValue("CMAKE_GENERATOR_PLATFORM")) + this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM")) { if(this->GeneratorPlatform.empty()) { @@ -1492,7 +1498,7 @@ int cmake::ActualConfigure() } if(const char* tsName = - this->CacheManager->GetCacheValue("CMAKE_GENERATOR_TOOLSET")) + this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET")) { if(this->GeneratorToolset.empty()) { @@ -1546,16 +1552,18 @@ int cmake::ActualConfigure() // project requires compatibility with CMake 2.4. We detect this // here by looking for the old CMAKE_BACKWARDS_COMPATIBILITY // variable created when CMP0001 is not set to NEW. - if(this->GetCacheManager()->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")) + if(this->GetCacheManager() + ->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")) { - if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH")) + if(!this->CacheManager->GetInitializedCacheValue("LIBRARY_OUTPUT_PATH")) { this->CacheManager->AddCacheEntry ("LIBRARY_OUTPUT_PATH", "", "Single output directory for building all libraries.", cmCacheManager::PATH); } - if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH")) + if(!this->CacheManager + ->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH")) { this->CacheManager->AddCacheEntry ("EXECUTABLE_OUTPUT_PATH", "", @@ -1563,24 +1571,25 @@ int cmake::ActualConfigure() cmCacheManager::PATH); } } - if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS")) + if(!this->CacheManager + ->GetInitializedCacheValue("CMAKE_USE_RELATIVE_PATHS")) { this->CacheManager->AddCacheEntry ("CMAKE_USE_RELATIVE_PATHS", "OFF", "If true, cmake will use relative paths in makefiles and projects.", cmCacheManager::BOOL); - cmCacheManager::CacheIterator it = - this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS"); - if ( !it.PropertyExists("ADVANCED") ) + if (!this->CacheManager->GetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS", + "ADVANCED")) { - it.SetProperty("ADVANCED", "1"); + this->CacheManager->SetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS", + "ADVANCED", "1"); } } if(cmSystemTools::GetFatalErrorOccured() && - (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") || + (!this->CacheManager->GetInitializedCacheValue("CMAKE_MAKE_PROGRAM") || cmSystemTools::IsOff(this->CacheManager-> - GetCacheValue("CMAKE_MAKE_PROGRAM")))) + GetInitializedCacheValue("CMAKE_MAKE_PROGRAM")))) { // We must have a bad generator selection. Wipe the cache entry so the // user can select another. @@ -1796,7 +1805,7 @@ void cmake::AddCacheEntry(const std::string& key, const char* value, const char* cmake::GetCacheDefinition(const std::string& name) const { - return this->CacheManager->GetCacheValue(name); + return this->CacheManager->GetInitializedCacheValue(name); } void cmake::AddDefaultCommands() @@ -1860,10 +1869,18 @@ void cmake::AddDefaultGenerators() #endif } +bool cmake::ParseCacheEntry(const std::string& entry, + std::string& var, + std::string& value, + cmCacheManager::CacheEntryType& type) +{ + return cmCacheManager::ParseEntry(entry, var, value, type); +} + int cmake::LoadCache() { // could we not read the cache - if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory())) + if (!this->LoadCache(this->GetHomeOutputDirectory())) { // if it does exist, but isn't readable then warn the user std::string cacheFile = this->GetHomeOutputDirectory(); @@ -1886,6 +1903,28 @@ int cmake::LoadCache() return 0; } +bool cmake::LoadCache(const std::string& path) +{ + return this->CacheManager->LoadCache(path); +} + +bool cmake::LoadCache(const std::string& path, bool internal, + std::set<std::string>& excludes, + std::set<std::string>& includes) +{ + return this->CacheManager->LoadCache(path, internal, excludes, includes); +} + +bool cmake::SaveCache(const std::string& path) +{ + return this->CacheManager->SaveCache(path); +} + +bool cmake::DeleteCache(const std::string& path) +{ + return this->CacheManager->DeleteCache(path); +} + void cmake::SetProgressCallback(ProgressCallbackType f, void *cd) { this->ProgressCallback = f; @@ -1926,7 +1965,8 @@ void cmake::UpdateConversionPathTable() { // Update the path conversion table with any specified file: const char* tablepath = - this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE"); + this->CacheManager + ->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE"); if(tablepath) { @@ -2160,7 +2200,7 @@ void cmake::TruncateOutputLog(const char* fname) { return; } - if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") ) + if ( !this->CacheManager->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR") ) { cmSystemTools::RemoveFile(fullPath); return; @@ -2277,17 +2317,9 @@ const char *cmake::GetProperty(const std::string& prop, std::string output = ""; if ( prop == "CACHE_VARIABLES" ) { - cmCacheManager::CacheIterator cit = - this->GetCacheManager()->GetCacheIterator(); - for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() ) - { - if (!output.empty()) - { - output += ";"; - } - output += cit.GetName(); - } - this->SetProperty("CACHE_VARIABLES", output.c_str()); + std::vector<std::string> cacheKeys = + this->CacheManager->GetCacheEntryKeys(); + this->SetProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str()); } else if ( prop == "COMMANDS" ) { @@ -2439,7 +2471,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args) // we have to find the module directory, so we can copy the files this->AddCMakePaths(); std::string modulesPath = - this->CacheManager->GetCacheValue("CMAKE_ROOT"); + this->CacheManager->GetInitializedCacheValue("CMAKE_ROOT"); modulesPath += "/Modules"; std::string inFile = modulesPath; inFile += "/SystemInformation.cmake"; @@ -2649,9 +2681,9 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text, if(t == cmake::AUTHOR_WARNING) { // Allow suppression of these warnings. - cmCacheManager::CacheIterator it = this->CacheManager - ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); - if(!it.IsAtEnd() && it.GetValueAsBool()) + const char* suppress = this->CacheManager->GetCacheEntryValue( + "CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); + if(suppress && cmSystemTools::IsOn(suppress)) { return; } @@ -2764,38 +2796,42 @@ int cmake::Build(const std::string& dir, } std::string cachePath = dir; cmSystemTools::ConvertToUnixSlashes(cachePath); - cmCacheManager* cachem = this->GetCacheManager(); - cmCacheManager::CacheIterator it = cachem->NewIterator(); - if(!cachem->LoadCache(cachePath)) + if(!this->LoadCache(cachePath)) { std::cerr << "Error: could not load cache\n"; return 1; } - if(!it.Find("CMAKE_GENERATOR")) + const char* cachedGenerator = + this->CacheManager->GetCacheEntryValue("CMAKE_GENERATOR"); + if(!cachedGenerator) { std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n"; return 1; } cmsys::auto_ptr<cmGlobalGenerator> gen( - this->CreateGlobalGenerator(it.GetValue())); + this->CreateGlobalGenerator(cachedGenerator)); if(!gen.get()) { std::cerr << "Error: could create CMAKE_GENERATOR \"" - << it.GetValue() << "\"\n"; + << cachedGenerator << "\"\n"; return 1; } std::string output; std::string projName; - if(!it.Find("CMAKE_PROJECT_NAME")) + const char* cachedProjectName = + this->CacheManager->GetCacheEntryValue("CMAKE_PROJECT_NAME"); + if(!cachedProjectName) { std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n"; return 1; } - projName = it.GetValue(); + projName = cachedProjectName; bool verbose = false; - if(it.Find("CMAKE_VERBOSE_MAKEFILE")) + const char* cachedVerbose = + this->CacheManager->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE"); + if(cachedVerbose) { - verbose = it.GetValueAsBool(); + verbose = cmSystemTools::IsOn(cachedVerbose); } return gen->Build("", dir, projName, target, |