cmCacheManager: Rename GetCacheValue to GetInitializedCacheValue.

Being initialized is a requirement for this method to return something,
and is what differentiates it from using GetIterator with it.GetValue.
This commit is contained in:
Stephen Kelly 2015-04-05 10:28:34 +02:00
parent 1fe7f24c2b
commit 9ada4c0433
8 changed files with 51 additions and 37 deletions

View File

@ -117,7 +117,8 @@ void QCMake::setBinaryDirectory(const QString& _dir)
} }
if ( itm.Find("CMAKE_GENERATOR")) if ( itm.Find("CMAKE_GENERATOR"))
{ {
const char* extraGen = cachem->GetCacheValue("CMAKE_EXTRA_GENERATOR"); const char* extraGen = cachem
->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
std::string curGen = cmExternalMakefileProjectGenerator:: std::string curGen = cmExternalMakefileProjectGenerator::
CreateFullGeneratorName(itm.GetValue(), extraGen? extraGen : ""); CreateFullGeneratorName(itm.GetValue(), extraGen? extraGen : "");
this->setGenerator(QString::fromLocal8Bit(curGen.c_str())); this->setGenerator(QString::fromLocal8Bit(curGen.c_str()));

View File

@ -284,14 +284,16 @@ bool cmCacheManager::LoadCache(const std::string& path,
} }
this->CacheMajorVersion = 0; this->CacheMajorVersion = 0;
this->CacheMinorVersion = 0; this->CacheMinorVersion = 0;
if(const char* cmajor = this->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION")) if(const char* cmajor =
this->GetInitializedCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
{ {
unsigned int v=0; unsigned int v=0;
if(sscanf(cmajor, "%u", &v) == 1) if(sscanf(cmajor, "%u", &v) == 1)
{ {
this->CacheMajorVersion = v; this->CacheMajorVersion = v;
} }
if(const char* cminor = this->GetCacheValue("CMAKE_CACHE_MINOR_VERSION")) if(const char* cminor =
this->GetInitializedCacheValue("CMAKE_CACHE_MINOR_VERSION"))
{ {
if(sscanf(cminor, "%u", &v) == 1) if(sscanf(cminor, "%u", &v) == 1)
{ {
@ -313,10 +315,11 @@ bool cmCacheManager::LoadCache(const std::string& path,
} }
// check to make sure the cache directory has not // check to make sure the cache directory has not
// been moved // been moved
if ( internal && this->GetCacheValue("CMAKE_CACHEFILE_DIR") ) const char* oldDir = this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR");
if (internal && oldDir)
{ {
std::string currentcwd = path; std::string currentcwd = path;
std::string oldcwd = this->GetCacheValue("CMAKE_CACHEFILE_DIR"); std::string oldcwd = oldDir;
cmSystemTools::ConvertToUnixSlashes(currentcwd); cmSystemTools::ConvertToUnixSlashes(currentcwd);
currentcwd += "/CMakeCache.txt"; currentcwd += "/CMakeCache.txt";
oldcwd += "/CMakeCache.txt"; oldcwd += "/CMakeCache.txt";
@ -325,7 +328,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
std::string message = std::string message =
std::string("The current CMakeCache.txt directory ") + std::string("The current CMakeCache.txt directory ") +
currentcwd + std::string(" is different than the directory ") + currentcwd + std::string(" is different than the directory ") +
std::string(this->GetCacheValue("CMAKE_CACHEFILE_DIR")) + std::string(this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR")) +
std::string(" where CMakeCache.txt was created. This may result " std::string(" where CMakeCache.txt was created. This may result "
"in binaries being created in the wrong place. If you " "in binaries being created in the wrong place. If you "
"are not sure, reedit the CMakeCache.txt"); "are not sure, reedit the CMakeCache.txt");
@ -655,7 +658,8 @@ cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(
return CacheIterator(*this, key); return CacheIterator(*this, key);
} }
const char* cmCacheManager::GetCacheValue(const std::string& key) const const char*
cmCacheManager::GetInitializedCacheValue(const std::string& key) const
{ {
CacheEntryMap::const_iterator i = this->Cache.find(key); CacheEntryMap::const_iterator i = this->Cache.find(key);
if(i != this->Cache.end() && if(i != this->Cache.end() &&

View File

@ -137,7 +137,7 @@ public:
CacheEntryType& type); CacheEntryType& type);
///! Get a value from the cache given a key ///! Get a value from the cache given a key
const char* GetCacheValue(const std::string& key) const; const char* GetInitializedCacheValue(const std::string& key) const;
/** Get the version of CMake that wrote the cache. */ /** Get the version of CMake that wrote the cache. */
unsigned int GetCacheMajorVersion() const unsigned int GetCacheMajorVersion() const

View File

@ -90,7 +90,8 @@ char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key,
} }
if ( strcmp(key, "CACHE") == 0 ) if ( strcmp(key, "CACHE") == 0 )
{ {
if(const char* c = this->Makefile->GetCacheManager()->GetCacheValue(var)) if(const char* c = this->Makefile->GetCacheManager()
->GetInitializedCacheValue(var))
{ {
if(this->EscapeQuotes) if(this->EscapeQuotes)
{ {

View File

@ -205,7 +205,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_"; std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_";
cacheEntryName += envVar; cacheEntryName += envVar;
const char* cacheValue = mf->GetCacheManager()->GetCacheValue( const char* cacheValue = mf->GetCacheManager()->GetInitializedCacheValue(
cacheEntryName); cacheEntryName);
// now we have both, decide which one to use // now we have both, decide which one to use

View File

@ -179,7 +179,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
return; return;
} }
const char* cname = this->GetCMakeInstance()-> const char* cname = this->GetCMakeInstance()->
GetCacheManager()->GetCacheValue(langComp); GetCacheManager()->GetInitializedCacheValue(langComp);
std::string changeVars; std::string changeVars;
if(cname && !optional) if(cname && !optional)
{ {
@ -1641,7 +1641,7 @@ int cmGlobalGenerator::TryCompile(const std::string& srcdir,
// and there is a good chance that the try compile stuff will // and there is a good chance that the try compile stuff will
// take the bulk of the time, so try and guess some progress // take the bulk of the time, so try and guess some progress
// by getting closer and closer to 100 without actually getting there. // by getting closer and closer to 100 without actually getting there.
if (!this->CMakeInstance->GetCacheManager()->GetCacheValue if (!this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue
("CMAKE_NUMBER_OF_LOCAL_GENERATORS")) ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
{ {
// If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
@ -1839,7 +1839,7 @@ void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg)
// update progress // update progress
// estimate how many lg there will be // estimate how many lg there will be
const char *numGenC = const char *numGenC =
this->CMakeInstance->GetCacheManager()->GetCacheValue this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue
("CMAKE_NUMBER_OF_LOCAL_GENERATORS"); ("CMAKE_NUMBER_OF_LOCAL_GENERATORS");
if (!numGenC) if (!numGenC)

View File

@ -2432,7 +2432,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
this->Internal->VarUsageStack.top().insert(name); this->Internal->VarUsageStack.top().insert(name);
if(!def) if(!def)
{ {
def = this->GetCacheManager()->GetCacheValue(name); def = this->GetCacheManager()->GetInitializedCacheValue(name);
} }
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
if(cmVariableWatch* vv = this->GetVariableWatch()) if(cmVariableWatch* vv = this->GetVariableWatch())
@ -2457,7 +2457,7 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
const char* def = this->Internal->VarStack.top().Get(name); const char* def = this->Internal->VarStack.top().Get(name);
if(!def) if(!def)
{ {
def = this->GetCacheManager()->GetCacheValue(name); def = this->GetCacheManager()->GetInitializedCacheValue(name);
} }
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
cmVariableWatch* vv = this->GetVariableWatch(); cmVariableWatch* vv = this->GetVariableWatch();
@ -2835,7 +2835,8 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
value = cmSystemTools::GetEnv(lookup.c_str()); value = cmSystemTools::GetEnv(lookup.c_str());
break; break;
case CACHE: case CACHE:
value = this->GetCacheManager()->GetCacheValue(lookup); value = this->GetCacheManager()
->GetInitializedCacheValue(lookup);
break; break;
} }
// Get the string we're meant to append to. // Get the string we're meant to append to.
@ -4903,7 +4904,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
(status == cmPolicies::WARN || status == cmPolicies::OLD)) (status == cmPolicies::WARN || status == cmPolicies::OLD))
{ {
if(!(this->GetCacheManager() if(!(this->GetCacheManager()
->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))) ->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
{ {
// Set it to 2.4 because that is the last version where the // Set it to 2.4 because that is the last version where the
// variable had meaning. // variable had meaning.

View File

@ -344,7 +344,8 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
std::string cachedValue; std::string cachedValue;
if(this->WarnUnusedCli) if(this->WarnUnusedCli)
{ {
if(const char *v = this->CacheManager->GetCacheValue(var)) if(const char *v = this->CacheManager
->GetInitializedCacheValue(var))
{ {
haveValue = true; haveValue = true;
cachedValue = v; cachedValue = v;
@ -357,7 +358,8 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
if(this->WarnUnusedCli) if(this->WarnUnusedCli)
{ {
if (!haveValue || if (!haveValue ||
cachedValue != this->CacheManager->GetCacheValue(var)) cachedValue != this->CacheManager
->GetInitializedCacheValue(var))
{ {
this->WatchUnusedCli(var); this->WatchUnusedCli(var);
} }
@ -1203,10 +1205,10 @@ int cmake::DoPreConfigureChecks()
} }
// do a sanity check on some values // do a sanity check on some values
if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY")) if(this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"))
{ {
std::string cacheStart = std::string cacheStart =
this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"); this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
cacheStart += "/CMakeLists.txt"; cacheStart += "/CMakeLists.txt";
std::string currentStart = this->GetHomeDirectory(); std::string currentStart = this->GetHomeDirectory();
currentStart += "/CMakeLists.txt"; currentStart += "/CMakeLists.txt";
@ -1355,9 +1357,9 @@ int cmake::ActualConfigure()
if(!this->GlobalGenerator) if(!this->GlobalGenerator)
{ {
const char* genName = const char* genName =
this->CacheManager->GetCacheValue("CMAKE_GENERATOR"); this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR");
const char* extraGenName = const char* extraGenName =
this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR"); this->CacheManager->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
if(genName) if(genName)
{ {
std::string fullName = cmExternalMakefileProjectGenerator:: std::string fullName = cmExternalMakefileProjectGenerator::
@ -1435,7 +1437,8 @@ int cmake::ActualConfigure()
} }
} }
const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR"); const char* genName = this->CacheManager
->GetInitializedCacheValue("CMAKE_GENERATOR");
if(genName) if(genName)
{ {
if(!this->GlobalGenerator->MatchesGeneratorName(genName)) if(!this->GlobalGenerator->MatchesGeneratorName(genName))
@ -1451,7 +1454,7 @@ int cmake::ActualConfigure()
return -2; return -2;
} }
} }
if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR")) if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"))
{ {
this->CacheManager->AddCacheEntry("CMAKE_GENERATOR", this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
this->GlobalGenerator->GetName().c_str(), this->GlobalGenerator->GetName().c_str(),
@ -1464,7 +1467,7 @@ int cmake::ActualConfigure()
} }
if(const char* platformName = if(const char* platformName =
this->CacheManager->GetCacheValue("CMAKE_GENERATOR_PLATFORM")) this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM"))
{ {
if(this->GeneratorPlatform.empty()) if(this->GeneratorPlatform.empty())
{ {
@ -1492,7 +1495,7 @@ int cmake::ActualConfigure()
} }
if(const char* tsName = if(const char* tsName =
this->CacheManager->GetCacheValue("CMAKE_GENERATOR_TOOLSET")) this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET"))
{ {
if(this->GeneratorToolset.empty()) if(this->GeneratorToolset.empty())
{ {
@ -1546,16 +1549,18 @@ int cmake::ActualConfigure()
// project requires compatibility with CMake 2.4. We detect this // project requires compatibility with CMake 2.4. We detect this
// here by looking for the old CMAKE_BACKWARDS_COMPATIBILITY // here by looking for the old CMAKE_BACKWARDS_COMPATIBILITY
// variable created when CMP0001 is not set to NEW. // 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 this->CacheManager->AddCacheEntry
("LIBRARY_OUTPUT_PATH", "", ("LIBRARY_OUTPUT_PATH", "",
"Single output directory for building all libraries.", "Single output directory for building all libraries.",
cmCacheManager::PATH); cmCacheManager::PATH);
} }
if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH")) if(!this->CacheManager
->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH"))
{ {
this->CacheManager->AddCacheEntry this->CacheManager->AddCacheEntry
("EXECUTABLE_OUTPUT_PATH", "", ("EXECUTABLE_OUTPUT_PATH", "",
@ -1563,7 +1568,8 @@ int cmake::ActualConfigure()
cmCacheManager::PATH); cmCacheManager::PATH);
} }
} }
if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS")) if(!this->CacheManager
->GetInitializedCacheValue("CMAKE_USE_RELATIVE_PATHS"))
{ {
this->CacheManager->AddCacheEntry this->CacheManager->AddCacheEntry
("CMAKE_USE_RELATIVE_PATHS", "OFF", ("CMAKE_USE_RELATIVE_PATHS", "OFF",
@ -1578,9 +1584,9 @@ int cmake::ActualConfigure()
} }
if(cmSystemTools::GetFatalErrorOccured() && if(cmSystemTools::GetFatalErrorOccured() &&
(!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") || (!this->CacheManager->GetInitializedCacheValue("CMAKE_MAKE_PROGRAM") ||
cmSystemTools::IsOff(this->CacheManager-> 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 // We must have a bad generator selection. Wipe the cache entry so the
// user can select another. // user can select another.
@ -1796,7 +1802,7 @@ void cmake::AddCacheEntry(const std::string& key, const char* value,
const char* cmake::GetCacheDefinition(const std::string& name) const const char* cmake::GetCacheDefinition(const std::string& name) const
{ {
return this->CacheManager->GetCacheValue(name); return this->CacheManager->GetInitializedCacheValue(name);
} }
void cmake::AddDefaultCommands() void cmake::AddDefaultCommands()
@ -1956,7 +1962,8 @@ void cmake::UpdateConversionPathTable()
{ {
// Update the path conversion table with any specified file: // Update the path conversion table with any specified file:
const char* tablepath = const char* tablepath =
this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE"); this->CacheManager
->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
if(tablepath) if(tablepath)
{ {
@ -2190,7 +2197,7 @@ void cmake::TruncateOutputLog(const char* fname)
{ {
return; return;
} }
if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") ) if ( !this->CacheManager->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR") )
{ {
cmSystemTools::RemoveFile(fullPath); cmSystemTools::RemoveFile(fullPath);
return; return;
@ -2469,7 +2476,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
// we have to find the module directory, so we can copy the files // we have to find the module directory, so we can copy the files
this->AddCMakePaths(); this->AddCMakePaths();
std::string modulesPath = std::string modulesPath =
this->CacheManager->GetCacheValue("CMAKE_ROOT"); this->CacheManager->GetInitializedCacheValue("CMAKE_ROOT");
modulesPath += "/Modules"; modulesPath += "/Modules";
std::string inFile = modulesPath; std::string inFile = modulesPath;
inFile += "/SystemInformation.cmake"; inFile += "/SystemInformation.cmake";