ENH: add command line arguments to set cache entries

This commit is contained in:
Bill Hoffman 2001-11-20 17:51:03 -05:00
parent f3d63c1932
commit f7fae15d39
4 changed files with 69 additions and 45 deletions

View File

@ -114,6 +114,32 @@ bool cmCacheManager::LoadCache(const char* path,
return this->LoadCache(path, internal, emptySet, emptySet);
}
bool cmCacheManager::ParseEntry(const char* entry,
std::string& var,
std::string& value,
CacheEntryType& type)
{
// input line is: key:type=value
cmRegularExpression reg("^([^:]*):([^=]*)=(.*[^\t ]|[\t ]*)[\t ]*$");
// input line is: "key":type=value
cmRegularExpression regQuoted("^\"([^\"]*)\":([^=]*)=(.*[^\t ]|[\t ]*)[\t ]*$");
if(regQuoted.find(entry))
{
var = regQuoted.match(1);
type = cmCacheManager::StringToType(regQuoted.match(2).c_str());
value = regQuoted.match(3);
return true;
}
else if (reg.find(entry))
{
var = reg.match(1);
type = cmCacheManager::StringToType(reg.match(2).c_str());
value = reg.match(3);
return true;
}
return false;
}
bool cmCacheManager::LoadCache(const char* path,
bool internal,
std::set<std::string>& excludes,
@ -167,12 +193,10 @@ bool cmCacheManager::LoadCache(const char* path,
continue;
}
}
if(regQuoted.find(realbuffer))
if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.m_Value, e.m_Type))
{
entryKey = regQuoted.match(1);
if ( excludes.find(entryKey) == excludes.end() )
{
e.m_Type = cmCacheManager::StringToType(regQuoted.match(2).c_str());
// Load internal values if internal is set.
// If the entry is not internal to the cache being loaded
// or if it is in the list of internal entries to be
@ -192,43 +216,10 @@ bool cmCacheManager::LoadCache(const char* path,
e.m_HelpString += path;
e.m_HelpString += "/CMakeCache.txt" ;
}
e.m_Value = regQuoted.match(3);
m_Cache[entryKey] = e;
}
}
}
else if (reg.find(realbuffer))
{
entryKey = reg.match(1);
if ( excludes.find(entryKey) == excludes.end() )
{
e.m_Type = cmCacheManager::StringToType(reg.match(2).c_str());
// only load internal values if internal is set
// Load internal values if internal is set.
// If the entry is not internal to the cache being loaded
// or if it is in the list of internal entries to be
// imported, load it.
if ( internal || (e.m_Type != INTERNAL) ||
(includes.find(entryKey) != includes.end()) )
{
// If we are loading the cache from another project,
// make all loaded entries internal so that it is
// not visible in the gui
if (!internal)
{
e.m_Type = INTERNAL;
e.m_HelpString = "DO NOT EDIT, ";
e.m_HelpString += entryKey;
e.m_HelpString += " loaded from external file. "
"To change this value edit this file: ";
e.m_HelpString += path;
e.m_HelpString += "/CMakeCache.txt";
}
e.m_Value = reg.match(3);
m_Cache[entryKey] = e;
}
}
}
else
{
cmSystemTools::Error("Parse error in cache file ", cacheFile.c_str(),
@ -247,6 +238,8 @@ bool cmCacheManager::LoadCache(const char* path,
"current loaded cache", cmCacheManager::INTERNAL);
}
// check to make sure the cache directory has not
// been moved
if ( internal && this->GetCacheValue("CMAKE_CACHEFILE_DIR") )
{
std::string currentcwd = path;

View File

@ -102,6 +102,12 @@ public:
///! Remove an entry from the cache
void RemoveCacheEntry(const char* key);
///! Break up a line like VAR:type="value" into var, type and value
static bool ParseEntry(const char* entry,
std::string& var,
std::string& value,
CacheEntryType& type);
protected:
///! Add an entry into the cache
void AddCacheEntry(const char* key, const char* value,

View File

@ -79,6 +79,35 @@ void cmake::Usage(const char* program)
std::cerr << ")\n";
}
// Parse the args
void cmake::SetCacheArgs(cmMakefile& builder, const std::vector<std::string>& args)
{
for(unsigned int i=1; i < args.size(); ++i)
{
std::string arg = args[i];
if(arg.find("-D",0) == 0)
{
std::string entry = arg.substr(2);
std::string var, value;
cmCacheManager::CacheEntryType type;
if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type))
{
cmCacheManager::GetInstance()->AddCacheEntry(
var.c_str(),
cmSystemTools::EscapeSpaces(value.c_str()).c_str(),
"No help, variable specified on the command line.",
type);
std::cerr << "parse entry " << var.c_str()<< " " << value.c_str() << "\n";
}
else
{
std::cerr << "Parse error in command line argument: " << arg << "\n"
<< "Should be: VAR:type=value\n";
}
}
}
}
// Parse the args
void cmake::SetArgs(cmMakefile& builder, const std::vector<std::string>& args)
{
@ -136,11 +165,6 @@ void cmake::SetArgs(cmMakefile& builder, const std::vector<std::string>& args)
std::string path = arg.substr(2);
builder.SetHomeOutputDirectory(path.c_str());
}
else if(arg.find("-D",0) == 0)
{
std::string value = arg.substr(2);
builder.AddDefinition(value.c_str(), true);
}
else if(arg.find("-V",0) == 0)
{
m_Verbose = true;
@ -315,6 +339,8 @@ int cmake::Generate(const std::vector<std::string>& args, bool buildMakefiles)
// Read and parse the input makefile
mf.MakeStartDirectoriesCurrent();
cmCacheManager::GetInstance()->LoadCache(&mf);
// extract command line arguments that might add cache entries
this->SetCacheArgs(mf, args);
// no generator specified on the command line
if(!mf.GetMakefileGenerator())
{

View File

@ -65,11 +65,10 @@ class cmake
*/
int Generate(const std::vector<std::string>&, bool buildMakefiles = true);
/**
* Generate the SourceFilesList from the SourceLists. This should only be
* done once to be safe.
*/
///! Parse command line arguments
void SetArgs(cmMakefile& builder, const std::vector<std::string>&);
///! Parse command line arguments that might set cache values
void SetCacheArgs(cmMakefile& builder, const std::vector<std::string>&);
/**
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries