diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1b3ca61dc..104d007ad 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2613,6 +2613,42 @@ 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) +{ + if (!prop) + { + return; + } + + // handle special props + std::string propname = prop; + if ( propname == "INCLUDE_DIRECTORIES" ) + { + std::vector varArgsExpanded; + cmSystemTools::ExpandListArgument(value, varArgsExpanded); + for(std::vector::const_iterator vi = varArgsExpanded.begin(); + vi != varArgsExpanded.end(); ++vi) + { + this->AddIncludeDirectory(vi->c_str()); + } + return; + } + + if ( propname == "LINK_DIRECTORIES" ) + { + std::vector varArgsExpanded; + cmSystemTools::ExpandListArgument(value, varArgsExpanded); + for(std::vector::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 *ret = this->GetProperty(prop, cmProperty::DIRECTORY); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 3fa99513e..989cd1536 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -713,6 +713,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); const char *GetProperty(const char *prop); const char *GetPropertyOrDefinition(const char *prop); const char *GetProperty(const char *prop, cmProperty::ScopeType scope); diff --git a/Source/cmProperty.cxx b/Source/cmProperty.cxx index dbfeae9af..5e082dc99 100644 --- a/Source/cmProperty.cxx +++ b/Source/cmProperty.cxx @@ -24,6 +24,17 @@ void cmProperty::Set(const char *name, const char *value) 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 { if (this->ValueHasBeenSet) diff --git a/Source/cmProperty.h b/Source/cmProperty.h index fc8e2775b..7d238b6ef 100644 --- a/Source/cmProperty.h +++ b/Source/cmProperty.h @@ -28,6 +28,9 @@ public: // set this property void Set(const char *name, const char *value); + // append to this property + void Append(const char *name, const char *value); + // get the value const char *GetValue() const; diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index dcd3cb71a..db1f75b2c 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -63,6 +63,32 @@ void cmPropertyMap::SetProperty(const char *name, const char *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 ::GetPropertyValue(const char *name, cmProperty::ScopeType scope, diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 11d35d689..b058a820e 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -29,6 +29,9 @@ public: void SetProperty(const char *name, const char *value, cmProperty::ScopeType scope); + void AppendProperty(const char* name, const char* value, + cmProperty::ScopeType scope); + const char *GetPropertyValue(const char *name, cmProperty::ScopeType scope, bool &chain) const; diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index 3b6a53af5..933a3e8cf 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -128,37 +128,6 @@ bool cmSetPropertyCommand::InitialPass(std::vector const& args) 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() { @@ -171,16 +140,13 @@ bool cmSetPropertyCommand::HandleGlobalMode() // Set or append the property. cmake* cm = this->Makefile->GetCMakeInstance(); const char* name = this->PropertyName.c_str(); - std::string value; - if(this->ConstructValue(value, cm->GetProperty(name))) + if(this->AppendMode) { - // Set the new property. - cm->SetProperty(name, value.c_str()); + cm->AppendProperty(name, this->PropertyValue.c_str()); } else { - // Remove the property. - cm->SetProperty(name, 0); + cm->SetProperty(name, this->PropertyValue.c_str()); } return true; @@ -235,16 +201,13 @@ bool cmSetPropertyCommand::HandleDirectoryMode() // Set or append the property. const char* name = this->PropertyName.c_str(); - std::string value; - if(this->ConstructValue(value, mf->GetProperty(name))) + if(this->AppendMode) { - // Set the new property. - mf->SetProperty(name, value.c_str()); + mf->AppendProperty(name, this->PropertyValue.c_str()); } else { - // Remove the property. - mf->SetProperty(name, 0); + mf->SetProperty(name, this->PropertyValue.c_str()); } return true; @@ -283,16 +246,13 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target) { // Set or append the property. const char* name = this->PropertyName.c_str(); - std::string value; - if(this->ConstructValue(value, target->GetProperty(name))) + if(this->AppendMode) { - // Set the new property. - target->SetProperty(name, value.c_str()); + target->AppendProperty(name, this->PropertyValue.c_str()); } else { - // Remove the property. - target->SetProperty(name, 0); + target->SetProperty(name, this->PropertyValue.c_str()); } return true; @@ -328,16 +288,13 @@ bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf) { // Set or append the property. const char* name = this->PropertyName.c_str(); - std::string value; - if(this->ConstructValue(value, sf->GetProperty(name))) + if(this->AppendMode) { - // Set the new property. - sf->SetProperty(name, value.c_str()); + sf->AppendProperty(name, this->PropertyValue.c_str()); } else { - // Remove the property. - sf->SetProperty(name, 0); + sf->SetProperty(name, this->PropertyValue.c_str()); } // TODO: MACOSX_PACKAGE_LOCATION special case in @@ -392,16 +349,13 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test) { // Set or append the property. const char* name = this->PropertyName.c_str(); - std::string value; - if(this->ConstructValue(value, test->GetProperty(name))) + if(this->AppendMode) { - // Set the new property. - test->SetProperty(name, value.c_str()); + test->AppendProperty(name, this->PropertyValue.c_str()); } else { - // Remove the property. - test->SetProperty(name, 0); + test->SetProperty(name, this->PropertyValue.c_str()); } return true; diff --git a/Source/cmSetPropertyCommand.h b/Source/cmSetPropertyCommand.h index c5de8e56f..06d4da59b 100644 --- a/Source/cmSetPropertyCommand.h +++ b/Source/cmSetPropertyCommand.h @@ -93,9 +93,6 @@ private: std::string PropertyValue; bool AppendMode; - // Implementation of value construction. - bool ConstructValue(std::string& value, const char* old); - // Implementation of each property type. bool HandleGlobalMode(); bool HandleDirectoryMode(); diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index f0dbd989f..48f975df7 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -270,6 +270,16 @@ void cmSourceFile::SetProperty(const char* prop, const char* value) 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 { diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 9ad6f3e2b..423e44030 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -49,6 +49,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); const char *GetProperty(const char *prop) const; bool GetPropertyAsBool(const char *prop) const; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 981ba3fc0..6f90024ec 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1345,6 +1345,16 @@ void cmTarget::SetProperty(const char* prop, const char* value) 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() { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 8439ee18a..d1b48e668 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -187,6 +187,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); const char *GetProperty(const char *prop); const char *GetProperty(const char *prop, cmProperty::ScopeType scope); bool GetPropertyAsBool(const char *prop); diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx index 11c6a8c80..0a59fe035 100644 --- a/Source/cmTest.cxx +++ b/Source/cmTest.cxx @@ -84,6 +84,16 @@ void cmTest::SetProperty(const char* prop, const char* value) 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) { diff --git a/Source/cmTest.h b/Source/cmTest.h index 9594a46eb..d4945db88 100644 --- a/Source/cmTest.h +++ b/Source/cmTest.h @@ -52,6 +52,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); const char *GetProperty(const char *prop) const; bool GetPropertyAsBool(const char *prop) const; cmPropertyMap &GetProperties() { return this->Properties; }; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index c5466a6ef..e95a3bbe7 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3435,6 +3435,15 @@ 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) +{ + if (!prop) + { + return; + } + this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL); +} + const char *cmake::GetProperty(const char* prop) { return this->GetProperty(prop, cmProperty::GLOBAL); diff --git a/Source/cmake.h b/Source/cmake.h index b43e77018..80c9de8b1 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -258,6 +258,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); const char *GetProperty(const char *prop); const char *GetProperty(const char *prop, cmProperty::ScopeType scope); bool GetPropertyAsBool(const char *prop);