ENH: Add AppendProperty methods for use by C++ code in CMake. Simplify implementation of SET_PROPERTY command by using them.
This commit is contained in:
parent
9e8a1c639a
commit
caca9b8065
|
@ -2613,6 +2613,42 @@ void cmMakefile::SetProperty(const char* prop, const char* value)
|
||||||
this->Properties.SetProperty(prop,value,cmProperty::DIRECTORY);
|
this->Properties.SetProperty(prop,value,cmProperty::DIRECTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmMakefile::AppendProperty(const char* prop, const char* value)
|
||||||
|
{
|
||||||
|
if (!prop)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle special props
|
||||||
|
std::string propname = prop;
|
||||||
|
if ( propname == "INCLUDE_DIRECTORIES" )
|
||||||
|
{
|
||||||
|
std::vector<std::string> varArgsExpanded;
|
||||||
|
cmSystemTools::ExpandListArgument(value, varArgsExpanded);
|
||||||
|
for(std::vector<std::string>::const_iterator vi = varArgsExpanded.begin();
|
||||||
|
vi != varArgsExpanded.end(); ++vi)
|
||||||
|
{
|
||||||
|
this->AddIncludeDirectory(vi->c_str());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( propname == "LINK_DIRECTORIES" )
|
||||||
|
{
|
||||||
|
std::vector<std::string> varArgsExpanded;
|
||||||
|
cmSystemTools::ExpandListArgument(value, varArgsExpanded);
|
||||||
|
for(std::vector<std::string>::const_iterator vi = varArgsExpanded.begin();
|
||||||
|
vi != varArgsExpanded.end(); ++vi)
|
||||||
|
{
|
||||||
|
this->AddLinkDirectory(vi->c_str());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY);
|
||||||
|
}
|
||||||
|
|
||||||
const char *cmMakefile::GetPropertyOrDefinition(const char* prop)
|
const char *cmMakefile::GetPropertyOrDefinition(const char* prop)
|
||||||
{
|
{
|
||||||
const char *ret = this->GetProperty(prop, cmProperty::DIRECTORY);
|
const char *ret = this->GetProperty(prop, cmProperty::DIRECTORY);
|
||||||
|
|
|
@ -713,6 +713,7 @@ public:
|
||||||
|
|
||||||
///! Set/Get a property of this directory
|
///! Set/Get a property of this directory
|
||||||
void SetProperty(const char *prop, const char *value);
|
void SetProperty(const char *prop, const char *value);
|
||||||
|
void AppendProperty(const char *prop, const char *value);
|
||||||
const char *GetProperty(const char *prop);
|
const char *GetProperty(const char *prop);
|
||||||
const char *GetPropertyOrDefinition(const char *prop);
|
const char *GetPropertyOrDefinition(const char *prop);
|
||||||
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
||||||
|
|
|
@ -24,6 +24,17 @@ void cmProperty::Set(const char *name, const char *value)
|
||||||
this->ValueHasBeenSet = true;
|
this->ValueHasBeenSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmProperty::Append(const char *name, const char *value)
|
||||||
|
{
|
||||||
|
this->Name = name;
|
||||||
|
if(!this->Value.empty() && *value)
|
||||||
|
{
|
||||||
|
this->Value += ";";
|
||||||
|
}
|
||||||
|
this->Value += value;
|
||||||
|
this->ValueHasBeenSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
const char *cmProperty::GetValue() const
|
const char *cmProperty::GetValue() const
|
||||||
{
|
{
|
||||||
if (this->ValueHasBeenSet)
|
if (this->ValueHasBeenSet)
|
||||||
|
|
|
@ -28,6 +28,9 @@ public:
|
||||||
// set this property
|
// set this property
|
||||||
void Set(const char *name, const char *value);
|
void Set(const char *name, const char *value);
|
||||||
|
|
||||||
|
// append to this property
|
||||||
|
void Append(const char *name, const char *value);
|
||||||
|
|
||||||
// get the value
|
// get the value
|
||||||
const char *GetValue() const;
|
const char *GetValue() const;
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,32 @@ void cmPropertyMap::SetProperty(const char *name, const char *value,
|
||||||
prop->Set(name,value);
|
prop->Set(name,value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmPropertyMap::AppendProperty(const char* name, const char* value,
|
||||||
|
cmProperty::ScopeType scope)
|
||||||
|
{
|
||||||
|
// Skip if nothing to append.
|
||||||
|
if(!name || !value || !*value)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef CMAKE_STRICT
|
||||||
|
if (!this->CMakeInstance)
|
||||||
|
{
|
||||||
|
cmSystemTools::Error("CMakeInstance not set on a property map!");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->CMakeInstance->RecordPropertyAccess(name,scope);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void)scope;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cmProperty *prop = this->GetOrCreateProperty(name);
|
||||||
|
prop->Append(name,value);
|
||||||
|
}
|
||||||
|
|
||||||
const char *cmPropertyMap
|
const char *cmPropertyMap
|
||||||
::GetPropertyValue(const char *name,
|
::GetPropertyValue(const char *name,
|
||||||
cmProperty::ScopeType scope,
|
cmProperty::ScopeType scope,
|
||||||
|
|
|
@ -29,6 +29,9 @@ public:
|
||||||
void SetProperty(const char *name, const char *value,
|
void SetProperty(const char *name, const char *value,
|
||||||
cmProperty::ScopeType scope);
|
cmProperty::ScopeType scope);
|
||||||
|
|
||||||
|
void AppendProperty(const char* name, const char* value,
|
||||||
|
cmProperty::ScopeType scope);
|
||||||
|
|
||||||
const char *GetPropertyValue(const char *name,
|
const char *GetPropertyValue(const char *name,
|
||||||
cmProperty::ScopeType scope,
|
cmProperty::ScopeType scope,
|
||||||
bool &chain) const;
|
bool &chain) const;
|
||||||
|
|
|
@ -128,37 +128,6 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
bool cmSetPropertyCommand::ConstructValue(std::string& value,
|
|
||||||
const char* old)
|
|
||||||
{
|
|
||||||
if(this->AppendMode)
|
|
||||||
{
|
|
||||||
// This is an append. Start with the original value.
|
|
||||||
if(old)
|
|
||||||
{
|
|
||||||
value = old;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(this->PropertyValue.empty())
|
|
||||||
{
|
|
||||||
// This is a set to no values. Remove the property.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the new value.
|
|
||||||
if(!this->PropertyValue.empty())
|
|
||||||
{
|
|
||||||
if(!value.empty())
|
|
||||||
{
|
|
||||||
value += ";";
|
|
||||||
}
|
|
||||||
value += this->PropertyValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
bool cmSetPropertyCommand::HandleGlobalMode()
|
bool cmSetPropertyCommand::HandleGlobalMode()
|
||||||
{
|
{
|
||||||
|
@ -171,16 +140,13 @@ bool cmSetPropertyCommand::HandleGlobalMode()
|
||||||
// Set or append the property.
|
// Set or append the property.
|
||||||
cmake* cm = this->Makefile->GetCMakeInstance();
|
cmake* cm = this->Makefile->GetCMakeInstance();
|
||||||
const char* name = this->PropertyName.c_str();
|
const char* name = this->PropertyName.c_str();
|
||||||
std::string value;
|
if(this->AppendMode)
|
||||||
if(this->ConstructValue(value, cm->GetProperty(name)))
|
|
||||||
{
|
{
|
||||||
// Set the new property.
|
cm->AppendProperty(name, this->PropertyValue.c_str());
|
||||||
cm->SetProperty(name, value.c_str());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Remove the property.
|
cm->SetProperty(name, this->PropertyValue.c_str());
|
||||||
cm->SetProperty(name, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -235,16 +201,13 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
|
||||||
|
|
||||||
// Set or append the property.
|
// Set or append the property.
|
||||||
const char* name = this->PropertyName.c_str();
|
const char* name = this->PropertyName.c_str();
|
||||||
std::string value;
|
if(this->AppendMode)
|
||||||
if(this->ConstructValue(value, mf->GetProperty(name)))
|
|
||||||
{
|
{
|
||||||
// Set the new property.
|
mf->AppendProperty(name, this->PropertyValue.c_str());
|
||||||
mf->SetProperty(name, value.c_str());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Remove the property.
|
mf->SetProperty(name, this->PropertyValue.c_str());
|
||||||
mf->SetProperty(name, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -283,16 +246,13 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target)
|
||||||
{
|
{
|
||||||
// Set or append the property.
|
// Set or append the property.
|
||||||
const char* name = this->PropertyName.c_str();
|
const char* name = this->PropertyName.c_str();
|
||||||
std::string value;
|
if(this->AppendMode)
|
||||||
if(this->ConstructValue(value, target->GetProperty(name)))
|
|
||||||
{
|
{
|
||||||
// Set the new property.
|
target->AppendProperty(name, this->PropertyValue.c_str());
|
||||||
target->SetProperty(name, value.c_str());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Remove the property.
|
target->SetProperty(name, this->PropertyValue.c_str());
|
||||||
target->SetProperty(name, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -328,16 +288,13 @@ bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf)
|
||||||
{
|
{
|
||||||
// Set or append the property.
|
// Set or append the property.
|
||||||
const char* name = this->PropertyName.c_str();
|
const char* name = this->PropertyName.c_str();
|
||||||
std::string value;
|
if(this->AppendMode)
|
||||||
if(this->ConstructValue(value, sf->GetProperty(name)))
|
|
||||||
{
|
{
|
||||||
// Set the new property.
|
sf->AppendProperty(name, this->PropertyValue.c_str());
|
||||||
sf->SetProperty(name, value.c_str());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Remove the property.
|
sf->SetProperty(name, this->PropertyValue.c_str());
|
||||||
sf->SetProperty(name, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: MACOSX_PACKAGE_LOCATION special case in
|
// TODO: MACOSX_PACKAGE_LOCATION special case in
|
||||||
|
@ -392,16 +349,13 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test)
|
||||||
{
|
{
|
||||||
// Set or append the property.
|
// Set or append the property.
|
||||||
const char* name = this->PropertyName.c_str();
|
const char* name = this->PropertyName.c_str();
|
||||||
std::string value;
|
if(this->AppendMode)
|
||||||
if(this->ConstructValue(value, test->GetProperty(name)))
|
|
||||||
{
|
{
|
||||||
// Set the new property.
|
test->AppendProperty(name, this->PropertyValue.c_str());
|
||||||
test->SetProperty(name, value.c_str());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Remove the property.
|
test->SetProperty(name, this->PropertyValue.c_str());
|
||||||
test->SetProperty(name, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -93,9 +93,6 @@ private:
|
||||||
std::string PropertyValue;
|
std::string PropertyValue;
|
||||||
bool AppendMode;
|
bool AppendMode;
|
||||||
|
|
||||||
// Implementation of value construction.
|
|
||||||
bool ConstructValue(std::string& value, const char* old);
|
|
||||||
|
|
||||||
// Implementation of each property type.
|
// Implementation of each property type.
|
||||||
bool HandleGlobalMode();
|
bool HandleGlobalMode();
|
||||||
bool HandleDirectoryMode();
|
bool HandleDirectoryMode();
|
||||||
|
|
|
@ -270,6 +270,16 @@ void cmSourceFile::SetProperty(const char* prop, const char* value)
|
||||||
this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
|
this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmSourceFile::AppendProperty(const char* prop, const char* value)
|
||||||
|
{
|
||||||
|
if (!prop)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->Properties.AppendProperty(prop, value, cmProperty::SOURCE_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char* cmSourceFile::GetProperty(const char* prop) const
|
const char* cmSourceFile::GetProperty(const char* prop) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
|
|
||||||
///! Set/Get a property of this source file
|
///! Set/Get a property of this source file
|
||||||
void SetProperty(const char *prop, const char *value);
|
void SetProperty(const char *prop, const char *value);
|
||||||
|
void AppendProperty(const char* prop, const char* value);
|
||||||
const char *GetProperty(const char *prop) const;
|
const char *GetProperty(const char *prop) const;
|
||||||
bool GetPropertyAsBool(const char *prop) const;
|
bool GetPropertyAsBool(const char *prop) const;
|
||||||
|
|
||||||
|
|
|
@ -1345,6 +1345,16 @@ void cmTarget::SetProperty(const char* prop, const char* value)
|
||||||
this->Properties.SetProperty(prop, value, cmProperty::TARGET);
|
this->Properties.SetProperty(prop, value, cmProperty::TARGET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmTarget::AppendProperty(const char* prop, const char* value)
|
||||||
|
{
|
||||||
|
if (!prop)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->Properties.AppendProperty(prop, value, cmProperty::TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmTarget::MarkAsImported()
|
void cmTarget::MarkAsImported()
|
||||||
{
|
{
|
||||||
|
|
|
@ -187,6 +187,7 @@ public:
|
||||||
|
|
||||||
///! Set/Get a property of this target file
|
///! Set/Get a property of this target file
|
||||||
void SetProperty(const char *prop, const char *value);
|
void SetProperty(const char *prop, const char *value);
|
||||||
|
void AppendProperty(const char* prop, const char* value);
|
||||||
const char *GetProperty(const char *prop);
|
const char *GetProperty(const char *prop);
|
||||||
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
||||||
bool GetPropertyAsBool(const char *prop);
|
bool GetPropertyAsBool(const char *prop);
|
||||||
|
|
|
@ -84,6 +84,16 @@ void cmTest::SetProperty(const char* prop, const char* value)
|
||||||
this->Properties.SetProperty(prop, value, cmProperty::TEST);
|
this->Properties.SetProperty(prop, value, cmProperty::TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmTest::AppendProperty(const char* prop, const char* value)
|
||||||
|
{
|
||||||
|
if (!prop)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->Properties.AppendProperty(prop, value, cmProperty::TEST);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmTest::SetMakefile(cmMakefile* mf)
|
void cmTest::SetMakefile(cmMakefile* mf)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
|
|
||||||
///! Set/Get a property of this source file
|
///! Set/Get a property of this source file
|
||||||
void SetProperty(const char *prop, const char *value);
|
void SetProperty(const char *prop, const char *value);
|
||||||
|
void AppendProperty(const char* prop, const char* value);
|
||||||
const char *GetProperty(const char *prop) const;
|
const char *GetProperty(const char *prop) const;
|
||||||
bool GetPropertyAsBool(const char *prop) const;
|
bool GetPropertyAsBool(const char *prop) const;
|
||||||
cmPropertyMap &GetProperties() { return this->Properties; };
|
cmPropertyMap &GetProperties() { return this->Properties; };
|
||||||
|
|
|
@ -3435,6 +3435,15 @@ void cmake::SetProperty(const char* prop, const char* value)
|
||||||
this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
|
this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmake::AppendProperty(const char* prop, const char* value)
|
||||||
|
{
|
||||||
|
if (!prop)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL);
|
||||||
|
}
|
||||||
|
|
||||||
const char *cmake::GetProperty(const char* prop)
|
const char *cmake::GetProperty(const char* prop)
|
||||||
{
|
{
|
||||||
return this->GetProperty(prop, cmProperty::GLOBAL);
|
return this->GetProperty(prop, cmProperty::GLOBAL);
|
||||||
|
|
|
@ -258,6 +258,7 @@ class cmake
|
||||||
|
|
||||||
///! Set/Get a property of this target file
|
///! Set/Get a property of this target file
|
||||||
void SetProperty(const char *prop, const char *value);
|
void SetProperty(const char *prop, const char *value);
|
||||||
|
void AppendProperty(const char *prop, const char *value);
|
||||||
const char *GetProperty(const char *prop);
|
const char *GetProperty(const char *prop);
|
||||||
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
||||||
bool GetPropertyAsBool(const char *prop);
|
bool GetPropertyAsBool(const char *prop);
|
||||||
|
|
Loading…
Reference in New Issue