diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 586070b87..08270375e 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -18,6 +18,7 @@ #include "cmGlobalGenerator.h" #include #include "cmCTestTestHandler.h" +#include "cmCacheManager.h" //---------------------------------------------------------------------- cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler() @@ -254,7 +255,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) cm.SetGeneratorToolset(this->BuildGeneratorToolset); // Load the cache to make CMAKE_MAKE_PROGRAM available. - cm.LoadCache(this->BinaryDir); + cm.GetCacheManager()->LoadCache(this->BinaryDir); } else { diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx index 4f028c42a..682f95f9e 100644 --- a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx +++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx @@ -18,9 +18,6 @@ #include "cmCursesFilePathWidget.h" #include "cmCursesDummyWidget.h" #include "../cmSystemTools.h" -#include "../cmake.h" - -#include cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( const std::string& key, @@ -35,7 +32,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( } cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( - const std::string& key, cmake *cm, bool isNew, + const std::string& key, const cmCacheManager::CacheIterator& it, bool isNew, int labelwidth, int entrywidth) : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth) { @@ -50,13 +47,11 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( } this->Entry = 0; - const char* value = cm->GetCacheManager()->GetCacheEntryValue(key); - assert(value); - switch (cm->GetCacheManager()->GetCacheEntryType(key)) + switch ( it.GetType() ) { - case cmCacheManager::BOOL: + case cmCacheManager::BOOL: this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1); - if (cmSystemTools::IsOn(value)) + if (cmSystemTools::IsOn(it.GetValue().c_str())) { static_cast(this->Entry)->SetValueAsBool(true); } @@ -67,40 +62,40 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( break; case cmCacheManager::PATH: this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1); - static_cast(this->Entry)->SetString(value); + static_cast(this->Entry)->SetString( + it.GetValue()); break; case cmCacheManager::FILEPATH: this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1); - static_cast(this->Entry)->SetString(value); + static_cast(this->Entry)->SetString( + it.GetValue()); break; case cmCacheManager::STRING: - { - const char* stringsProp = cm->GetCacheManager() - ->GetCacheEntryProperty(key, "STRINGS"); - if(stringsProp) + if(it.PropertyExists("STRINGS")) { cmCursesOptionsWidget* ow = new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1); this->Entry = ow; std::vector options; - cmSystemTools::ExpandListArgument(stringsProp, options); + cmSystemTools::ExpandListArgument( + std::string(it.GetProperty("STRINGS")), options); for(std::vector::iterator si = options.begin(); si != options.end(); ++si) { ow->AddOption(*si); } - ow->SetOption(value); + ow->SetOption(it.GetValue()); } else { this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1); - static_cast(this->Entry)->SetString(value); + static_cast(this->Entry)->SetString( + it.GetValue()); } break; - } case cmCacheManager::UNINITIALIZED: cmSystemTools::Error("Found an undefined variable: ", - key.c_str()); + it.GetName().c_str()); break; default: // TODO : put warning message here diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.h b/Source/CursesDialog/cmCursesCacheEntryComposite.h index dc4ee4af0..7cdf13bad 100644 --- a/Source/CursesDialog/cmCursesCacheEntryComposite.h +++ b/Source/CursesDialog/cmCursesCacheEntryComposite.h @@ -21,7 +21,7 @@ public: cmCursesCacheEntryComposite(const std::string& key, int labelwidth, int entrywidth); cmCursesCacheEntryComposite(const std::string& key, - cmake *cm, + const cmCacheManager::CacheIterator& it, bool isNew, int labelwidth, int entrywidth); ~cmCursesCacheEntryComposite(); const char* GetValue(); diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 833d54038..d60062e5b 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -111,17 +111,13 @@ void cmCursesMainForm::InitializeUI() // Count non-internal and non-static entries int count=0; - std::vector cacheKeys = - this->CMakeInstance->GetCacheManager()->GetCacheEntryKeys(); - - for(std::vector::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) + for(cmCacheManager::CacheIterator i = + this->CMakeInstance->GetCacheManager()->NewIterator(); + !i.IsAtEnd(); i.Next()) { - cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager() - ->GetCacheEntryType(*it); - if (t != cmCacheManager::INTERNAL && - t != cmCacheManager::STATIC && - t != cmCacheManager::UNINITIALIZED) + if ( i.GetType() != cmCacheManager::INTERNAL && + i.GetType() != cmCacheManager::STATIC && + i.GetType() != cmCacheManager::UNINITIALIZED) { ++count; } @@ -143,49 +139,45 @@ void cmCursesMainForm::InitializeUI() // Create the composites. // First add entries which are new - for(std::vector::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) + for(cmCacheManager::CacheIterator i = + this->CMakeInstance->GetCacheManager()->NewIterator(); + !i.IsAtEnd(); i.Next()) { - std::string key = *it; - cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager() - ->GetCacheEntryType(*it); - if (t == cmCacheManager::INTERNAL || - t == cmCacheManager::STATIC || - t == cmCacheManager::UNINITIALIZED ) + std::string key = i.GetName(); + if ( i.GetType() == cmCacheManager::INTERNAL || + i.GetType() == cmCacheManager::STATIC || + i.GetType() == cmCacheManager::UNINITIALIZED ) { continue; } if (!this->LookForCacheEntry(key)) { - newEntries->push_back(new cmCursesCacheEntryComposite(key, - this->CMakeInstance, - true, 30, - entrywidth)); + newEntries->push_back(new cmCursesCacheEntryComposite(key, i, + true, 30, + entrywidth)); this->OkToGenerate = false; } } // then add entries which are old - for(std::vector::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) + for(cmCacheManager::CacheIterator i = + this->CMakeInstance->GetCacheManager()->NewIterator(); + !i.IsAtEnd(); i.Next()) { - std::string key = *it; - cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager() - ->GetCacheEntryType(*it); - if (t == cmCacheManager::INTERNAL || - t == cmCacheManager::STATIC || - t == cmCacheManager::UNINITIALIZED ) + std::string key = i.GetName(); + if ( i.GetType() == cmCacheManager::INTERNAL || + i.GetType() == cmCacheManager::STATIC || + i.GetType() == cmCacheManager::UNINITIALIZED ) { continue; } if (this->LookForCacheEntry(key)) { - newEntries->push_back(new cmCursesCacheEntryComposite(key, - this->CMakeInstance, - false, 30, - entrywidth)); + newEntries->push_back(new cmCursesCacheEntryComposite(key, i, + false, 30, + entrywidth)); } } } @@ -224,13 +216,10 @@ void cmCursesMainForm::RePost() std::vector::iterator it; for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - const char* existingValue = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryValue((*it)->GetValue()); - bool advanced = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED"); - if (!existingValue || (!this->AdvancedMode && advanced)) + cmCacheManager::CacheIterator mit = + this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -256,13 +245,10 @@ void cmCursesMainForm::RePost() std::vector::iterator it; for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - const char* existingValue = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryValue((*it)->GetValue()); - bool advanced = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED"); - if (!existingValue || (!this->AdvancedMode && advanced)) + cmCacheManager::CacheIterator mit = + this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -328,13 +314,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) std::vector::iterator it; for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - const char* existingValue = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryValue((*it)->GetValue()); - bool advanced = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED"); - if (!existingValue || (!this->AdvancedMode && advanced)) + cmCacheManager::CacheIterator mit = + this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -351,13 +334,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) std::vector::iterator it; for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - const char* existingValue = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryValue((*it)->GetValue()); - bool advanced = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED"); - if (!existingValue || (!this->AdvancedMode && advanced)) + cmCacheManager::CacheIterator mit = + this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -515,12 +495,11 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) // Get the help string of the current entry // and add it to the help string - const char* existingValue = - this->CMakeInstance->GetCacheManager()->GetCacheEntryValue(curField); - if (existingValue) + cmCacheManager::CacheIterator it = + this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField); + if (!it.IsAtEnd()) { - const char* hs = this->CMakeInstance->GetCacheManager() - ->GetCacheEntryProperty(curField, "HELPSTRING"); + const char* hs = it.GetProperty("HELPSTRING"); if ( hs ) { strncpy(help, hs, 127); @@ -660,7 +639,7 @@ int cmCursesMainForm::Configure(int noconfigure) // always save the current gui values to disk this->FillCacheManagerFromUI(); - this->CMakeInstance->SaveCache( + this->CMakeInstance->GetCacheManager()->SaveCache( this->CMakeInstance->GetHomeOutputDirectory()); this->LoadCache(0); @@ -813,28 +792,23 @@ void cmCursesMainForm::FillCacheManagerFromUI() size_t size = this->Entries->size(); for(size_t i=0; i < size; i++) { - std::string cacheKey = (*this->Entries)[i]->Key; - const char* existingValue = this->CMakeInstance->GetCacheManager() - ->GetCacheEntryValue(cacheKey); - if (existingValue) + cmCacheManager::CacheIterator it = + this->CMakeInstance->GetCacheManager()->GetCacheIterator( + (*this->Entries)[i]->Key.c_str()); + if (!it.IsAtEnd()) { - std::string oldValue = existingValue; + std::string oldValue = it.GetValue(); std::string newValue = (*this->Entries)[i]->Entry->GetValue(); std::string fixedOldValue; std::string fixedNewValue; - cmCacheManager::CacheEntryType t = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryType(cacheKey); - this->FixValue(t, oldValue, fixedOldValue); - this->FixValue(t, newValue, fixedNewValue); + this->FixValue(it.GetType(), oldValue, fixedOldValue); + this->FixValue(it.GetType(), newValue, fixedNewValue); if(!(fixedOldValue == fixedNewValue)) { // The user has changed the value. Mark it as modified. - this->CMakeInstance->GetCacheManager() - ->SetCacheEntryBoolProperty(cacheKey, "MODIFIED", true); - this->CMakeInstance->GetCacheManager() - ->SetCacheEntryValue(cacheKey, fixedNewValue); + it.SetProperty("MODIFIED", true); + it.SetValue(fixedNewValue.c_str()); } } } @@ -1043,15 +1017,12 @@ void cmCursesMainForm::HandleInput() cmCursesWidget* lbl = reinterpret_cast(field_userptr( this->Fields[findex-2])); const char* curField = lbl->GetValue(); - const char* helpString = 0; - - const char* existingValue = - this->CMakeInstance->GetCacheManager() - ->GetCacheEntryValue(curField); - if (existingValue) + const char* helpString=0; + cmCacheManager::CacheIterator it = + this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField); + if (!it.IsAtEnd()) { - helpString = this->CMakeInstance->GetCacheManager() - ->GetCacheEntryProperty(curField, "HELPSTRING"); + helpString = it.GetProperty("HELPSTRING"); } if (helpString) { diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 08d53ce27..996aa75fe 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -96,7 +96,7 @@ void QCMake::setBinaryDirectory(const QString& _dir) emit this->binaryDirChanged(this->BinaryDirectory); cmCacheManager *cachem = this->CMakeInstance->GetCacheManager(); this->setGenerator(QString()); - if(!this->CMakeInstance->LoadCache( + if(!this->CMakeInstance->GetCacheManager()->LoadCache( this->BinaryDirectory.toLocal8Bit().data())) { QDir testDir(this->BinaryDirectory); @@ -110,18 +110,16 @@ void QCMake::setBinaryDirectory(const QString& _dir) QCMakePropertyList props = this->properties(); emit this->propertiesChanged(props); - const char* homeDir = cachem->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"); - if (homeDir) + cmCacheManager::CacheIterator itm = cachem->NewIterator(); + if ( itm.Find("CMAKE_HOME_DIRECTORY")) { - setSourceDirectory(QString::fromLocal8Bit(homeDir)); + setSourceDirectory(QString::fromLocal8Bit(itm.GetValue().c_str())); } - const char* gen = cachem->GetCacheEntryValue("CMAKE_GENERATOR"); - if (gen) + if ( itm.Find("CMAKE_GENERATOR")) { - const char* extraGen = cachem - ->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR"); + const char* extraGen = cachem->GetCacheValue("CMAKE_EXTRA_GENERATOR"); std::string curGen = cmExternalMakefileProjectGenerator:: - CreateFullGeneratorName(gen, extraGen? extraGen : ""); + CreateFullGeneratorName(itm.GetValue(), extraGen? extraGen : ""); this->setGenerator(QString::fromLocal8Bit(curGen.c_str())); } } @@ -196,35 +194,33 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) // set the value of properties cmCacheManager *cachem = this->CMakeInstance->GetCacheManager(); - std::vector cacheKeys = cachem->GetCacheEntryKeys(); - for(std::vector::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) + for(cmCacheManager::CacheIterator i = cachem->NewIterator(); + !i.IsAtEnd(); i.Next()) { - cmCacheManager::CacheEntryType t = cachem->GetCacheEntryType(*it); - if(t == cmCacheManager::INTERNAL || - t == cmCacheManager::STATIC) + + if(i.GetType() == cmCacheManager::INTERNAL || + i.GetType() == cmCacheManager::STATIC) { continue; } QCMakeProperty prop; - prop.Key = QString::fromLocal8Bit(it->c_str()); + prop.Key = QString::fromLocal8Bit(i.GetName().c_str()); int idx = props.indexOf(prop); if(idx == -1) { - toremove.append(QString::fromLocal8Bit(it->c_str())); + toremove.append(QString::fromLocal8Bit(i.GetName().c_str())); } else { prop = props[idx]; if(prop.Value.type() == QVariant::Bool) { - cachem->SetCacheEntryValue(*it, prop.Value.toBool() ? "ON" : "OFF"); + i.SetValue(prop.Value.toBool() ? "ON" : "OFF"); } else { - cachem->SetCacheEntryValue(*it, - prop.Value.toString().toLocal8Bit().data()); + i.SetValue(prop.Value.toString().toLocal8Bit().data()); } props.removeAt(idx); } @@ -274,7 +270,7 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) } } - this->CMakeInstance->SaveCache(this->BinaryDirectory.toLocal8Bit().data()); + cachem->SaveCache(this->BinaryDirectory.toLocal8Bit().data()); } QCMakePropertyList QCMake::properties() const @@ -282,47 +278,42 @@ QCMakePropertyList QCMake::properties() const QCMakePropertyList ret; cmCacheManager *cachem = this->CMakeInstance->GetCacheManager(); - std::vector cacheKeys = cachem->GetCacheEntryKeys(); - for (std::vector::const_iterator i = cacheKeys.begin(); - i != cacheKeys.end(); ++i) + for(cmCacheManager::CacheIterator i = cachem->NewIterator(); + !i.IsAtEnd(); i.Next()) { - cmCacheManager::CacheEntryType t = cachem->GetCacheEntryType(*i); - if(t == cmCacheManager::INTERNAL || - t == cmCacheManager::STATIC || - t == cmCacheManager::UNINITIALIZED) + + if(i.GetType() == cmCacheManager::INTERNAL || + i.GetType() == cmCacheManager::STATIC || + i.GetType() == cmCacheManager::UNINITIALIZED) { continue; } - const char* cachedValue = cachem->GetCacheEntryValue(*i); - QCMakeProperty prop; - prop.Key = QString::fromLocal8Bit(i->c_str()); - prop.Help = QString::fromLocal8Bit( - cachem->GetCacheEntryProperty(*i, "HELPSTRING")); - prop.Value = QString::fromLocal8Bit(cachedValue); - prop.Advanced = cachem->GetCacheEntryPropertyAsBool(*i, "ADVANCED"); - if(t == cmCacheManager::BOOL) + prop.Key = QString::fromLocal8Bit(i.GetName().c_str()); + prop.Help = QString::fromLocal8Bit(i.GetProperty("HELPSTRING")); + prop.Value = QString::fromLocal8Bit(i.GetValue().c_str()); + prop.Advanced = i.GetPropertyAsBool("ADVANCED"); + + if(i.GetType() == cmCacheManager::BOOL) { prop.Type = QCMakeProperty::BOOL; - prop.Value = cmSystemTools::IsOn(cachedValue); + prop.Value = cmSystemTools::IsOn(i.GetValue().c_str()); } - else if(t == cmCacheManager::PATH) + else if(i.GetType() == cmCacheManager::PATH) { prop.Type = QCMakeProperty::PATH; } - else if(t == cmCacheManager::FILEPATH) + else if(i.GetType() == cmCacheManager::FILEPATH) { prop.Type = QCMakeProperty::FILEPATH; } - else if(t == cmCacheManager::STRING) + else if(i.GetType() == cmCacheManager::STRING) { prop.Type = QCMakeProperty::STRING; - const char* stringsProperty = - cachem->GetCacheEntryProperty(*i, "STRINGS"); - if (stringsProperty) + if (i.PropertyExists("STRINGS")) { - prop.Strings = QString::fromLocal8Bit(stringsProperty).split(";"); + prop.Strings = QString::fromLocal8Bit(i.GetProperty("STRINGS")).split(";"); } } @@ -406,9 +397,9 @@ QStringList QCMake::availableGenerators() const void QCMake::deleteCache() { // delete cache - this->CMakeInstance->DeleteCache(this->BinaryDirectory.toLocal8Bit().data()); + this->CMakeInstance->GetCacheManager()->DeleteCache(this->BinaryDirectory.toLocal8Bit().data()); // reload to make our cache empty - this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); + this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); // emit no generator and no properties this->setGenerator(QString()); QCMakePropertyList props = this->properties(); @@ -421,7 +412,7 @@ void QCMake::reloadCache() QCMakePropertyList props; emit this->propertiesChanged(props); // reload - this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); + this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); // emit new cache properties props = this->properties(); emit this->propertiesChanged(props); diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 987a7b17d..691d80d7e 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -51,14 +51,12 @@ void CCONV cmSetError(void *info, const char *err) unsigned int CCONV cmGetCacheMajorVersion(void *arg) { cmMakefile *mf = static_cast(arg); - cmCacheManager *manager = mf->GetCMakeInstance()->GetCacheManager(); - return manager->GetCacheMajorVersion(); + return mf->GetCacheMajorVersion(); } unsigned int CCONV cmGetCacheMinorVersion(void *arg) { cmMakefile *mf = static_cast(arg); - cmCacheManager *manager = mf->GetCMakeInstance()->GetCacheManager(); - return manager->GetCacheMinorVersion(); + return mf->GetCacheMinorVersion(); } unsigned int CCONV cmGetMajorVersion(void *) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 1db057bd1..df61fe6bf 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2281,7 +2281,7 @@ bool cmCTest::AddVariableDefinition(const std::string &arg) std::string value; cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED; - if (cmake::ParseCacheEntry(arg, name, value, type)) + if (cmCacheManager::ParseEntry(arg, name, value, type)) { this->Definitions[name] = value; return true; diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 5387d0c81..b8dfe04c7 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -283,16 +283,14 @@ bool cmCacheManager::LoadCache(const std::string& path, } this->CacheMajorVersion = 0; this->CacheMinorVersion = 0; - if(const char* cmajor = - this->GetInitializedCacheValue("CMAKE_CACHE_MAJOR_VERSION")) + if(const char* cmajor = this->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION")) { unsigned int v=0; if(sscanf(cmajor, "%u", &v) == 1) { this->CacheMajorVersion = v; } - if(const char* cminor = - this->GetInitializedCacheValue("CMAKE_CACHE_MINOR_VERSION")) + if(const char* cminor = this->GetCacheValue("CMAKE_CACHE_MINOR_VERSION")) { if(sscanf(cminor, "%u", &v) == 1) { @@ -314,11 +312,10 @@ bool cmCacheManager::LoadCache(const std::string& path, } // check to make sure the cache directory has not // been moved - const char* oldDir = this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR"); - if (internal && oldDir) + if ( internal && this->GetCacheValue("CMAKE_CACHEFILE_DIR") ) { std::string currentcwd = path; - std::string oldcwd = oldDir; + std::string oldcwd = this->GetCacheValue("CMAKE_CACHEFILE_DIR"); cmSystemTools::ConvertToUnixSlashes(currentcwd); currentcwd += "/CMakeCache.txt"; oldcwd += "/CMakeCache.txt"; @@ -327,7 +324,7 @@ bool cmCacheManager::LoadCache(const std::string& path, std::string message = std::string("The current CMakeCache.txt directory ") + currentcwd + std::string(" is different than the directory ") + - std::string(this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR")) + + std::string(this->GetCacheValue("CMAKE_CACHEFILE_DIR")) + std::string(" where CMakeCache.txt was created. This may result " "in binaries being created in the wrong place. If you " "are not sure, reedit the CMakeCache.txt"); @@ -657,8 +654,7 @@ cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator( return CacheIterator(*this, key); } -const char* -cmCacheManager::GetInitializedCacheValue(const std::string& key) const +const char* cmCacheManager::GetCacheValue(const std::string& key) const { CacheEntryMap::const_iterator i = this->Cache.find(key); if(i != this->Cache.end() && diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 2d3f6e5fc..f7f877606 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -137,82 +137,7 @@ public: CacheEntryType& type); ///! Get a value from the cache given a key - const char* GetInitializedCacheValue(const std::string& key) const; - - const char* GetCacheEntryValue(const std::string& key) - { - cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str()); - if (it.IsAtEnd()) - { - return 0; - } - return it.GetValue().c_str(); - } - - const char* GetCacheEntryProperty(std::string const& key, - std::string const& propName) - { - return this->GetCacheIterator(key.c_str()).GetProperty(propName); - } - - CacheEntryType GetCacheEntryType(std::string const& key) - { - return this->GetCacheIterator(key.c_str()).GetType(); - } - - bool GetCacheEntryPropertyAsBool(std::string const& key, - std::string const& propName) - { - return this->GetCacheIterator(key.c_str()).GetPropertyAsBool(propName); - } - - void SetCacheEntryProperty(std::string const& key, - std::string const& propName, - std::string const& value) - { - this->GetCacheIterator(key.c_str()).SetProperty(propName, value.c_str()); - } - - void SetCacheEntryBoolProperty(std::string const& key, - std::string const& propName, - bool value) - { - this->GetCacheIterator(key.c_str()).SetProperty(propName, value); - } - - void SetCacheEntryValue(std::string const& key, - std::string const& value) - { - this->GetCacheIterator(key.c_str()).SetValue(value.c_str()); - } - - void RemoveCacheEntryProperty(std::string const& key, - std::string const& propName) - { - this->GetCacheIterator(key.c_str()).SetProperty(propName, (void*)0); - } - - void AppendCacheEntryProperty(std::string const& key, - std::string const& propName, - std::string const& value, - bool asString = false) - { - this->GetCacheIterator(key.c_str()).AppendProperty(propName, - value.c_str(), - asString); - } - - std::vector GetCacheEntryKeys() - { - std::vector definitions; - definitions.reserve(this->GetSize()); - cmCacheManager::CacheIterator cit = this->GetCacheIterator(); - for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() ) - { - definitions.push_back(cit.GetName()); - } - return definitions; - } + const char* GetCacheValue(const std::string& key) const; /** Get the version of CMake that wrote the cache. */ unsigned int GetCacheMajorVersion() const diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 99bf5f55f..747b7e434 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -90,8 +90,7 @@ char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key, } if ( strcmp(key, "CACHE") == 0 ) { - if(const char* c = this->Makefile->GetCacheManager() - ->GetInitializedCacheValue(var)) + if(const char* c = this->Makefile->GetCacheManager()->GetCacheValue(var)) { if(this->EscapeQuotes) { diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 0d32e4bac..d64b0d74c 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -205,7 +205,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout, std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_"; cacheEntryName += envVar; - const char* cacheValue = mf->GetCacheManager()->GetInitializedCacheValue( + const char* cacheValue = mf->GetCacheManager()->GetCacheValue( cacheEntryName); // now we have both, decide which one to use @@ -223,7 +223,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout, mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(), cacheEntryName.c_str(), cmCacheManager::STRING, true); - mf->GetCMakeInstance()->SaveCache(mf->GetHomeOutputDirectory()); + mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory()); } else if (envVarValue==0 && cacheValue!=0) { @@ -244,7 +244,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout, mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(), cacheEntryName.c_str(), cmCacheManager::STRING, true); - mf->GetCMakeInstance()->SaveCache(mf->GetHomeOutputDirectory()); + mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory()); } } diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index cc080528d..f63df616d 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -366,18 +366,18 @@ bool cmFindBase::CheckForVariableInCache() if(const char* cacheValue = this->Makefile->GetDefinition(this->VariableName)) { - cmCacheManager* manager = this->Makefile->GetCacheManager(); - const char* cacheEntry = manager->GetCacheEntryValue(this->VariableName); + cmCacheManager::CacheIterator it = + this->Makefile->GetCacheManager()-> + GetCacheIterator(this->VariableName.c_str()); bool found = !cmSystemTools::IsNOTFOUND(cacheValue); - bool cached = cacheEntry ? true : false; + bool cached = !it.IsAtEnd(); if(found) { // If the user specifies the entry on the command line without a // type we should add the type and docstring but keep the // original value. Tell the subclass implementations to do // this. - if(cached && manager->GetCacheEntryType(this->VariableName) - == cmCacheManager::UNINITIALIZED) + if(cached && it.GetType() == cmCacheManager::UNINITIALIZED) { this->AlreadyInCacheWithoutMetaInfo = true; } @@ -385,8 +385,7 @@ bool cmFindBase::CheckForVariableInCache() } else if(cached) { - const char* hs = manager->GetCacheEntryProperty(this->VariableName, - "HELPSTRING"); + const char* hs = it.GetProperty("HELPSTRING"); this->VariableDocumentation = hs?hs:"(none)"; } } diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 0e6e0c20e..f0b268685 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -391,10 +391,11 @@ bool cmGetPropertyCommand::HandleCacheMode() } const char* value = 0; - if(this->Makefile->GetCacheManager()->GetCacheEntryValue(this->Name)) + cmCacheManager::CacheIterator it = + this->Makefile->GetCacheManager()->GetCacheIterator(this->Name.c_str()); + if(!it.IsAtEnd()) { - value = this->Makefile->GetCacheManager() - ->GetCacheEntryProperty(this->Name, this->PropertyName); + value = it.GetProperty(this->PropertyName); } this->StoreResult(value); return true; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 35394b8f9..3c0a0e244 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -179,7 +179,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang, return; } const char* cname = this->GetCMakeInstance()-> - GetCacheManager()->GetInitializedCacheValue(langComp); + GetCacheManager()->GetCacheValue(langComp); std::string changeVars; if(cname && !optional) { @@ -1559,7 +1559,9 @@ void cmGlobalGenerator::CheckLocalGenerators() cmSystemTools::IsNOTFOUND(lib->first.c_str())) { std::string varName = lib->first.substr(0, lib->first.size()-9); - if(manager->GetCacheEntryPropertyAsBool(varName, "ADVANCED")) + cmCacheManager::CacheIterator it = + manager->GetCacheIterator(varName.c_str()); + if(it.GetPropertyAsBool("ADVANCED")) { varName += " (ADVANCED)"; } @@ -1590,7 +1592,9 @@ void cmGlobalGenerator::CheckLocalGenerators() cmSystemTools::IsNOTFOUND(incDir->c_str())) { std::string varName = incDir->substr(0, incDir->size()-9); - if(manager->GetCacheEntryPropertyAsBool(varName, "ADVANCED")) + cmCacheManager::CacheIterator it = + manager->GetCacheIterator(varName.c_str()); + if(it.GetPropertyAsBool("ADVANCED")) { varName += " (ADVANCED)"; } @@ -1637,7 +1641,7 @@ int cmGlobalGenerator::TryCompile(const std::string& srcdir, // and there is a good chance that the try compile stuff will // take the bulk of the time, so try and guess some progress // by getting closer and closer to 100 without actually getting there. - if (!this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue + if (!this->CMakeInstance->GetCacheManager()->GetCacheValue ("CMAKE_NUMBER_OF_LOCAL_GENERATORS")) { // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set @@ -1835,7 +1839,7 @@ void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg) // update progress // estimate how many lg there will be const char *numGenC = - this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue + this->CMakeInstance->GetCacheManager()->GetCacheValue ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"); if (!numGenC) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0561a0542..5e584a452 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3703,7 +3703,7 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root, // Since this call may have created new cache entries, save the cache: // - root->GetMakefile()->GetCMakeInstance()->SaveCache( + root->GetMakefile()->GetCacheManager()->SaveCache( root->GetMakefile()->GetHomeOutputDirectory()); } diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx index e2ae90111..93aec3220 100644 --- a/Source/cmLoadCacheCommand.cxx +++ b/Source/cmLoadCacheCommand.cxx @@ -81,8 +81,8 @@ bool cmLoadCacheCommand { break; } - this->Makefile->GetCMakeInstance()->LoadCache(args[i], false, - excludes, includes); + this->Makefile->GetCacheManager()->LoadCache(args[i], false, + excludes, includes); } @@ -173,7 +173,7 @@ void cmLoadCacheCommand::CheckLine(const char* line) std::string var; std::string value; cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED; - if(cmake::ParseCacheEntry(line, var, value, type)) + if(cmCacheManager::ParseEntry(line, var, value, type)) { // Found a real entry. See if this one was requested. if(this->VariablesToRead.find(var) != this->VariablesToRead.end()) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 34b46218d..215ee1614 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -174,6 +174,16 @@ void cmMakefile::Initialize() this->CheckCMP0000 = false; } +unsigned int cmMakefile::GetCacheMajorVersion() const +{ + return this->GetCacheManager()->GetCacheMajorVersion(); +} + +unsigned int cmMakefile::GetCacheMinorVersion() const +{ + return this->GetCacheManager()->GetCacheMinorVersion(); +} + cmMakefile::~cmMakefile() { cmDeleteAll(this->InstallGenerators); @@ -1810,17 +1820,16 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, { bool haveVal = value ? true : false; std::string val = haveVal ? value : ""; - const char* existingValue = - this->GetCacheManager()->GetInitializedCacheValue(name); - if(existingValue - && (this->GetCacheManager()->GetCacheEntryType(name) - == cmCacheManager::UNINITIALIZED)) + cmCacheManager::CacheIterator it = + this->GetCacheManager()->GetCacheIterator(name.c_str()); + if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) && + it.Initialized()) { // if this is not a force, then use the value from the cache // if it is a force, then use the value being passed in if(!force) { - val = existingValue; + val = it.GetValue(); haveVal = true; } if ( type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH ) @@ -1843,13 +1852,13 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, } this->GetCacheManager()->AddCacheEntry(name, nvalue.c_str(), doc, type); - val = this->GetCacheManager()->GetInitializedCacheValue(name); + val = it.GetValue(); haveVal = true; } } - this->GetCacheManager()->AddCacheEntry(name, haveVal ? val.c_str() : 0, - doc, type); + this->GetCacheManager()->AddCacheEntry(name, haveVal ? val.c_str() : 0, doc, + type); // if there was a definition then remove it this->Internal->VarStack.top().Set(name, 0); } @@ -2433,7 +2442,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const this->Internal->VarUsageStack.top().insert(name); if(!def) { - def = this->GetCacheManager()->GetInitializedCacheValue(name); + def = this->GetCacheManager()->GetCacheValue(name); } #ifdef CMAKE_BUILD_WITH_CMAKE if(cmVariableWatch* vv = this->GetVariableWatch()) @@ -2458,7 +2467,7 @@ const char* cmMakefile::GetDefinition(const std::string& name) const const char* def = this->Internal->VarStack.top().Get(name); if(!def) { - def = this->GetCacheManager()->GetInitializedCacheValue(name); + def = this->GetCacheManager()->GetCacheValue(name); } #ifdef CMAKE_BUILD_WITH_CMAKE cmVariableWatch* vv = this->GetVariableWatch(); @@ -2492,18 +2501,20 @@ const char* cmMakefile::GetSafeDefinition(const std::string& def) const std::vector cmMakefile ::GetDefinitions(int cacheonly /* = 0 */) const { - std::vector res; + std::set definitions; if ( !cacheonly ) { - std::set definitions = - this->Internal->VarStack.top().ClosureKeys(); - res.insert(res.end(), definitions.begin(), definitions.end()); + definitions = this->Internal->VarStack.top().ClosureKeys(); + } + cmCacheManager::CacheIterator cit = + this->GetCacheManager()->GetCacheIterator(); + for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() ) + { + definitions.insert(cit.GetName()); } - std::vector cacheKeys = - this->GetCacheManager()->GetCacheEntryKeys(); - res.insert(res.end(), cacheKeys.begin(), cacheKeys.end()); - std::sort(res.begin(), res.end()); + std::vector res; + res.insert(res.end(), definitions.begin(), definitions.end()); return res; } @@ -2834,8 +2845,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( value = cmSystemTools::GetEnv(lookup.c_str()); break; case CACHE: - value = this->GetCacheManager() - ->GetInitializedCacheValue(lookup); + value = this->GetCacheManager()->GetCacheValue(lookup); break; } // Get the string we're meant to append to. @@ -4903,7 +4913,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, (status == cmPolicies::WARN || status == cmPolicies::OLD)) { if(!(this->GetCacheManager() - ->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))) + ->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))) { // Set it to 2.4 because that is the last version where the // variable had meaning. diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 5209891d2..920b6b79d 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -62,6 +62,14 @@ class cmMakefile class Internals; cmsys::auto_ptr Internal; public: + /** + * Return the major and minor version of the cmake that + * was used to write the currently loaded cache, note + * this method will not work before the cache is loaded. + */ + unsigned int GetCacheMajorVersion() const; + unsigned int GetCacheMinorVersion() const; + /* Check for unused variables in this scope */ void CheckForUnusedVariables() const; /* Mark a variable as used */ diff --git a/Source/cmMarkAsAdvancedCommand.cxx b/Source/cmMarkAsAdvancedCommand.cxx index cc094b1bc..f6a2c2670 100644 --- a/Source/cmMarkAsAdvancedCommand.cxx +++ b/Source/cmMarkAsAdvancedCommand.cxx @@ -37,19 +37,24 @@ bool cmMarkAsAdvancedCommand { std::string variable = args[i]; cmCacheManager* manager = this->Makefile->GetCacheManager(); - if (!manager->GetCacheEntryValue(variable)) + cmCacheManager::CacheIterator it = + manager->GetCacheIterator(variable.c_str()); + if ( it.IsAtEnd() ) { - manager->AddCacheEntry(variable, 0, 0, cmCacheManager::UNINITIALIZED); + this->Makefile->GetCacheManager() + ->AddCacheEntry(variable, 0, 0, + cmCacheManager::UNINITIALIZED); overwrite = true; } - if (!manager->GetCacheEntryValue(variable)) + it.Find(variable); + if ( it.IsAtEnd() ) { cmSystemTools::Error("This should never happen..."); return false; } - if (!manager->GetCacheEntryProperty(variable, "ADVANCED") || overwrite) + if ( !it.PropertyExists("ADVANCED") || overwrite ) { - manager->SetCacheEntryProperty(variable, "ADVANCED", value); + it.SetProperty("ADVANCED", value); } } return true; diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index baf5b1e08..60728eaea 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -42,16 +42,16 @@ bool cmOptionCommand std::string initialValue = "Off"; // Now check and see if the value has been stored in the cache // already, if so use that value and don't look for the program - cmCacheManager* manager = this->Makefile->GetCacheManager(); - const char* existingValue = manager->GetCacheEntryValue(args[0]); - if(existingValue) + cmCacheManager::CacheIterator it = + this->Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str()); + if(!it.IsAtEnd()) { - if (manager->GetCacheEntryType(args[0]) != cmCacheManager::UNINITIALIZED) + if ( it.GetType() != cmCacheManager::UNINITIALIZED ) { - manager->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]); + it.SetProperty("HELPSTRING", args[1].c_str()); return true; } - initialValue = existingValue; + initialValue = it.GetValue(); } if(args.size() == 3) { diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index e17474bd6..204d95b1e 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -136,10 +136,9 @@ bool cmSetCommand } // see if this is already in the cache - cmCacheManager* manager = this->Makefile->GetCacheManager(); - const char* existingValue = manager->GetCacheEntryValue(variable); - if(existingValue && - (manager->GetCacheEntryType(variable) != cmCacheManager::UNINITIALIZED)) + cmCacheManager::CacheIterator it = + this->Makefile->GetCacheManager()->GetCacheIterator(variable); + if(!it.IsAtEnd() && (it.GetType() != cmCacheManager::UNINITIALIZED)) { // if the set is trying to CACHE the value but the value // is already in the cache and the type is not internal diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index 77f9fb90b..1150bc7ad 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -452,11 +452,11 @@ bool cmSetPropertyCommand::HandleCacheMode() // Get the source file. cmMakefile* mf = this->GetMakefile(); cmake* cm = mf->GetCMakeInstance(); - const char* existingValue - = cm->GetCacheManager()->GetCacheEntryValue(*ni); - if(existingValue) + cmCacheManager::CacheIterator it = + cm->GetCacheManager()->GetCacheIterator(ni->c_str()); + if(!it.IsAtEnd()) { - if(!this->HandleCacheEntry(*ni)) + if(!this->HandleCacheEntry(it)) { return false; } @@ -474,25 +474,22 @@ bool cmSetPropertyCommand::HandleCacheMode() } //---------------------------------------------------------------------------- -bool cmSetPropertyCommand::HandleCacheEntry(std::string const& cacheKey) +bool cmSetPropertyCommand::HandleCacheEntry(cmCacheManager::CacheIterator& it) { // Set or append the property. const char* name = this->PropertyName.c_str(); const char* value = this->PropertyValue.c_str(); - cmCacheManager* manager = this->Makefile->GetCacheManager(); if (this->Remove) { - manager->RemoveCacheEntryProperty(cacheKey, name); - return true; + value = 0; } if(this->AppendMode) { - manager->AppendCacheEntryProperty(cacheKey, name, value, - this->AppendAsString); + it.AppendProperty(name, value, this->AppendAsString); } else { - manager->SetCacheEntryProperty(cacheKey, name, value); + it.SetProperty(name, value); } return true; diff --git a/Source/cmSetPropertyCommand.h b/Source/cmSetPropertyCommand.h index 3285e60ab..b06cb6857 100644 --- a/Source/cmSetPropertyCommand.h +++ b/Source/cmSetPropertyCommand.h @@ -61,7 +61,7 @@ private: bool HandleTestMode(); bool HandleTest(cmTest* test); bool HandleCacheMode(); - bool HandleCacheEntry(std::string const&); + bool HandleCacheEntry(cmCacheManager::CacheIterator&); bool HandleInstallMode(); bool HandleInstall(cmInstalledFile* file); }; diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 911ade810..b5280cfd7 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -264,12 +264,11 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, comment.c_str(), cmCacheManager::STRING); - cmCacheManager* manager = this->Makefile->GetCacheManager(); - const char* existingValue - = manager->GetCacheEntryValue(this->RunResultVariable); - if (existingValue) + cmCacheManager::CacheIterator it = this->Makefile->GetCacheManager()-> + GetCacheIterator(this->RunResultVariable.c_str()); + if ( !it.IsAtEnd() ) { - manager->SetCacheEntryProperty(this->RunResultVariable, "ADVANCED", "1"); + it.SetProperty("ADVANCED", "1"); } error = true; @@ -291,13 +290,11 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, "PLEASE_FILL_OUT-NOTFOUND", comment.c_str(), cmCacheManager::STRING); - cmCacheManager* manager = this->Makefile->GetCacheManager(); - const char* existing = - manager->GetCacheEntryValue(internalRunOutputName); - if (existing) + cmCacheManager::CacheIterator it = this->Makefile->GetCacheManager()-> + GetCacheIterator(internalRunOutputName.c_str()); + if ( !it.IsAtEnd() ) { - manager->SetCacheEntryProperty(internalRunOutputName, - "ADVANCED", "1"); + it.SetProperty("ADVANCED", "1"); } error = true; diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx index 2799a9be5..ee1ff291a 100644 --- a/Source/cmUtilitySourceCommand.cxx +++ b/Source/cmUtilitySourceCommand.cxx @@ -52,13 +52,11 @@ bool cmUtilitySourceCommand } else { - cmCacheManager *manager = - this->Makefile->GetCMakeInstance()->GetCacheManager(); haveCacheValue = (cacheValue && (strstr(cacheValue, "(IntDir)") == 0 || (intDir && strcmp(intDir, "$(IntDir)") == 0)) && - (manager->GetCacheMajorVersion() != 0 && - manager->GetCacheMinorVersion() != 0 )); + (this->Makefile->GetCacheMajorVersion() != 0 && + this->Makefile->GetCacheMinorVersion() != 0 )); } if(haveCacheValue) diff --git a/Source/cmVariableRequiresCommand.cxx b/Source/cmVariableRequiresCommand.cxx index dd2a68299..80c128654 100644 --- a/Source/cmVariableRequiresCommand.cxx +++ b/Source/cmVariableRequiresCommand.cxx @@ -41,9 +41,9 @@ bool cmVariableRequiresCommand requirementsMet = false; notSet += args[i]; notSet += "\n"; - cmCacheManager* manager = this->Makefile->GetCacheManager(); - if(manager->GetCacheEntryValue(args[i]) && - manager->GetCacheEntryPropertyAsBool(args[i], "ADVANCED")) + cmCacheManager::CacheIterator it = + this->Makefile->GetCacheManager()->GetCacheIterator(args[i].c_str()); + if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED")) { hasAdvanced = true; } diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 64b332ccc..5c52a1a2d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -344,8 +344,7 @@ bool cmake::SetCacheArgs(const std::vector& args) std::string cachedValue; if(this->WarnUnusedCli) { - if(const char *v = this->CacheManager - ->GetInitializedCacheValue(var)) + if(const char *v = this->CacheManager->GetCacheValue(var)) { haveValue = true; cachedValue = v; @@ -358,8 +357,7 @@ bool cmake::SetCacheArgs(const std::vector& args) if(this->WarnUnusedCli) { if (!haveValue || - cachedValue != this->CacheManager - ->GetInitializedCacheValue(var)) + cachedValue != this->CacheManager->GetCacheValue(var)) { this->WatchUnusedCli(var); } @@ -403,18 +401,17 @@ bool cmake::SetCacheArgs(const std::vector& args) cmsys::Glob::PatternToRegex(entryPattern, true, true).c_str()); //go through all cache entries and collect the vars which will be removed std::vector entriesToDelete; - std::vector cacheKeys = - this->CacheManager->GetCacheEntryKeys(); - for (std::vector::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) + cmCacheManager::CacheIterator it = + this->CacheManager->GetCacheIterator(); + for ( it.Begin(); !it.IsAtEnd(); it.Next() ) { - cmCacheManager::CacheEntryType t = - this->CacheManager->GetCacheEntryType(*it); + cmCacheManager::CacheEntryType t = it.GetType(); if(t != cmCacheManager::STATIC) { - if (regex.find(it->c_str())) + std::string entryName = it.GetName(); + if (regex.find(entryName.c_str())) { - entriesToDelete.push_back(*it); + entriesToDelete.push_back(entryName); } } } @@ -918,18 +915,16 @@ void cmake::SetDirectoriesFromFile(const char* arg) // If there is a CMakeCache.txt file, use its settings. if(!cachePath.empty()) { - if(this->LoadCache(cachePath)) + cmCacheManager* cachem = this->GetCacheManager(); + cmCacheManager::CacheIterator it = cachem->NewIterator(); + if(cachem->LoadCache(cachePath) && + it.Find("CMAKE_HOME_DIRECTORY")) { - const char* existingValue = - this->CacheManager->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"); - if (existingValue) - { - this->SetHomeOutputDirectory(cachePath); - this->SetStartOutputDirectory(cachePath); - this->SetHomeDirectory(existingValue); - this->SetStartDirectory(existingValue); - return; - } + this->SetHomeOutputDirectory(cachePath); + this->SetStartOutputDirectory(cachePath); + this->SetHomeDirectory(it.GetValue()); + this->SetStartDirectory(it.GetValue()); + return; } } @@ -1208,10 +1203,10 @@ int cmake::DoPreConfigureChecks() } // do a sanity check on some values - if(this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY")) + if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY")) { std::string cacheStart = - this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"); + this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"); cacheStart += "/CMakeLists.txt"; std::string currentStart = this->GetHomeDirectory(); currentStart += "/CMakeLists.txt"; @@ -1360,9 +1355,9 @@ int cmake::ActualConfigure() if(!this->GlobalGenerator) { const char* genName = - this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"); + this->CacheManager->GetCacheValue("CMAKE_GENERATOR"); const char* extraGenName = - this->CacheManager->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR"); + this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR"); if(genName) { std::string fullName = cmExternalMakefileProjectGenerator:: @@ -1440,8 +1435,7 @@ int cmake::ActualConfigure() } } - const char* genName = this->CacheManager - ->GetInitializedCacheValue("CMAKE_GENERATOR"); + const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR"); if(genName) { if(!this->GlobalGenerator->MatchesGeneratorName(genName)) @@ -1457,7 +1451,7 @@ int cmake::ActualConfigure() return -2; } } - if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR")) + if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR")) { this->CacheManager->AddCacheEntry("CMAKE_GENERATOR", this->GlobalGenerator->GetName().c_str(), @@ -1470,7 +1464,7 @@ int cmake::ActualConfigure() } if(const char* platformName = - this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM")) + this->CacheManager->GetCacheValue("CMAKE_GENERATOR_PLATFORM")) { if(this->GeneratorPlatform.empty()) { @@ -1498,7 +1492,7 @@ int cmake::ActualConfigure() } if(const char* tsName = - this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET")) + this->CacheManager->GetCacheValue("CMAKE_GENERATOR_TOOLSET")) { if(this->GeneratorToolset.empty()) { @@ -1552,18 +1546,16 @@ 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() - ->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")) + if(this->GetCacheManager()->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")) { - if(!this->CacheManager->GetInitializedCacheValue("LIBRARY_OUTPUT_PATH")) + if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH")) { this->CacheManager->AddCacheEntry ("LIBRARY_OUTPUT_PATH", "", "Single output directory for building all libraries.", cmCacheManager::PATH); } - if(!this->CacheManager - ->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH")) + if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH")) { this->CacheManager->AddCacheEntry ("EXECUTABLE_OUTPUT_PATH", "", @@ -1571,25 +1563,24 @@ int cmake::ActualConfigure() cmCacheManager::PATH); } } - if(!this->CacheManager - ->GetInitializedCacheValue("CMAKE_USE_RELATIVE_PATHS")) + if(!this->CacheManager->GetCacheValue("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); - if (!this->CacheManager->GetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS", - "ADVANCED")) + cmCacheManager::CacheIterator it = + this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS"); + if ( !it.PropertyExists("ADVANCED") ) { - this->CacheManager->SetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS", - "ADVANCED", "1"); + it.SetProperty("ADVANCED", "1"); } } if(cmSystemTools::GetFatalErrorOccured() && - (!this->CacheManager->GetInitializedCacheValue("CMAKE_MAKE_PROGRAM") || + (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") || cmSystemTools::IsOff(this->CacheManager-> - GetInitializedCacheValue("CMAKE_MAKE_PROGRAM")))) + GetCacheValue("CMAKE_MAKE_PROGRAM")))) { // We must have a bad generator selection. Wipe the cache entry so the // user can select another. @@ -1805,7 +1796,7 @@ void cmake::AddCacheEntry(const std::string& key, const char* value, const char* cmake::GetCacheDefinition(const std::string& name) const { - return this->CacheManager->GetInitializedCacheValue(name); + return this->CacheManager->GetCacheValue(name); } void cmake::AddDefaultCommands() @@ -1869,18 +1860,10 @@ 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->LoadCache(this->GetHomeOutputDirectory())) + if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory())) { // if it does exist, but isn't readable then warn the user std::string cacheFile = this->GetHomeOutputDirectory(); @@ -1903,28 +1886,6 @@ 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& excludes, - std::set& 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; @@ -1965,8 +1926,7 @@ void cmake::UpdateConversionPathTable() { // Update the path conversion table with any specified file: const char* tablepath = - this->CacheManager - ->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE"); + this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE"); if(tablepath) { @@ -2200,7 +2160,7 @@ void cmake::TruncateOutputLog(const char* fname) { return; } - if ( !this->CacheManager->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR") ) + if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") ) { cmSystemTools::RemoveFile(fullPath); return; @@ -2317,9 +2277,17 @@ const char *cmake::GetProperty(const std::string& prop, std::string output = ""; if ( prop == "CACHE_VARIABLES" ) { - std::vector cacheKeys = - this->CacheManager->GetCacheEntryKeys(); - this->SetProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str()); + 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()); } else if ( prop == "COMMANDS" ) { @@ -2471,7 +2439,7 @@ int cmake::GetSystemInformation(std::vector& args) // we have to find the module directory, so we can copy the files this->AddCMakePaths(); std::string modulesPath = - this->CacheManager->GetInitializedCacheValue("CMAKE_ROOT"); + this->CacheManager->GetCacheValue("CMAKE_ROOT"); modulesPath += "/Modules"; std::string inFile = modulesPath; inFile += "/SystemInformation.cmake"; @@ -2681,9 +2649,9 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text, if(t == cmake::AUTHOR_WARNING) { // Allow suppression of these warnings. - const char* suppress = this->CacheManager->GetCacheEntryValue( - "CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); - if(suppress && cmSystemTools::IsOn(suppress)) + cmCacheManager::CacheIterator it = this->CacheManager + ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); + if(!it.IsAtEnd() && it.GetValueAsBool()) { return; } @@ -2796,42 +2764,38 @@ int cmake::Build(const std::string& dir, } std::string cachePath = dir; cmSystemTools::ConvertToUnixSlashes(cachePath); - if(!this->LoadCache(cachePath)) + cmCacheManager* cachem = this->GetCacheManager(); + cmCacheManager::CacheIterator it = cachem->NewIterator(); + if(!cachem->LoadCache(cachePath)) { std::cerr << "Error: could not load cache\n"; return 1; } - const char* cachedGenerator = - this->CacheManager->GetCacheEntryValue("CMAKE_GENERATOR"); - if(!cachedGenerator) + if(!it.Find("CMAKE_GENERATOR")) { std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n"; return 1; } cmsys::auto_ptr gen( - this->CreateGlobalGenerator(cachedGenerator)); + this->CreateGlobalGenerator(it.GetValue())); if(!gen.get()) { std::cerr << "Error: could create CMAKE_GENERATOR \"" - << cachedGenerator << "\"\n"; + << it.GetValue() << "\"\n"; return 1; } std::string output; std::string projName; - const char* cachedProjectName = - this->CacheManager->GetCacheEntryValue("CMAKE_PROJECT_NAME"); - if(!cachedProjectName) + if(!it.Find("CMAKE_PROJECT_NAME")) { std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n"; return 1; } - projName = cachedProjectName; + projName = it.GetValue(); bool verbose = false; - const char* cachedVerbose = - this->CacheManager->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE"); - if(cachedVerbose) + if(it.Find("CMAKE_VERBOSE_MAKEFILE")) { - verbose = cmSystemTools::IsOn(cachedVerbose); + verbose = it.GetValueAsBool(); } return gen->Build("", dir, projName, target, diff --git a/Source/cmake.h b/Source/cmake.h index 3acf4a82f..c22b329d7 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -18,11 +18,11 @@ #include "cmPropertyDefinitionMap.h" #include "cmPropertyMap.h" #include "cmInstalledFile.h" -#include "cmCacheManager.h" class cmGlobalGeneratorFactory; class cmGlobalGenerator; class cmLocalGenerator; +class cmCacheManager; class cmMakefile; class cmCommand; class cmVariableWatch; @@ -173,19 +173,7 @@ class cmake int Configure(); int ActualConfigure(); - ///! Break up a line like VAR:type="value" into var, type and value - static bool ParseCacheEntry(const std::string& entry, - std::string& var, - std::string& value, - cmCacheManager::CacheEntryType& type); - int LoadCache(); - bool LoadCache(const std::string& path); - bool LoadCache(const std::string& path, bool internal, - std::set& excludes, - std::set& includes); - bool SaveCache(const std::string& path); - bool DeleteCache(const std::string& path); void PreLoadCMakeFiles(); ///! Create a GlobalGenerator diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 3b518be77..ac73ad079 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -328,31 +328,25 @@ int do_cmake(int ac, char const* const* av) int res = cm.Run(args, view_only); if ( list_cached || list_all_cached ) { + cmCacheManager::CacheIterator it = + cm.GetCacheManager()->GetCacheIterator(); std::cout << "-- Cache values" << std::endl; - std::vector keys = - cm.GetCacheManager()->GetCacheEntryKeys(); - for (std::vector::const_iterator it = keys.begin(); - it != keys.end(); ++it) + for ( it.Begin(); !it.IsAtEnd(); it.Next() ) { - cmCacheManager::CacheEntryType t = - cm.GetCacheManager()->GetCacheEntryType(*it); + cmCacheManager::CacheEntryType t = it.GetType(); if ( t != cmCacheManager::INTERNAL && t != cmCacheManager::STATIC && t != cmCacheManager::UNINITIALIZED ) { - const char* advancedProp = - cm.GetCacheManager()->GetCacheEntryProperty(*it, "ADVANCED"); - if ( list_all_cached || !advancedProp) + bool advanced = it.PropertyExists("ADVANCED"); + if ( list_all_cached || !advanced) { if ( list_help ) { - std::cout << "// " - << cm.GetCacheManager()->GetCacheEntryProperty(*it, - "HELPSTRING") << std::endl; + std::cout << "// " << it.GetProperty("HELPSTRING") << std::endl; } - std::cout << *it << ":" << - cmCacheManager::TypeToString(t) - << "=" << cm.GetCacheManager()->GetCacheEntryValue(*it) - << std::endl; + std::cout << it.GetName() << ":" << + cmCacheManager::TypeToString(it.GetType()) + << "=" << it.GetValue() << std::endl; if ( list_help ) { std::cout << std::endl;