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:
Alex Neundorf 2011-07-13 23:14:41 +02:00
parent 37340687a4
commit 9dbba1b464
19 changed files with 73 additions and 35 deletions

View File

@ -849,7 +849,8 @@ void cmCacheManager::CacheEntry::SetProperty(const char* prop,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCacheManager::CacheEntry::AppendProperty(const char* prop, void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
const char* value) const char* value,
bool asString)
{ {
if(strcmp(prop, "TYPE") == 0) if(strcmp(prop, "TYPE") == 0)
{ {
@ -859,7 +860,7 @@ void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
{ {
if(value) if(value)
{ {
if(!this->Value.empty() && *value) if(!this->Value.empty() && *value && !asString)
{ {
this->Value += ";"; this->Value += ";";
} }
@ -868,7 +869,7 @@ void cmCacheManager::CacheEntry::AppendProperty(const char* prop,
} }
else 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, void cmCacheManager::CacheIterator::AppendProperty(const char* p,
const char* v) const char* v,
bool asString)
{ {
if(!this->IsAtEnd()) if(!this->IsAtEnd())
{ {
this->GetEntry().AppendProperty(p, v); this->GetEntry().AppendProperty(p, v, asString);
} }
} }

View File

@ -41,7 +41,8 @@ private:
cmPropertyMap Properties; cmPropertyMap Properties;
const char* GetProperty(const char*) const; const char* GetProperty(const char*) const;
void SetProperty(const char* property, const char* value); 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; bool Initialized;
CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false) CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false)
{} {}
@ -61,7 +62,8 @@ public:
bool GetPropertyAsBool(const char*) const ; bool GetPropertyAsBool(const char*) const ;
bool PropertyExists(const char*) const; bool PropertyExists(const char*) const;
void SetProperty(const char* property, const char* value); 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); void SetProperty(const char* property, bool value);
const char* GetValue() const { return this->GetEntry().Value.c_str(); } const char* GetValue() const { return this->GetEntry().Value.c_str(); }
bool GetValueAsBool() const; bool GetValueAsBool() const;

View File

@ -3332,7 +3332,8 @@ 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) void cmMakefile::AppendProperty(const char* prop, const char* value,
bool asString)
{ {
if (!prop) if (!prop)
{ {
@ -3365,7 +3366,7 @@ void cmMakefile::AppendProperty(const char* prop, const char* value)
return; return;
} }
this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY); this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY,asString);
} }
const char *cmMakefile::GetPropertyOrDefinition(const char* prop) const char *cmMakefile::GetPropertyOrDefinition(const char* prop)

View File

@ -799,7 +799,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); void AppendProperty(const char *prop, const char *value,bool asString=false);
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);

View File

@ -19,10 +19,10 @@ void cmProperty::Set(const char *name, const char *value)
this->ValueHasBeenSet = true; 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; this->Name = name;
if(!this->Value.empty() && *value) if(!this->Value.empty() && *value && !asString)
{ {
this->Value += ";"; this->Value += ";";
} }

View File

@ -24,7 +24,7 @@ public:
void Set(const char *name, const char *value); void Set(const char *name, const char *value);
// append to this property // 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 // get the value
const char *GetValue() const; const char *GetValue() const;

View File

@ -59,7 +59,7 @@ void cmPropertyMap::SetProperty(const char *name, const char *value,
} }
void cmPropertyMap::AppendProperty(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. // Skip if nothing to append.
if(!name || !value || !*value) if(!name || !value || !*value)
@ -81,7 +81,7 @@ void cmPropertyMap::AppendProperty(const char* name, const char* value,
#endif #endif
cmProperty *prop = this->GetOrCreateProperty(name); cmProperty *prop = this->GetOrCreateProperty(name);
prop->Append(name,value); prop->Append(name,value,asString);
} }
const char *cmPropertyMap const char *cmPropertyMap

View File

