ENH: Allow specifying cmake variables on the command line without specifying the type Bug #118 - Specifying cache entries with -D should not need the type
This commit is contained in:
parent
7d33e05a15
commit
2f98c791fa
@ -79,6 +79,42 @@ bool cmCacheManager::LoadCache(const char* path,
|
|||||||
return this->LoadCache(path, internal, emptySet, emptySet);
|
return this->LoadCache(path, internal, emptySet, emptySet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmCacheManager::ParseEntry(const char* entry,
|
||||||
|
std::string& var,
|
||||||
|
std::string& value)
|
||||||
|
{
|
||||||
|
// input line is: key:type=value
|
||||||
|
cmsys::RegularExpression reg("^([^:]*)=(.*[^\t ]|[\t ]*)[\t ]*$");
|
||||||
|
// input line is: "key":type=value
|
||||||
|
cmsys::RegularExpression regQuoted("^\"([^\"]*)\"=(.*[^\t ]|[\t ]*)[\t ]*$");
|
||||||
|
bool flag = false;
|
||||||
|
if(regQuoted.find(entry))
|
||||||
|
{
|
||||||
|
var = regQuoted.match(1);
|
||||||
|
value = regQuoted.match(2);
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
else if (reg.find(entry))
|
||||||
|
{
|
||||||
|
var = reg.match(1);
|
||||||
|
value = reg.match(2);
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if value is enclosed in single quotes ('foo') then remove them
|
||||||
|
// it is used to enclose trailing space or tab
|
||||||
|
if (flag &&
|
||||||
|
value.size() >= 2 &&
|
||||||
|
value[0] == '\'' &&
|
||||||
|
value[value.size() - 1] == '\'')
|
||||||
|
{
|
||||||
|
value = value.substr(1,
|
||||||
|
value.size() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
bool cmCacheManager::ParseEntry(const char* entry,
|
bool cmCacheManager::ParseEntry(const char* entry,
|
||||||
std::string& var,
|
std::string& var,
|
||||||
std::string& value,
|
std::string& value,
|
||||||
|
@ -31,7 +31,7 @@ class cmCacheManager
|
|||||||
public:
|
public:
|
||||||
class CacheIterator;
|
class CacheIterator;
|
||||||
friend class cmCacheManager::CacheIterator;
|
friend class cmCacheManager::CacheIterator;
|
||||||
enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,UNINITIALIZED };
|
enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC, UNINITIALIZED };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct CacheEntry
|
struct CacheEntry
|
||||||
@ -125,6 +125,10 @@ public:
|
|||||||
std::string& value,
|
std::string& value,
|
||||||
CacheEntryType& type);
|
CacheEntryType& type);
|
||||||
|
|
||||||
|
static bool ParseEntry(const char* entry,
|
||||||
|
std::string& var,
|
||||||
|
std::string& value);
|
||||||
|
|
||||||
///! Get a value from the cache given a key
|
///! Get a value from the cache given a key
|
||||||
const char* GetCacheValue(const char* key) const;
|
const char* GetCacheValue(const char* key) const;
|
||||||
|
|
||||||
|
@ -839,8 +839,15 @@ void cmMakefile::AddCacheDefinition(const char* name, const char* value,
|
|||||||
const char* doc,
|
const char* doc,
|
||||||
cmCacheManager::CacheEntryType type)
|
cmCacheManager::CacheEntryType type)
|
||||||
{
|
{
|
||||||
this->GetCacheManager()->AddCacheEntry(name, value, doc, type);
|
const char* val = value;
|
||||||
this->AddDefinition(name, value);
|
cmCacheManager::CacheIterator it =
|
||||||
|
this->GetCacheManager()->GetCacheIterator(name);
|
||||||
|
if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED))
|
||||||
|
{
|
||||||
|
val = it.GetValue();
|
||||||
|
}
|
||||||
|
this->GetCacheManager()->AddCacheEntry(name, val, doc, type);
|
||||||
|
this->AddDefinition(name, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,8 +185,9 @@ void cmake::SetCacheArgs(const std::vector<std::string>& args)
|
|||||||
{
|
{
|
||||||
std::string entry = arg.substr(2);
|
std::string entry = arg.substr(2);
|
||||||
std::string var, value;
|
std::string var, value;
|
||||||
cmCacheManager::CacheEntryType type;
|
cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
|
||||||
if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type))
|
if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type) ||
|
||||||
|
cmCacheManager::ParseEntry(entry.c_str(), var, value))
|
||||||
{
|
{
|
||||||
this->m_CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
|
this->m_CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
|
||||||
"No help, variable specified on the command line.",
|
"No help, variable specified on the command line.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user