Couple of changes: cache variables now have a map of properties. ADVANCED and HELPSTRING are now properties of cache variable, IsAdvanced is gone, so is GetCacheEntry, since cache entries are now all private. To access them, you use the iterator. -ADVANCED cache entries are gone and are replaced by the property of cache variables. The cache file still looks the same, but the -ADVANCED cache entries are created when writing file. MarkAsAdvanced and VariableRequires are fixed. So are curses gui and wizard

This commit is contained in:
Andy Cedilnik 2002-09-11 14:05:45 -04:00
parent bfdf8f7dcd
commit bef93dc5c1
12 changed files with 336 additions and 155 deletions

View File

@ -34,7 +34,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(const char* key,
}
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
const char* key, const cmCacheManager::CacheEntry& value, bool isNew,
const char* key, const cmCacheManager::CacheIterator& it, bool isNew,
int labelwidth, int entrywidth)
: m_Key(key), m_LabelWidth(labelwidth), m_EntryWidth(entrywidth)
{
@ -49,11 +49,11 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
}
m_Entry = 0;
switch ( value.m_Type )
switch ( it.GetType() )
{
case cmCacheManager::BOOL:
m_Entry = new cmCursesBoolWidget(m_EntryWidth, 1, 1, 1);
if (cmSystemTools::IsOn(value.m_Value.c_str()))
if (cmSystemTools::IsOn(it.GetValue()))
{
static_cast<cmCursesBoolWidget*>(m_Entry)->SetValueAsBool(true);
}
@ -65,17 +65,20 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
case cmCacheManager::PATH:
m_Entry = new cmCursesPathWidget(m_EntryWidth, 1, 1, 1);
static_cast<cmCursesPathWidget*>(m_Entry)->SetString(
value.m_Value.c_str());
it.GetValue());
break;
case cmCacheManager::FILEPATH:
m_Entry = new cmCursesFilePathWidget(m_EntryWidth, 1, 1, 1);
static_cast<cmCursesFilePathWidget*>(m_Entry)->SetString(
value.m_Value.c_str());
it.GetValue());
break;
case cmCacheManager::STRING:
m_Entry = new cmCursesStringWidget(m_EntryWidth, 1, 1, 1);
static_cast<cmCursesStringWidget*>(m_Entry)->SetString(
value.m_Value.c_str());
it.GetValue());
break;
case cmCacheManager::UNINITIALIZED:
cmSystemTools::Error("Found an undefined variable: ", it.GetName());
break;
default:
// TODO : put warning message here

View File

@ -25,7 +25,7 @@ class cmCursesCacheEntryComposite
public:
cmCursesCacheEntryComposite(const char* key, int labelwidth, int entrywidth);
cmCursesCacheEntryComposite(const char* key,
const cmCacheManager::CacheEntry& value,
const cmCacheManager::CacheIterator& it,
bool isNew, int labelwidth, int entrywidth);
~cmCursesCacheEntryComposite();
const char* GetValue();

View File