@ -25,7 +25,7 @@ public:
cmProperty::ScopeType scope); cmProperty::ScopeType scope);
void AppendProperty(const char* name, const char* value, void AppendProperty(const char* name, const char* value,
cmProperty::ScopeType scope); cmProperty::ScopeType scope, bool asString=false);
const char *GetPropertyValue(const char *name, const char *GetPropertyValue(const char *name,
cmProperty::ScopeType scope, cmProperty::ScopeType scope,

View File

@ -20,6 +20,7 @@
cmSetPropertyCommand::cmSetPropertyCommand() cmSetPropertyCommand::cmSetPropertyCommand()
{ {
this->AppendMode = false; this->AppendMode = false;
this->AppendAsString = false;
this->Remove = true; this->Remove = true;
} }
@ -83,6 +84,13 @@ bool cmSetPropertyCommand
{ {
doing = DoingNone; doing = DoingNone;
this->AppendMode = true; this->AppendMode = true;
this->AppendAsString = false;
}
else if(*arg == "APPEND_STRING")
{
doing = DoingNone;
this->AppendMode = true;
this->AppendAsString = true;
} }
else if(doing == DoingNames) else if(doing == DoingNames)
{ {
@ -152,7 +160,7 @@ bool cmSetPropertyCommand::HandleGlobalMode()
} }
if(this->AppendMode) if(this->AppendMode)
{ {
cm->AppendProperty(name, value); cm->AppendProperty(name, value, this->AppendAsString);
} }
else else
{ {
@ -218,7 +226,7 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
} }
if(this->AppendMode) if(this->AppendMode)
{ {
mf->AppendProperty(name, value); mf->AppendProperty(name, value, this->AppendAsString);
} }
else else
{ {
@ -266,7 +274,7 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target)
} }
if(this->AppendMode) if(this->AppendMode)
{ {
target->AppendProperty(name, value); target->AppendProperty(name, value, this->AppendAsString);
} }
else else
{ {
@ -317,7 +325,7 @@ bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf)
if(this->AppendMode) if(this->AppendMode)
{ {
sf->AppendProperty(name, value); sf->AppendProperty(name, value, this->AppendAsString);
} }
else else
{ {
@ -377,7 +385,7 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test)
} }
if(this->AppendMode) if(this->AppendMode)
{ {
test->AppendProperty(name, value); test->AppendProperty(name, value, this->AppendAsString);
} }
else else
{ {
@ -464,7 +472,7 @@ bool cmSetPropertyCommand::HandleCacheEntry(cmCacheManager::CacheIterator& it)
} }
if(this->AppendMode) if(this->AppendMode)
{ {
it.AppendProperty(name, value); it.AppendProperty(name, value, this->AppendAsString);
} }
else else
{ {

View File

@ -56,7 +56,7 @@ public:
" SOURCE [src1 [src2 ...]] |\n" " SOURCE [src1 [src2 ...]] |\n"
" TEST [test1 [test2 ...]] |\n" " TEST [test1 [test2 ...]] |\n"
" CACHE [entry1 [entry2 ...]]>\n" " CACHE [entry1 [entry2 ...]]>\n"
" [APPEND]\n" " [APPEND] [APPEND_STRING]\n"
" PROPERTY <name> [value1 [value2 ...]])\n" " PROPERTY <name> [value1 [value2 ...]])\n"
"Set one property on zero or more objects of a scope. " "Set one property on zero or more objects of a scope. "
"The first argument determines the scope in which the property " "The first argument determines the scope in which the property "
@ -77,6 +77,9 @@ public:
"list. " "list. "
"If the APPEND option is given the list is appended to any " "If the APPEND option is given the list is appended to any "
"existing property value." "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; std::string PropertyValue;
bool Remove; bool Remove;
bool AppendMode; bool AppendMode;
bool AppendAsString;
// Implementation of each property type. // Implementation of each property type.
bool HandleGlobalMode(); bool HandleGlobalMode();

View File

@ -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) if (!prop)
{ {
return; return;
} }
this->Properties.AppendProperty(prop, value, cmProperty::SOURCE_FILE); this->Properties.AppendProperty(prop, value, cmProperty::SOURCE_FILE,
asString);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -44,7 +44,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); void AppendProperty(const char* prop, const char* value,bool asString=false);
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;

View File

@ -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) if (!prop)
{ {
return; return;
} }
this->Properties.AppendProperty(prop, value, cmProperty::TARGET); this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
this->MaybeInvalidatePropertyCache(prop); this->MaybeInvalidatePropertyCache(prop);
} }

View File

@ -224,7 +224,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); void AppendProperty(const char* prop, const char* value,bool asString=false);
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);

View File

@ -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) if (!prop)
{ {
return; return;
} }
this->Properties.AppendProperty(prop, value, cmProperty::TEST); this->Properties.AppendProperty(prop, value, cmProperty::TEST, asString);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -47,7 +47,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); void AppendProperty(const char* prop, const char* value,bool asString=false);
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; };

View File

@ -3536,7 +3536,7 @@ 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) void cmake::AppendProperty(const char* prop, const char* value, bool asString)
{ {
if (!prop) if (!prop)
{ {
@ -3549,7 +3549,7 @@ void cmake::AppendProperty(const char* prop, const char* value)
this->DebugConfigs.clear(); 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) const char *cmake::GetProperty(const char* prop)

View File

@ -263,7 +263,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); void AppendProperty(const char *prop, const char *value,bool asString=false);
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);

View File

@ -71,6 +71,24 @@ if (NOT TARGETRESULT)
"Error: target result is TARGETRESULT=${TARGETRESULT}") "Error: target result is TARGETRESULT=${TARGETRESULT}")
endif (NOT 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 # test get_property SET
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET) get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
if (NOT TARGETRESULT) if (NOT TARGETRESULT)