Fix #12342: Add APPEND_STRING option to set_property()
set_property() has APPEND, which creates a list. E.g. when appending to COMPILE_FLAGS a string is needed, not a list. With the APPEND_STRING option the value is append as string, not as list. Alex
This commit is contained in:
parent
37340687a4
commit
9dbba1b464
|
@ -849,7 +849,8 @@ void cmCacheManager::CacheEntry::SetProperty(const char* prop,
|
|||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
|
||||
const char* value)
|
||||
const char* value,
|
||||
bool asString)
|
||||
{
|
||||
if(strcmp(prop, "TYPE") == 0)
|
||||
{
|
||||
|
@ -859,7 +860,7 @@ void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
|
|||
{
|
||||
if(value)
|
||||
{
|
||||
if(!this->Value.empty() && *value)
|
||||
if(!this->Value.empty() && *value && !asString)
|
||||
{
|
||||
this->Value += ";";
|
||||
}
|
||||
|
@ -868,7 +869,7 @@ void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
|
|||
}
|
||||
else
|
||||
{
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::CACHE);
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::CACHE, asString);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -893,11 +894,12 @@ void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
|
|||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmCacheManager::CacheIterator::AppendProperty(const char* p,
|
||||
const char* v)
|
||||
const char* v,
|
||||
bool asString)
|
||||
{
|
||||
if(!this->IsAtEnd())
|
||||
{
|
||||
this->GetEntry().AppendProperty(p, v);
|
||||
this->GetEntry().AppendProperty(p, v, asString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@ private:
|
|||
cmPropertyMap Properties;
|
||||
const char* GetProperty(const char*) const;
|
||||
void SetProperty(const char* property, const char* value);
|
||||
void AppendProperty(const char* property, const char* value);
|
||||
void AppendProperty(const char* property, const char* value,
|
||||
bool asString=false);
|
||||
bool Initialized;
|
||||
CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
|
||||
{}
|
||||
|
@ -61,7 +62,8 @@ public:
|
|||
bool GetPropertyAsBool(const char*) const ;
|
||||
bool PropertyExists(const char*) const;
|
||||
void SetProperty(const char* property, const char* value);
|
||||
void AppendProperty(const char* property, const char* value);
|
||||
void AppendProperty(const char* property, const char* value,
|
||||
bool asString=false);
|
||||
void SetProperty(const char* property, bool value);
|
||||
const char* GetValue() const { return this->GetEntry().Value.c_str(); }
|
||||
bool GetValueAsBool() const;
|
||||
|
|
|
@ -3332,7 +3332,8 @@ void cmMakefile::SetProperty(const char* prop, const char* value)
|
|||
this->Properties.SetProperty(prop,value,cmProperty::DIRECTORY);
|
||||
}
|
||||
|
||||
void cmMakefile::AppendProperty(const char* prop, const char* value)
|
||||
void cmMakefile::AppendProperty(const char* prop, const char* value,
|
||||
bool asString)
|
||||
{
|
||||
if (!prop)
|
||||
{
|
||||
|
@ -3365,7 +3366,7 @@ void cmMakefile::AppendProperty(const char* prop, const char* value)
|
|||
return;
|
||||
}
|
||||
|
||||
this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY);
|
||||
this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY,asString);
|
||||
}
|
||||
|
||||
const char *cmMakefile::GetPropertyOrDefinition(const char* prop)
|
||||
|
|
|
@ -799,7 +799,7 @@ public:
|
|||
|
||||
///! Set/Get a property of this directory
|
||||
void SetProperty(const char *prop, const char *value);
|
||||
void AppendProperty(const char *prop, const char *value);
|
||||
void AppendProperty(const char *prop, const char *value,bool asString=false);
|
||||
const char *GetProperty(const char *prop);
|
||||
const char *GetPropertyOrDefinition(const char *prop);
|
||||
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
||||
|
|
|
@ -19,10 +19,10 @@ void cmProperty::Set(const char *name, const char *value)
|
|||
this->ValueHasBeenSet = true;
|
||||
}
|
||||
|
||||
void cmProperty::Append(const char *name, const char *value)
|
||||
void cmProperty::Append(const char *name, const char *value, bool asString)
|
||||
{
|
||||
this->Name = name;
|
||||
if(!this->Value.empty() && *value)
|
||||
if(!this->Value.empty() && *value && !asString)
|
||||
{
|
||||
this->Value += ";";
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
void Set(const char *name, const char *value);
|
||||
|
||||
// append to this property
|
||||
void Append(const char *name, const char *value);
|
||||
void Append(const char *name, const char *value, bool asString = false);
|
||||
|
||||
// get the value
|
||||
const char *GetValue() const;
|
||||
|
|
|
@ -59,7 +59,7 @@ void cmPropertyMap::SetProperty(const char *name, const char *value,
|
|||
}
|
||||
|
||||
void cmPropertyMap::AppendProperty(const char* name, const char* value,
|
||||
cmProperty::ScopeType scope)
|
||||
cmProperty::ScopeType scope, bool asString)
|
||||
{
|
||||
// Skip if nothing to append.
|
||||
if(!name || !value || !*value)
|
||||
|
@ -81,7 +81,7 @@ void cmPropertyMap::AppendProperty(const char* name, const char* value,
|
|||
#endif
|
||||
|
||||
cmProperty *prop = this->GetOrCreateProperty(name);
|
||||
prop->Append(name,value);
|
||||
prop->Append(name,value,asString);
|
||||
}
|
||||
|
||||
const char *cmPropertyMap
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
cmProperty::ScopeType scope);
|
||||
|
||||
void AppendProperty(const char* name, const char* value,
|
||||
cmProperty::ScopeType scope);
|
||||
cmProperty::ScopeType scope, bool asString=false);
|
||||
|
||||
const char *GetPropertyValue(const char *name,
|
||||
cmProperty::ScopeType scope,
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
cmSetPropertyCommand::cmSetPropertyCommand()
|
||||
{
|
||||
this->AppendMode = false;
|
||||
this->AppendAsString = false;
|
||||
this->Remove = true;
|
||||
}
|
||||
|
||||
|
@ -83,6 +84,13 @@ bool cmSetPropertyCommand
|
|||
{
|
||||
doing = DoingNone;
|
||||
this->AppendMode = true;
|
||||
this->AppendAsString = false;
|
||||
}
|
||||
else if(*arg == "APPEND_STRING")
|
||||
{
|
||||
doing = DoingNone;
|
||||
this->AppendMode = true;
|
||||
this->AppendAsString = true;
|
||||
}
|
||||
else if(doing == DoingNames)
|
||||
{
|
||||
|
@ -152,7 +160,7 @@ bool cmSetPropertyCommand::HandleGlobalMode()
|
|||
}
|
||||
if(this->AppendMode)
|
||||
{
|
||||
cm->AppendProperty(name, value);
|
||||
cm->AppendProperty(name, value, this->AppendAsString);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -218,7 +226,7 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
|
|||
}
|
||||
if(this->AppendMode)
|
||||
{
|
||||
mf->AppendProperty(name, value);
|
||||
mf->AppendProperty(name, value, this->AppendAsString);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -266,7 +274,7 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target)
|
|||
}
|
||||
if(this->AppendMode)
|
||||
{
|
||||
target->AppendProperty(name, value);
|
||||
target->AppendProperty(name, value, this->AppendAsString);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -317,7 +325,7 @@ bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf)
|
|||
|
||||
if(this->AppendMode)
|
||||
{
|
||||
sf->AppendProperty(name, value);
|
||||
sf->AppendProperty(name, value, this->AppendAsString);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -377,7 +385,7 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test)
|
|||
}
|
||||
if(this->AppendMode)
|
||||
{
|
||||
test->AppendProperty(name, value);
|
||||
test->AppendProperty(name, value, this->AppendAsString);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -464,7 +472,7 @@ bool cmSetPropertyCommand::HandleCacheEntry(cmCacheManager::CacheIterator& it)
|
|||
}
|
||||
if(this->AppendMode)
|
||||
{
|
||||
it.AppendProperty(name, value);
|
||||
it.AppendProperty(name, value, this->AppendAsString);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
" SOURCE [src1 [src2 ...]] |\n"
|
||||
" TEST [test1 [test2 ...]] |\n"
|
||||
" CACHE [entry1 [entry2 ...]]>\n"
|
||||
" [APPEND]\n"
|
||||
" [APPEND] [APPEND_STRING]\n"
|
||||
" PROPERTY <name> [value1 [value2 ...]])\n"
|
||||
"Set one property on zero or more objects of a scope. "
|
||||
"The first argument determines the scope in which the property "
|
||||
|
@ -77,6 +77,9 @@ public:
|
|||
"list. "
|
||||
"If the APPEND option is given the list is appended to any "
|
||||
"existing property value."
|
||||
"If the APPEND_STRING option is given the string is append to any "
|
||||
"existing property value as string, i.e. it results in a longer "
|
||||
"string and not a list of strings."
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -93,6 +96,7 @@ private:
|
|||
std::string PropertyValue;
|
||||
bool Remove;
|
||||
bool AppendMode;
|
||||
bool AppendAsString;
|
||||
|
||||
// Implementation of each property type.
|
||||
bool HandleGlobalMode();
|
||||
|
|
|
@ -291,13 +291,15 @@ void cmSourceFile::SetProperty(const char* prop, const char* value)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmSourceFile::AppendProperty(const char* prop, const char* value)
|
||||
void cmSourceFile::AppendProperty(const char* prop, const char* value,
|
||||
bool asString)
|
||||
{
|
||||
if (!prop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::SOURCE_FILE);
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::SOURCE_FILE,
|
||||
asString);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
///! Set/Get a property of this source file
|
||||
void SetProperty(const char *prop, const char *value);
|
||||
void AppendProperty(const char* prop, const char* value);
|
||||
void AppendProperty(const char* prop, const char* value,bool asString=false);
|
||||
const char *GetProperty(const char *prop) const;
|
||||
bool GetPropertyAsBool(const char *prop) const;
|
||||
|
||||
|
|
|
@ -2191,13 +2191,14 @@ void cmTarget::SetProperty(const char* prop, const char* value)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmTarget::AppendProperty(const char* prop, const char* value)
|
||||
void cmTarget::AppendProperty(const char* prop, const char* value,
|
||||
bool asString)
|
||||
{
|
||||
if (!prop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::TARGET);
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
|
||||
this->MaybeInvalidatePropertyCache(prop);
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ public:
|
|||
|
||||
///! Set/Get a property of this target file
|
||||
void SetProperty(const char *prop, const char *value);
|
||||
void AppendProperty(const char* prop, const char* value);
|
||||
void AppendProperty(const char* prop, const char* value,bool asString=false);
|
||||
const char *GetProperty(const char *prop);
|
||||
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
||||
bool GetPropertyAsBool(const char *prop);
|
||||
|
|
|
@ -84,13 +84,13 @@ void cmTest::SetProperty(const char* prop, const char* value)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmTest::AppendProperty(const char* prop, const char* value)
|
||||
void cmTest::AppendProperty(const char* prop, const char* value, bool asString)
|
||||
{
|
||||
if (!prop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::TEST);
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::TEST, asString);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
///! Set/Get a property of this source file
|
||||
void SetProperty(const char *prop, const char *value);
|
||||
void AppendProperty(const char* prop, const char* value);
|
||||
void AppendProperty(const char* prop, const char* value,bool asString=false);
|
||||
const char *GetProperty(const char *prop) const;
|
||||
bool GetPropertyAsBool(const char *prop) const;
|
||||
cmPropertyMap &GetProperties() { return this->Properties; };
|
||||
|
|
|
@ -3536,7 +3536,7 @@ void cmake::SetProperty(const char* prop, const char* value)
|
|||
this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
|
||||
}
|
||||
|
||||
void cmake::AppendProperty(const char* prop, const char* value)
|
||||
void cmake::AppendProperty(const char* prop, const char* value, bool asString)
|
||||
{
|
||||
if (!prop)
|
||||
{
|
||||
|
@ -3549,7 +3549,7 @@ void cmake::AppendProperty(const char* prop, const char* value)
|
|||
this->DebugConfigs.clear();
|
||||
}
|
||||
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL);
|
||||
this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString);
|
||||
}
|
||||
|
||||
const char *cmake::GetProperty(const char* prop)
|
||||
|
|
|
@ -263,7 +263,7 @@ class cmake
|
|||
|
||||
///! Set/Get a property of this target file
|
||||
void SetProperty(const char *prop, const char *value);
|
||||
void AppendProperty(const char *prop, const char *value);
|
||||
void AppendProperty(const char *prop, const char *value,bool asString=false);
|
||||
const char *GetProperty(const char *prop);
|
||||
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
|
||||
bool GetPropertyAsBool(const char *prop);
|
||||
|
|
|
@ -71,6 +71,24 @@ if (NOT TARGETRESULT)
|
|||
"Error: target result is TARGETRESULT=${TARGETRESULT}")
|
||||
endif (NOT TARGETRESULT)
|
||||
|
||||
# test APPEND and APPEND_STRING set_property()
|
||||
set_property(TARGET Properties PROPERTY FOO foo)
|
||||
set_property(TARGET Properties PROPERTY BAR bar)
|
||||
set_property(TARGET Properties APPEND PROPERTY FOO 123)
|
||||
set_property(TARGET Properties APPEND_STRING PROPERTY BAR 456)
|
||||
|
||||
get_property(APPEND_RESULT TARGET Properties PROPERTY FOO)
|
||||
if (NOT "${APPEND_RESULT}" STREQUAL "foo;123")
|
||||
message(SEND_ERROR
|
||||
"Error: target result is APPEND_RESULT=${APPEND_RESULT}")
|
||||
endif ()
|
||||
|
||||
get_property(APPEND_STRING_RESULT TARGET Properties PROPERTY BAR)
|
||||
if (NOT "${APPEND_STRING_RESULT}" STREQUAL "bar456")
|
||||
message(SEND_ERROR
|
||||
"Error: target result is APPEND_STRING_RESULT=${APPEND_STRING_RESULT}")
|
||||
endif ()
|
||||
|
||||
# test get_property SET
|
||||
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
|
||||
if (NOT TARGETRESULT)
|
||||
|
|
Loading…
Reference in New Issue