@ -117,9 +117,9 @@ void cmCursesMainForm::InitializeUI()
this->m_CMakeInstance->GetCacheManager()->NewIterator();
!i.IsAtEnd(); i.Next())
{
const cmCacheManager::CacheEntry& value = i.GetEntry();
if ( value.m_Type != cmCacheManager::INTERNAL &&
value.m_Type != cmCacheManager::STATIC )
if ( i.GetType() != cmCacheManager::INTERNAL &&
i.GetType() != cmCacheManager::STATIC &&
i.GetType() != cmCacheManager::UNINITIALIZED)
{
++count;
}
@ -146,16 +146,16 @@ void cmCursesMainForm::InitializeUI()
!i.IsAtEnd(); i.Next())
{
const char* key = i.GetName();
const cmCacheManager::CacheEntry& value = i.GetEntry();
if ( value.m_Type == cmCacheManager::INTERNAL ||
value.m_Type == cmCacheManager::STATIC )
if ( i.GetType() == cmCacheManager::INTERNAL ||
i.GetType() == cmCacheManager::STATIC ||
i.GetType() == cmCacheManager::UNINITIALIZED )
{
continue;
}
if (!this->LookForCacheEntry(key))
{
newEntries->push_back(new cmCursesCacheEntryComposite(key, value,
newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
true, 30,
entrywidth));
m_OkToGenerate = false;
@ -168,16 +168,16 @@ void cmCursesMainForm::InitializeUI()
!i.IsAtEnd(); i.Next())
{
const char* key = i.GetName();
const cmCacheManager::CacheEntry& value = i.GetEntry();
if ( value.m_Type == cmCacheManager::INTERNAL ||
value.m_Type == cmCacheManager::STATIC )
if ( i.GetType() == cmCacheManager::INTERNAL ||
i.GetType() == cmCacheManager::STATIC ||
i.GetType() == cmCacheManager::UNINITIALIZED )
{
continue;
}
if (this->LookForCacheEntry(key))
{
newEntries->push_back(new cmCursesCacheEntryComposite(key, value,
newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
false, 30,
entrywidth));
}
@ -224,9 +224,9 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
if (!m_AdvancedMode &&
this->m_CMakeInstance->GetCacheManager()->IsAdvanced(
(*it)->GetValue()))
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{
continue;
}
@ -243,8 +243,9 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
if (!m_AdvancedMode &&
this->m_CMakeInstance->GetCacheManager()->IsAdvanced((*it)->GetValue()))
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{
continue;
}
@ -302,8 +303,9 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
if (!m_AdvancedMode && this->m_CMakeInstance->GetCacheManager()->IsAdvanced(
(*it)->GetValue()))
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{
continue;
}
@ -318,8 +320,9 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
if (!m_AdvancedMode && this->m_CMakeInstance->GetCacheManager()->IsAdvanced(
(*it)->GetValue()))
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{
continue;
}
@ -453,15 +456,21 @@ void cmCursesMainForm::UpdateStatusBar()
// Get the help string of the current entry
// and add it to the help string
char help[128];
const char* helpString;
cmCacheManager::CacheEntry *entry =
this->m_CMakeInstance->GetCacheManager()->GetCacheEntry(curField);
if (entry)
cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
if (!it.IsAtEnd())
{
helpString = entry->m_HelpString.c_str();
strncpy(help, helpString, 127);
const char* hs = it.GetProperty("HELPSTRING");
if ( hs )
{
strncpy(help, hs, 127);
help[127] = '\0';
}
else
{
help[0] = 0;
}
}
else
{
sprintf(help," ");
@ -686,23 +695,22 @@ void cmCursesMainForm::FillCacheManagerFromUI()
int size = m_Entries->size();
for(int i=0; i < size; i++)
{
cmCacheManager::CacheEntry *entry =
this->m_CMakeInstance->GetCacheManager()->GetCacheEntry(
cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(
(*m_Entries)[i]->m_Key.c_str());
if (entry)
if (!it.IsAtEnd())
{
tmpString = (*m_Entries)[i]->m_Entry->GetValue();
// Remove trailing spaces, convert path to unix slashes
std::string tmpSubString =
tmpString.substr(0,tmpString.find_last_not_of(" ")+1);
if ( entry->m_Type == cmCacheManager::PATH ||
entry->m_Type == cmCacheManager::FILEPATH )
if ( it.GetType() == cmCacheManager::PATH ||
it.GetType() == cmCacheManager::FILEPATH )
{
cmSystemTools::ConvertToUnixSlashes(tmpSubString);
}
entry->m_Value = tmpSubString;
it.SetValue(tmpSubString.c_str());
}
}
}
@ -842,11 +850,11 @@ void cmCursesMainForm::HandleInput()
m_Fields[index-2]));
const char* curField = lbl->GetValue();
const char* helpString=0;
cmCacheManager::CacheEntry *entry =
this->m_CMakeInstance->GetCacheManager()->GetCacheEntry(curField);
if (entry)
cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
if (!it.IsAtEnd())
{
helpString = entry->m_HelpString.c_str();
helpString = it.GetProperty("HELPSTRING");
}
if (helpString)
{

View File

@ -33,6 +33,7 @@ const char* cmCacheManagerTypes[] =
"STRING",
"INTERNAL",
"STATIC",
"UNINITIALIZED",
0
};
@ -153,7 +154,7 @@ bool cmCacheManager::LoadCache(const char* path,
}
while(realbuffer[0] == '/' && realbuffer[1] == '/')
{
e.m_HelpString += &realbuffer[2];
e.m_Properties["HELPSTRING"] += &realbuffer[2];
fin.getline(realbuffer, bsize);
if(!fin)
{
@ -177,17 +178,37 @@ bool cmCacheManager::LoadCache(const char* path,
if (!internal)
{
e.m_Type = INTERNAL;
e.m_HelpString = "DO NOT EDIT, ";
e.m_HelpString += entryKey;
e.m_HelpString += " loaded from external file. "
e.m_Properties["HELPSTRING"] = "DO NOT EDIT, ";
e.m_Properties["HELPSTRING"] += entryKey;
e.m_Properties["HELPSTRING"] += " loaded from external file. "
"To change this value edit this file: ";
e.m_HelpString += path;
e.m_HelpString += "/CMakeCache.txt" ;
e.m_Properties["HELPSTRING"] += path;
e.m_Properties["HELPSTRING"] += "/CMakeCache.txt" ;
}
if ( e.m_Type == cmCacheManager::INTERNAL &&
(entryKey.size() > strlen("-ADVANCED")) &&
strcmp(entryKey.c_str() + (entryKey.size() - strlen("-ADVANCED")),
"-ADVANCED") == 0 )
{
std::string akey = entryKey.substr(0, (entryKey.size() - strlen("-ADVANCED")));
cmCacheManager::CacheIterator it = this->GetCacheIterator(akey.c_str());
if ( it.IsAtEnd() )
{
e.m_Type = cmCacheManager::UNINITIALIZED;
m_Cache[akey] = e;
}
else
{
it.SetProperty("ADVANCED", true);
}
}
else
{
m_Cache[entryKey] = e;
}
}
}
}
else
{
cmSystemTools::Error("Parse error in cache file ", cacheFile.c_str(),
@ -295,10 +316,24 @@ bool cmCacheManager::SaveCache(const char* path)
{
const CacheEntry& ce = (*i).second;
CacheEntryType t = ce.m_Type;
if(t != INTERNAL)
if(t == cmCacheManager::UNINITIALIZED)
{
cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
"\" is uninitialized");
}
else if(t != INTERNAL)
{
// Format is key:type=value
cmCacheManager::OutputHelpString(fout, ce.m_HelpString);
std::map<cmStdString,cmStdString>::const_iterator it =
ce.m_Properties.find("HELPSTRING");
if ( it == ce.m_Properties.end() )
{
cmCacheManager::OutputHelpString(fout, "Missing description");
}
else
{
cmCacheManager::OutputHelpString(fout, it->second);
}
std::string key;
// support : in key name by double quoting
if((*i).first.find(':') != std::string::npos ||
@ -335,40 +370,70 @@ bool cmCacheManager::SaveCache(const char* path)
fout << "########################\n";
fout << "\n";
for( std::map<cmStdString, CacheEntry>::const_iterator i = m_Cache.begin();
i != m_Cache.end(); ++i)
for( cmCacheManager::CacheIterator i = this->NewIterator();
!i.IsAtEnd(); i.Next())
{
const CacheEntry& ce = (*i).second;
CacheEntryType t = ce.m_Type;
if(t == INTERNAL)
CacheEntryType t = i.GetType();
bool advanced = i.GetPropertyAsBool("ADVANCED");
if ( advanced )
{
// Format is key:type=value
cmCacheManager::OutputHelpString(fout, ce.m_HelpString);
std::string key;
std::string rkey = i.GetName();
std::string helpstring;
// If this is advanced variable, we have to do some magic for
// backward compatibility
helpstring = "Advanced flag for variable: ";
helpstring += i.GetName();
rkey += "-ADVANCED";
cmCacheManager::OutputHelpString(fout, helpstring.c_str());
// support : in key name by double quoting
if((*i).first.find(':') != std::string::npos ||
(*i).first.find("//") == 0)
if(rkey.find(':') != std::string::npos ||
rkey.find("//") == 0)
{
key = "\"";
key += i->first;
key += rkey;
key += "\"";
}
else
{
key = i->first;
key = rkey;
}
fout << key.c_str() << ":INTERNAL=1\n";
}
if(t == cmCacheManager::INTERNAL)
{
// Format is key:type=value
std::string key;
std::string rkey = i.GetName();
std::string helpstring;
helpstring = i.GetProperty("HELPSTRING");
cmCacheManager::OutputHelpString(fout, helpstring.c_str());
// support : in key name by double quoting
if(rkey.find(':') != std::string::npos ||
rkey.find("//") == 0)
{
key = "\"";
key += rkey;
key += "\"";
}
else
{
key = rkey;
}
fout << key.c_str() << ":"
<< cmCacheManagerTypes[t] << "=";
// if value has trailing space or tab, enclose it in single quotes
if (ce.m_Value.size() &&
(ce.m_Value[ce.m_Value.size() - 1] == ' ' ||
ce.m_Value[ce.m_Value.size() - 1] == '\t'))
std::string value = i.GetValue();
if (value.size() &&
(value[value.size() - 1] == ' ' ||
value[value.size() - 1] == '\t'))
{
fout << '\'' << ce.m_Value << '\'';
fout << '\'' << value << '\'';
}
else
{
fout << ce.m_Value;
fout << value;
}
fout << "\n";
}
@ -439,6 +504,11 @@ cmCacheManager::CacheEntry *cmCacheManager::GetCacheEntry(const char* key)
return 0;
}
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char *key)
{
return CacheIterator(*this, key);
}
const char* cmCacheManager::GetCacheValue(const char* key) const
{
CacheEntryMap::const_iterator i = m_Cache.find(key);
@ -473,15 +543,29 @@ void cmCacheManager::AddCacheEntry(const char* key,
const char* helpString,
CacheEntryType type)
{
CacheEntry e;
CacheEntry& e = m_Cache[key];
if ( value )
{
e.m_Value = value;
}
else
{
e.m_Value = "(none)";
}
e.m_Type = type;
// make sure we only use unix style paths
if(type == FILEPATH || type == PATH)
{
cmSystemTools::ConvertToUnixSlashes(e.m_Value);
}
e.m_HelpString = helpString;
if ( helpString )
{
e.m_Properties["HELPSTRING"] = helpString;
}
else
{
e.m_Properties["HELPSTRING"] = "(This variable does not exists and should not be used)";
}
m_Cache[key] = e;
}
@ -498,29 +582,91 @@ void cmCacheManager::AddCacheEntry(const char* key, bool v,
}
}
bool cmCacheManager::IsAdvanced(const char* key)
{
std::string advancedVar = key;
advancedVar += "-ADVANCED";
const char* value = this->GetCacheValue(advancedVar.c_str());
if(value)
{
return cmSystemTools::IsOn(value);
}
return false;
}
bool cmCacheManager::CacheIterator::IsAtEnd()
{
return position == m_Container.m_Cache.end();
return m_Position == m_Container.m_Cache.end();
}
void cmCacheManager::CacheIterator::Begin()
{
position = m_Container.m_Cache.begin();
m_Position = m_Container.m_Cache.begin();
}
bool cmCacheManager::CacheIterator::Find(const char* key)
{
m_Position = m_Container.m_Cache.find(key);
return this->IsAtEnd();
}
void cmCacheManager::CacheIterator::Next()
{
++position;
++m_Position;
}
void cmCacheManager::CacheIterator::SetValue(const char* value)
{
CacheEntry* entry = &this->GetEntry();
entry->m_Value = value;
}
const char* cmCacheManager::CacheIterator::GetProperty(const char* property) const
{
if ( !strcasecmp(property, "TYPE") || !strcasecmp(property, "VALUE") )
{
cmSystemTools::Error("Property \"", property,
"\" cannot be accessed through the GetProperty()");
return 0;
}
const CacheEntry* ent = &this->GetEntry();
std::map<cmStdString,cmStdString>::const_iterator it =
ent->m_Properties.find(property);
if ( it == ent->m_Properties.end() )
{
return 0;
}
return it->second.c_str();
}
void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
{
if ( !strcasecmp(p, "TYPE") || !strcasecmp(p, "VALUE") )
{
cmSystemTools::Error("Property \"", p,
"\" cannot be accessed through the SetProperty()");
return;
}
CacheEntry* ent = &this->GetEntry();
ent->m_Properties[p] = v;
}
bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* property) const
{
if ( !strcasecmp(property, "TYPE") || !strcasecmp(property, "VALUE") )
{
cmSystemTools::Error("Property \"", property,
"\" cannot be accessed through the GetPropertyAsBool()");
return false;
}
const CacheEntry* ent = &this->GetEntry();
std::map<cmStdString,cmStdString>::const_iterator it =
ent->m_Properties.find(property);
if ( it == ent->m_Properties.end() )
{
return false;
}
return cmSystemTools::IsOn(it->second.c_str());
}
void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
{
if ( !strcasecmp(p, "TYPE") || !strcasecmp(p, "VALUE") )
{
cmSystemTools::Error("Property \"", p,
"\" cannot be accessed through the SetProperty()");
return;
}
CacheEntry* ent = &this->GetEntry();
ent->m_Properties[p] = v ? "ON" : "OFF";
}

View File

@ -29,28 +29,44 @@ class cmMakefile;
class cmCacheManager
{
public:
enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC };
enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,UNINITIALIZED };
private:
struct CacheEntry
{
std::string m_Value;
std::string m_HelpString;
CacheEntryType m_Type;
std::map<cmStdString,cmStdString> m_Properties;
};
public:
class CacheIterator
{
public:
void Begin();
bool Find(const char*);
bool IsAtEnd();
void Next();
const char *GetName() {
return position->first.c_str(); }
CacheEntry const &GetEntry() {
return position->second; }
cmCacheManager const &m_Container;
std::map<cmStdString, CacheEntry>::const_iterator position;
CacheIterator(cmCacheManager const &foo) : m_Container(foo) {
const char *GetName() const {
return m_Position->first.c_str(); }
const char* GetProperty(const char*) const ;
bool GetPropertyAsBool(const char*) const ;
void SetProperty(const char* property, const char* value);
void SetProperty(const char* property, bool value);
const char* GetValue() const { return this->GetEntry().m_Value.c_str(); }
void SetValue(const char*);
CacheEntryType GetType() const { return this->GetEntry().m_Type; }
cmCacheManager &m_Container;
std::map<cmStdString, CacheEntry>::iterator m_Position;
CacheIterator(cmCacheManager &foo) : m_Container(foo) {
this->Begin();
}
CacheIterator(cmCacheManager &foo, const char* key) : m_Container(foo) {
this->Find(key);
}
private:
CacheEntry const& GetEntry() const { return m_Position->second; }
CacheEntry& GetEntry() { return m_Position->second; }
};
friend class cmCacheManager::CacheIterator;
@ -60,7 +76,6 @@ public:
return CacheIterator(*this);
}
typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
/**
* Types for the cache entries. These are useful as
* hints for a cache editor program. Path should bring
@ -87,10 +102,8 @@ public:
///! Print the cache to a stream
void PrintCache(std::ostream&) const;
///! Get a cache entry object for a key
CacheEntry *GetCacheEntry(const char *key);
bool IsAdvanced(const char* key);
///! Get the iterator for an entry with a given key.
cmCacheManager::CacheIterator GetCacheIterator(const char *key);
///! Remove an entry from the cache
void RemoveCacheEntry(const char* key);
@ -116,7 +129,11 @@ protected:
///! Add a BOOL entry into the cache
void AddCacheEntry(const char* key, bool, const char* helpString);
///! Get a cache entry object for a key
CacheEntry *GetCacheEntry(const char *key);
private:
typedef std::map<cmStdString, CacheEntry> CacheEntryMap;
static void OutputHelpString(std::ofstream& fout,
const std::string& helpString);
CacheEntryMap m_Cache;

View File

@ -58,11 +58,12 @@ bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
}
if(cacheValue)
{
cmCacheManager::CacheEntry* e =
m_Makefile->GetCacheManager()->GetCacheEntry(args[0].c_str());
if(e)
cmCacheManager::CacheIterator it =
m_Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
if(!it.IsAtEnd())
{
helpString = e->m_HelpString;
const char* hs = it.GetProperty("HELPSTRING");
helpString = hs?hs:"(none)";
}
}
std::vector<std::string> path;

View File

@ -64,11 +64,12 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
}
if(cacheValue)
{
cmCacheManager::CacheEntry* e =
m_Makefile->GetCacheManager()->GetCacheEntry(args[0].c_str());
if(e)
cmCacheManager::CacheIterator it =
m_Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
if(!it.IsAtEnd())
{
doc = e->m_HelpString;
const char* hs = it.GetProperty("HELPSTRING");
doc = hs?hs:"(none)";
}
}
std::vector<std::string> path;

View File

@ -547,6 +547,10 @@ void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
void cmMakefile::AddDefinition(const char* name, const char* value)
{
if (!value )
{
return;
}
m_Definitions.erase( DefinitionMap::key_type(name));
m_Definitions.insert(DefinitionMap::value_type(name, value));
}

View File

@ -42,17 +42,20 @@ bool cmMarkAsAdvancedCommand::InitialPass(std::vector<std::string> const& argsIn
for(; i < args.size(); ++i)
{
std::string variable = args[i];
variable += "-ADVANCED";
std::string doc = "Advanced flag for variable: ";
doc += args[i];
// if not CLEAR or FORCE or it is not yet defined,
// then define variable-ADVANCED
if(overwrite || !m_Makefile->GetDefinition(variable.c_str()))
cmCacheManager* manager = m_Makefile->GetCacheManager();
cmCacheManager::CacheIterator it = manager->GetCacheIterator(variable.c_str());
if ( it.IsAtEnd() )
{
m_Makefile->AddCacheDefinition(variable.c_str(), value,
doc.c_str(),
cmCacheManager::INTERNAL);
m_Makefile->AddCacheDefinition(variable.c_str(), 0, 0,
cmCacheManager::UNINITIALIZED);
}
it.Find(variable.c_str());
if ( it.IsAtEnd() )
{
cmSystemTools::Error("This should never happen...");
return false;
}
it.SetProperty("ADVANCED", value);
}
return true;
}

View File

@ -47,7 +47,9 @@ void cmVariableRequiresCommand::FinalPass()
requirementsMet = false;
notSet += m_Arguments[i];
notSet += "\n";
if(m_Makefile->GetCacheManager()->IsAdvanced(m_Arguments[i].c_str()))
cmCacheManager::CacheIterator it =
m_Makefile->GetCacheManager()->GetCacheIterator(m_Arguments[i].c_str());
if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
{
hasAdvanced = true;
}

View File

@ -24,39 +24,33 @@ cmakewizard::cmakewizard()
}
void cmakewizard::AskUser(const char* key, cmCacheManager::CacheEntry & entry,
void cmakewizard::AskUser(const char* key, cmCacheManager::CacheIterator& iter,
cmCacheManager *cacheManager)
{
std::cout << "Variable Name: " << key << "\n";
std::cout << "Description: " << entry.m_HelpString << "\n";
std::cout << "Current Value: " << entry.m_Value.c_str() << "\n";
const char* helpstring = iter.GetProperty("HELPSTRING");
std::cout << "Description: " << (helpstring?helpstring:"(none)") << "\n";
std::cout << "Current Value: " << iter.GetValue() << "\n";
std::cout << "New Value (Enter to keep current value): ";
char buffer[4096];
buffer[0] = 0;
std::cin.getline(buffer, sizeof(buffer));
if(buffer[0])
{
cmCacheManager::CacheEntry *entry = cacheManager->GetCacheEntry(key);
if(entry)
std::string value = buffer;
if(iter.GetType() == cmCacheManager::PATH ||
iter.GetType() == cmCacheManager::FILEPATH)
{
entry->m_Value = buffer;
if(entry->m_Type == cmCacheManager::PATH ||
entry->m_Type == cmCacheManager::FILEPATH)
{
cmSystemTools::ConvertToUnixSlashes(entry->m_Value);
cmSystemTools::ConvertToUnixSlashes(value);
}
if(entry->m_Type == cmCacheManager::BOOL)
if(iter.GetType() == cmCacheManager::BOOL)
{
if(!cmSystemTools::IsOn(buffer))
if(!cmSystemTools::IsOn(value.c_str()))
{
entry->m_Value = "OFF";
value = "OFF";
}
}
}
else
{
std::cerr << "strange error, should be in cache but is not... " << key << "\n";
}
iter.SetValue(value.c_str());
}
std::cout << "\n";
}
@ -90,7 +84,8 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
m_ShowAdvanced = this->AskAdvanced();
cmSystemTools::DisableRunCommandOutput();
cmake make;
cmCacheManager::CacheEntryMap askedCache;
make.SetArgs(args);
std::map<std::string,std::string> askedCache;
bool asked = false;
// continue asking questions until no new questions are asked
do
@ -98,6 +93,7 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
asked = false;
// run cmake
this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n");
make.Configure(args[0].c_str(),&args);
this->ShowMessage("\n");
// load the cache from disk
@ -109,33 +105,33 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
for(;!i.IsAtEnd(); i.Next())
{
std::string key = i.GetName();
cmCacheManager::CacheEntry ce = i.GetEntry();
if(ce.m_Type == cmCacheManager::INTERNAL
|| ce.m_Type == cmCacheManager::STATIC)
if( i.GetType() == cmCacheManager::INTERNAL ||
i.GetType() == cmCacheManager::STATIC ||
i.GetType() == cmCacheManager::UNINITIALIZED )
{
continue;
}
if(askedCache.count(key))
{
cmCacheManager::CacheEntry& e = askedCache.find(key)->second;
if(e.m_Value != ce.m_Value)
std::string& e = askedCache.find(key)->second;
if(e != i.GetValue())
{
if(m_ShowAdvanced || !cachem->IsAdvanced(key.c_str()))
if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
{
this->AskUser(key.c_str(), ce, cachem);
this->AskUser(key.c_str(), i, cachem);
asked = true;
}
}
}
else
{
if(m_ShowAdvanced || !cachem->IsAdvanced(key.c_str()))
if(m_ShowAdvanced || !i.GetPropertyAsBool("ADVANCED"))
{
this->AskUser(key.c_str(), ce, cachem);
this->AskUser(key.c_str(), i, cachem);
asked = true;
}
}
askedCache[key] = i.GetEntry();
askedCache[key] = i.GetValue();
}
cachem->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
}

View File

@ -31,7 +31,7 @@ public:
/**
* Prompt the User for a new value for key, the answer is put in entry.
*/
virtual void AskUser(const char* key, cmCacheManager::CacheEntry & entry,
virtual void AskUser(const char* key, cmCacheManager::CacheIterator& iter,
cmCacheManager *cm);
///! Show a message to wait for cmake to run.
virtual void ShowMessage(const char*);