From caca9b80652c7c36ed1e39e1faeec64e3397f632 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Jan 2008 18:13:55 -0500 Subject: ENH: Add AppendProperty methods for use by C++ code in CMake. Simplify implementation of SET_PROPERTY command by using them. --- Source/cmMakefile.cxx | 36 +++++++++++++++++++ Source/cmMakefile.h | 1 + Source/cmProperty.cxx | 11 ++++++ Source/cmProperty.h | 3 ++ Source/cmPropertyMap.cxx | 26 ++++++++++++++ Source/cmPropertyMap.h | 3 ++ Source/cmSetPropertyCommand.cxx | 76 ++++++++--------------------------------- Source/cmSetPropertyCommand.h | 3 -- Source/cmSourceFile.cxx | 10 ++++++ Source/cmSourceFile.h | 1 + Source/cmTarget.cxx | 10 ++++++ Source/cmTarget.h | 1 + Source/cmTest.cxx | 10 ++++++ Source/cmTest.h | 1 + Source/cmake.cxx | 9 +++++ Source/cmake.h | 1 + 16 files changed, 138 insertions(+), 64 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1b3ca61..104d007 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 3fa9951..989cd15 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 dbfeae9..5e082dc 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 fc8e277..7d238b6 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 dcd3cb7..db1f75b 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 11d35d6..b058a82 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 3b6a53a..933a3e8 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -129,37 +129,6 @@ bool cmSetPropertyCommand::InitialPass(std::vector const& args) } //---------------------------------------------------------------------------- -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() { if(!this->Names.empty()) @@ -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 c5de8e5..06d4da5 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 f0dbd98..48f975d 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -271,6 +271,16 @@ void cmSourceFile::SetProperty(const char* prop, const char* value) } //---------------------------------------------------------------------------- +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 { // Check for computed properties. diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 9ad6f3e..423e440 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 981ba3f..6f90024 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1346,6 +1346,16 @@ void cmTarget::SetProperty(const char* prop, const char* value) } //---------------------------------------------------------------------------- +void cmTarget::AppendProperty(const char* prop, const char* value) +{ + if (!prop) + { + return; + } + this->Properties.AppendProperty(prop, value, cmProperty::TARGET); +} + +//---------------------------------------------------------------------------- void cmTarget::MarkAsImported() { this->IsImportedTarget = true; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 8439ee1..d1b48e6 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 11c6a8c..0a59fe0 100644 --- a/Source/cmTest.cxx +++ b/Source/cmTest.cxx @@ -85,6 +85,16 @@ void cmTest::SetProperty(const char* prop, const char* value) } //---------------------------------------------------------------------------- +void cmTest::AppendProperty(const char* prop, const char* value) +{ + if (!prop) + { + return; + } + this->Properties.AppendProperty(prop, value, cmProperty::TEST); +} + +//---------------------------------------------------------------------------- void cmTest::SetMakefile(cmMakefile* mf) { // Set our makefile. diff --git a/Source/cmTest.h b/Source/cmTest.h index 9594a46..d4945db 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 c5466a6..e95a3bb 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 b43e770..80c9de8 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); -- cgit v0.12