From ec97ed7d0c67b635caf3ada65541b2eaf0818a93 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 2 Sep 2013 16:27:32 -0400 Subject: [PATCH] stringapi: Use strings for property names Property names are always generated by CMake and should never be NULL. --- Source/cmCacheManager.cxx | 34 +++--- Source/cmCacheManager.h | 18 ++-- Source/cmExportFileGenerator.cxx | 15 +-- Source/cmExportFileGenerator.h | 8 +- Source/cmExportTryCompileFileGenerator.cxx | 5 +- Source/cmExportTryCompileFileGenerator.h | 2 +- Source/cmGeneratorTarget.cxx | 4 +- Source/cmGeneratorTarget.h | 4 +- Source/cmGetTargetPropertyCommand.cxx | 12 ++- Source/cmLocalGenerator.cxx | 16 +-- Source/cmLocalGenerator.h | 4 +- Source/cmMakefile.cxx | 89 ++++++---------- Source/cmMakefile.h | 16 +-- Source/cmProperty.cxx | 5 +- Source/cmProperty.h | 5 +- Source/cmPropertyDefinition.cxx | 2 +- Source/cmPropertyDefinition.h | 2 +- Source/cmPropertyDefinitionMap.cxx | 21 +--- Source/cmPropertyDefinitionMap.h | 6 +- Source/cmPropertyMap.cxx | 16 ++- Source/cmPropertyMap.h | 8 +- Source/cmQtAutoGenerators.cxx | 2 +- Source/cmSourceFile.cxx | 25 ++--- Source/cmSourceFile.h | 11 +- Source/cmTarget.cxx | 118 +++++++++------------ Source/cmTarget.h | 19 ++-- Source/cmTargetPropCommandBase.cxx | 5 +- Source/cmTargetPropCommandBase.h | 3 +- Source/cmTest.cxx | 18 +--- Source/cmTest.h | 9 +- Source/cmake.cxx | 50 ++++----- Source/cmake.h | 20 ++-- 32 files changed, 262 insertions(+), 310 deletions(-) diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 9e0064e5d..04542d8c9 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -807,13 +807,13 @@ bool cmCacheManager::CacheIterator::GetValueAsBool() const //---------------------------------------------------------------------------- const char* -cmCacheManager::CacheEntry::GetProperty(const char* prop) const +cmCacheManager::CacheEntry::GetProperty(const std::string& prop) const { - if(strcmp(prop, "TYPE") == 0) + if(prop == "TYPE") { return cmCacheManagerTypes[this->Type]; } - else if(strcmp(prop, "VALUE") == 0) + else if(prop == "VALUE") { return this->Value.c_str(); } @@ -823,14 +823,14 @@ cmCacheManager::CacheEntry::GetProperty(const char* prop) const } //---------------------------------------------------------------------------- -void cmCacheManager::CacheEntry::SetProperty(const char* prop, +void cmCacheManager::CacheEntry::SetProperty(const std::string& prop, const char* value) { - if(strcmp(prop, "TYPE") == 0) + if(prop == "TYPE") { this->Type = cmCacheManager::StringToType(value? value : "STRING"); } - else if(strcmp(prop, "VALUE") == 0) + else if(prop == "VALUE") { this->Value = value? value : ""; } @@ -841,15 +841,15 @@ void cmCacheManager::CacheEntry::SetProperty(const char* prop, } //---------------------------------------------------------------------------- -void cmCacheManager::CacheEntry::AppendProperty(const char* prop, +void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop, const char* value, bool asString) { - if(strcmp(prop, "TYPE") == 0) + if(prop == "TYPE") { this->Type = cmCacheManager::StringToType(value? value : "STRING"); } - else if(strcmp(prop, "VALUE") == 0) + else if(prop == "VALUE") { if(value) { @@ -867,7 +867,8 @@ void cmCacheManager::CacheEntry::AppendProperty(const char* prop, } //---------------------------------------------------------------------------- -const char* cmCacheManager::CacheIterator::GetProperty(const char* prop) const +const char* cmCacheManager::CacheIterator::GetProperty( + const std::string& prop) const { if(!this->IsAtEnd()) { @@ -877,7 +878,8 @@ const char* cmCacheManager::CacheIterator::GetProperty(const char* prop) const } //---------------------------------------------------------------------------- -void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v) +void cmCacheManager::CacheIterator::SetProperty(const std::string& p, + const char* v) { if(!this->IsAtEnd()) { @@ -886,7 +888,7 @@ void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v) } //---------------------------------------------------------------------------- -void cmCacheManager::CacheIterator::AppendProperty(const char* p, +void cmCacheManager::CacheIterator::AppendProperty(const std::string& p, const char* v, bool asString) { @@ -897,7 +899,8 @@ void cmCacheManager::CacheIterator::AppendProperty(const char* p, } //---------------------------------------------------------------------------- -bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* prop) const +bool cmCacheManager::CacheIterator::GetPropertyAsBool( + const std::string& prop) const { if(const char* value = this->GetProperty(prop)) { @@ -907,13 +910,14 @@ bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* prop) const } //---------------------------------------------------------------------------- -void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v) +void cmCacheManager::CacheIterator::SetProperty(const std::string& p, bool v) { this->SetProperty(p, v ? "ON" : "OFF"); } //---------------------------------------------------------------------------- -bool cmCacheManager::CacheIterator::PropertyExists(const char* prop) const +bool cmCacheManager::CacheIterator::PropertyExists( + const std::string& prop) const { return this->GetProperty(prop)? true:false; } diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index f487e8e6b..ac6187bfc 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -39,9 +39,9 @@ private: std::string Value; CacheEntryType Type; cmPropertyMap Properties; - const char* GetProperty(const char*) const; - void SetProperty(const char* property, const char* value); - void AppendProperty(const char* property, const char* value, + const char* GetProperty(const std::string&) const; + void SetProperty(const std::string& property, const char* value); + void AppendProperty(const std::string& property, const char* value, bool asString=false); bool Initialized; CacheEntry() : Value(""), Type(UNINITIALIZED), Initialized(false) @@ -58,13 +58,13 @@ public: void Next(); const char *GetName() const { return this->Position->first.c_str(); } - const char* GetProperty(const char*) const ; - 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, + const char* GetProperty(const std::string&) const ; + bool GetPropertyAsBool(const std::string&) const ; + bool PropertyExists(const std::string&) const; + void SetProperty(const std::string& property, const char* value); + void AppendProperty(const std::string& property, const char* value, bool asString=false); - void SetProperty(const char* property, bool value); + void SetProperty(const std::string& property, bool value); const char* GetValue() const { return this->GetEntry().Value.c_str(); } bool GetValueAsBool() const; void SetValue(const char*); diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 4a161eef7..79566a96d 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -136,7 +136,8 @@ void cmExportFileGenerator::GenerateImportConfig(std::ostream& os, } //---------------------------------------------------------------------------- -void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, +void cmExportFileGenerator::PopulateInterfaceProperty( + const std::string& propName, cmTarget *target, ImportPropertyMap &properties) { @@ -148,8 +149,9 @@ void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, } //---------------------------------------------------------------------------- -void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, - const char *outputName, +void cmExportFileGenerator::PopulateInterfaceProperty( + const std::string& propName, + const cmStdString& outputName, cmTarget *target, cmGeneratorExpression::PreprocessContext preprocessRule, ImportPropertyMap &properties, @@ -391,7 +393,8 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( } //---------------------------------------------------------------------------- -void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, +void cmExportFileGenerator::PopulateInterfaceProperty( + const std::string& propName, cmTarget *target, cmGeneratorExpression::PreprocessContext preprocessRule, ImportPropertyMap &properties, @@ -403,7 +406,7 @@ void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, //---------------------------------------------------------------------------- -void getPropertyContents(cmTarget const* tgt, const char *prop, +void getPropertyContents(cmTarget const* tgt, const std::string& prop, std::set &ifaceProperties) { const char *p = tgt->GetProperty(prop); @@ -825,7 +828,7 @@ void cmExportFileGenerator ::SetImportLinkProperty(std::string const& suffix, cmTarget* target, - const char* propName, + const std::string& propName, std::vector const& entries, ImportPropertyMap& properties, std::vector& missingTargets diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 57ab37899..326fe36c0 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -95,7 +95,7 @@ protected: ImportPropertyMap& properties, std::vector& missingTargets); void SetImportLinkProperty(std::string const& suffix, - cmTarget* target, const char* propName, + cmTarget* target, const std::string& propName, std::vector const& entries, ImportPropertyMap& properties, std::vector& missingTargets); @@ -116,7 +116,7 @@ protected: cmMakefile* mf, cmTarget* depender, cmTarget* dependee) = 0; - void PopulateInterfaceProperty(const char *, + void PopulateInterfaceProperty(const std::string&, cmTarget *target, cmGeneratorExpression::PreprocessContext, ImportPropertyMap &properties, @@ -125,7 +125,7 @@ protected: cmGeneratorExpression::PreprocessContext, ImportPropertyMap &properties, std::vector &missingTargets); - void PopulateInterfaceProperty(const char *propName, cmTarget *target, + void PopulateInterfaceProperty(const std::string& propName, cmTarget *target, ImportPropertyMap &properties); void PopulateCompatibleInterfaceProperties(cmTarget *target, ImportPropertyMap &properties); @@ -174,7 +174,7 @@ protected: std::set ExportedTargets; private: - void PopulateInterfaceProperty(const char *, const char *, + void PopulateInterfaceProperty(const std::string&, const cmStdString&, cmTarget *target, cmGeneratorExpression::PreprocessContext, ImportPropertyMap &properties, diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index a8a91d6d9..fe8c8ecad 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -46,8 +46,9 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os) return true; } -std::string cmExportTryCompileFileGenerator::FindTargets(const char *propName, - cmTarget const* tgt, +std::string cmExportTryCompileFileGenerator::FindTargets( + const std::string& propName, + cmTarget const* tgt, std::set &emitted) { const char *prop = tgt->GetProperty(propName); diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h index 71ac0dd9c..a16fe6b91 100644 --- a/Source/cmExportTryCompileFileGenerator.h +++ b/Source/cmExportTryCompileFileGenerator.h @@ -46,7 +46,7 @@ protected: std::string InstallNameDir(cmTarget* target, const std::string& config); private: - std::string FindTargets(const char *prop, cmTarget const* tgt, + std::string FindTargets(const std::string& prop, cmTarget const* tgt, std::set &emitted); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index a7b2fb69c..d9885b9ad 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -234,7 +234,7 @@ const char *cmGeneratorTarget::GetName() const } //---------------------------------------------------------------------------- -const char *cmGeneratorTarget::GetProperty(const char *prop) const +const char *cmGeneratorTarget::GetProperty(const std::string& prop) const { return this->Target->GetProperty(prop); } @@ -486,7 +486,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(const char *dir, } //---------------------------------------------------------------------------- -bool cmGeneratorTarget::GetPropertyAsBool(const char *prop) const +bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const { return this->Target->GetPropertyAsBool(prop); } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 1e6ce64c0..6e19f7de4 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -28,8 +28,8 @@ public: int GetType() const; const char *GetName() const; - const char *GetProperty(const char *prop) const; - bool GetPropertyAsBool(const char *prop) const; + const char *GetProperty(const std::string& prop) const; + bool GetPropertyAsBool(const std::string& prop) const; void GetSourceFiles(std::vector& files) const; void GetObjectSources(std::vector &) const; diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index 4aa49fe9c..b64f84752 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -22,7 +22,7 @@ bool cmGetTargetPropertyCommand } std::string var = args[0].c_str(); const std::string& targetName = args[1]; - const char *prop = 0; + std::string prop; if(args[2] == "ALIASED_TARGET") { @@ -38,7 +38,11 @@ bool cmGetTargetPropertyCommand else if(cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) { cmTarget& target = *tgt; - prop = target.GetProperty(args[2].c_str()); + const char* prop_cstr = target.GetProperty(args[2].c_str()); + if(prop_cstr) + { + prop = prop_cstr; + } } else { @@ -70,9 +74,9 @@ bool cmGetTargetPropertyCommand } } } - if (prop) + if (!prop.empty()) { - this->Makefile->AddDefinition(var.c_str(), prop); + this->Makefile->AddDefinition(var.c_str(), prop.c_str()); return true; } this->Makefile->AddDefinition(var.c_str(), (var+"-NOTFOUND").c_str()); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index b86a956d4..5bfd9da51 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1156,8 +1156,11 @@ void cmLocalGenerator::ExpandRuleVariables(std::string& s, const RuleVariables& replaceValues) { - this->InsertRuleLauncher(s, replaceValues.CMTarget, - replaceValues.RuleLauncher); + if(replaceValues.RuleLauncher) + { + this->InsertRuleLauncher(s, replaceValues.CMTarget, + replaceValues.RuleLauncher); + } std::string::size_type start = s.find('<'); // no variables to expand if(start == s.npos) @@ -1201,7 +1204,7 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s, //---------------------------------------------------------------------------- const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target, - const char* prop) + const std::string& prop) { if(target) { @@ -1215,7 +1218,7 @@ const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target, //---------------------------------------------------------------------------- void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target, - const char* prop) + const std::string& prop) { if(const char* val = this->GetRuleLauncher(target, prop)) { @@ -3455,11 +3458,12 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const } //---------------------------------------------------------------------------- -static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop) +static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, + const std::string& prop) { if(const char* val = target->GetProperty(prop)) { - mf->AddDefinition(prop, val); + mf->AddDefinition(prop.c_str(), val); } } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 2e0580446..888611db1 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -382,9 +382,9 @@ protected: std::string ExpandRuleVariable(std::string const& variable, const RuleVariables& replaceValues); - const char* GetRuleLauncher(cmTarget* target, const char* prop); + const char* GetRuleLauncher(cmTarget* target, const std::string& prop); void InsertRuleLauncher(std::string& s, cmTarget* target, - const char* prop); + const std::string& prop); /** Convert a target to a utility target for unsupported diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 556e7a444..0fce1f410 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3548,17 +3548,9 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, return res; } -void cmMakefile::SetProperty(const char* prop, const char* value) +void cmMakefile::SetProperty(const std::string& prop, const char* value) { - if (!prop) - { - return; - } - - // handle special props - std::string propname = prop; - - if ( propname == "LINK_DIRECTORIES" ) + if ( prop == "LINK_DIRECTORIES" ) { std::vector varArgsExpanded; if(value) @@ -3568,7 +3560,7 @@ void cmMakefile::SetProperty(const char* prop, const char* value) this->SetLinkDirectories(varArgsExpanded); return; } - if (propname == "INCLUDE_DIRECTORIES") + if (prop == "INCLUDE_DIRECTORIES") { this->IncludeDirectoriesEntries.clear(); if (!value) @@ -3581,7 +3573,7 @@ void cmMakefile::SetProperty(const char* prop, const char* value) cmValueWithOrigin(value, lfbt)); return; } - if (propname == "COMPILE_OPTIONS") + if (prop == "COMPILE_OPTIONS") { this->CompileOptionsEntries.clear(); if (!value) @@ -3593,7 +3585,7 @@ void cmMakefile::SetProperty(const char* prop, const char* value) this->CompileOptionsEntries.push_back(cmValueWithOrigin(value, lfbt)); return; } - if (propname == "COMPILE_DEFINITIONS") + if (prop == "COMPILE_DEFINITIONS") { this->CompileDefinitionsEntries.clear(); if (!value) @@ -3607,13 +3599,13 @@ void cmMakefile::SetProperty(const char* prop, const char* value) return; } - if ( propname == "INCLUDE_REGULAR_EXPRESSION" ) + if ( prop == "INCLUDE_REGULAR_EXPRESSION" ) { this->SetIncludeRegularExpression(value); return; } - if ( propname == "ADDITIONAL_MAKE_CLEAN_FILES" ) + if ( prop == "ADDITIONAL_MAKE_CLEAN_FILES" ) { // This property is not inherrited if ( strcmp(this->GetCurrentDirectory(), @@ -3626,18 +3618,11 @@ 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 std::string& prop, + const char* value, bool asString) { - if (!prop) - { - return; - } - - // handle special props - std::string propname = prop; - - if (propname == "INCLUDE_DIRECTORIES") + if (prop == "INCLUDE_DIRECTORIES") { cmListFileBacktrace lfbt; this->GetBacktrace(lfbt); @@ -3645,7 +3630,7 @@ void cmMakefile::AppendProperty(const char* prop, const char* value, cmValueWithOrigin(value, lfbt)); return; } - if (propname == "COMPILE_OPTIONS") + if (prop == "COMPILE_OPTIONS") { cmListFileBacktrace lfbt; this->GetBacktrace(lfbt); @@ -3653,7 +3638,7 @@ void cmMakefile::AppendProperty(const char* prop, const char* value, cmValueWithOrigin(value, lfbt)); return; } - if (propname == "COMPILE_DEFINITIONS") + if (prop == "COMPILE_DEFINITIONS") { cmListFileBacktrace lfbt; this->GetBacktrace(lfbt); @@ -3661,7 +3646,7 @@ void cmMakefile::AppendProperty(const char* prop, const char* value, cmValueWithOrigin(value, lfbt)); return; } - if ( propname == "LINK_DIRECTORIES" ) + if ( prop == "LINK_DIRECTORIES" ) { std::vector varArgsExpanded; cmSystemTools::ExpandListArgument(value, varArgsExpanded); @@ -3676,32 +3661,28 @@ void cmMakefile::AppendProperty(const char* prop, const char* value, this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY,asString); } -const char *cmMakefile::GetPropertyOrDefinition(const char* prop) const +const char *cmMakefile::GetPropertyOrDefinition(const std::string& prop) const { const char *ret = this->GetProperty(prop, cmProperty::DIRECTORY); if (!ret) { - ret = this->GetDefinition(prop); + ret = this->GetDefinition(prop.c_str()); } return ret; } -const char *cmMakefile::GetProperty(const char* prop) const +const char *cmMakefile::GetProperty(const std::string& prop) const { return this->GetProperty(prop, cmProperty::DIRECTORY); } -const char *cmMakefile::GetProperty(const char* prop, +const char *cmMakefile::GetProperty(const std::string& prop, cmProperty::ScopeType scope) const { - if(!prop) - { - return 0; - } // watch for specific properties static std::string output; output = ""; - if (!strcmp("PARENT_DIRECTORY",prop)) + if (prop == "PARENT_DIRECTORY") { if(cmLocalGenerator* plg = this->LocalGenerator->GetParent()) { @@ -3709,12 +3690,12 @@ const char *cmMakefile::GetProperty(const char* prop, } return output.c_str(); } - else if (!strcmp("INCLUDE_REGULAR_EXPRESSION",prop) ) + else if (prop == "INCLUDE_REGULAR_EXPRESSION" ) { output = this->GetIncludeRegularExpression(); return output.c_str(); } - else if (!strcmp("LISTFILE_STACK",prop)) + else if (prop == "LISTFILE_STACK") { for (std::deque::const_iterator i = this->ListFileStack.begin(); @@ -3728,10 +3709,10 @@ const char *cmMakefile::GetProperty(const char* prop, } return output.c_str(); } - else if (!strcmp("VARIABLES",prop) || !strcmp("CACHE_VARIABLES",prop)) + else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES") { int cacheonly = 0; - if ( !strcmp("CACHE_VARIABLES",prop) ) + if ( prop == "CACHE_VARIABLES" ) { cacheonly = 1; } @@ -3746,17 +3727,17 @@ const char *cmMakefile::GetProperty(const char* prop, } return output.c_str(); } - else if (!strcmp("MACROS",prop)) + else if (prop == "MACROS") { this->GetListOfMacros(output); return output.c_str(); } - else if (!strcmp("DEFINITIONS",prop)) + else if (prop == "DEFINITIONS") { output += this->DefineFlagsOrig; return output.c_str(); } - else if (!strcmp("LINK_DIRECTORIES",prop)) + else if (prop == "LINK_DIRECTORIES") { cmOStringStream str; for (std::vector::const_iterator @@ -3773,7 +3754,7 @@ const char *cmMakefile::GetProperty(const char* prop, output = str.str(); return output.c_str(); } - else if (!strcmp("INCLUDE_DIRECTORIES",prop)) + else if (prop == "INCLUDE_DIRECTORIES") { std::string sep; for (std::vector::const_iterator @@ -3787,7 +3768,7 @@ const char *cmMakefile::GetProperty(const char* prop, } return output.c_str(); } - else if (!strcmp("COMPILE_OPTIONS",prop)) + else if (prop == "COMPILE_OPTIONS") { std::string sep; for (std::vector::const_iterator @@ -3801,7 +3782,7 @@ const char *cmMakefile::GetProperty(const char* prop, } return output.c_str(); } - else if (!strcmp("COMPILE_DEFINITIONS",prop)) + else if (prop == "COMPILE_DEFINITIONS") { std::string sep; for (std::vector::const_iterator @@ -3832,7 +3813,7 @@ const char *cmMakefile::GetProperty(const char* prop, return retVal; } -bool cmMakefile::GetPropertyAsBool(const char* prop) const +bool cmMakefile::GetPropertyAsBool(const std::string& prop) const { return cmSystemTools::IsOn(this->GetProperty(prop)); } @@ -4014,9 +3995,9 @@ void cmMakefile::PopScope() } } -void cmMakefile::RaiseScope(const char *var, const char *varDef) +void cmMakefile::RaiseScope(const cmStdString& var, const char *varDef) { - if (!var || !strlen(var)) + if (var.empty()) { return; } @@ -4025,10 +4006,10 @@ void cmMakefile::RaiseScope(const char *var, const char *varDef) if(cmDefinitions* up = cur.GetParent()) { // First localize the definition in the current scope. - cur.Get(var); + cur.Get(var.c_str()); // Now update the definition in the parent scope. - up->Set(var, varDef); + up->Set(var.c_str(), varDef); } else if(cmLocalGenerator* plg = this->LocalGenerator->GetParent()) { @@ -4038,11 +4019,11 @@ void cmMakefile::RaiseScope(const char *var, const char *varDef) cmMakefile* parent = plg->GetMakefile(); if (varDef) { - parent->AddDefinition(var, varDef); + parent->AddDefinition(var.c_str(), varDef); } else { - parent->RemoveDefinition(var); + parent->RemoveDefinition(var.c_str()); } } else diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 45f3b9f4a..5f4b803d3 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -800,12 +800,14 @@ public: std::string GetModulesFile(const char* name) const; ///! Set/Get a property of this directory - void SetProperty(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 *GetPropertyOrDefinition(const char *prop) const; - const char *GetProperty(const char *prop, cmProperty::ScopeType scope) const; - bool GetPropertyAsBool(const char *prop) const; + void SetProperty(const std::string& prop, const char *value); + void AppendProperty(const std::string& prop, const char *value, + bool asString=false); + const char *GetProperty(const std::string& prop) const; + const char *GetPropertyOrDefinition(const std::string& prop) const; + const char *GetProperty(const std::string& prop, + cmProperty::ScopeType scope) const; + bool GetPropertyAsBool(const std::string& prop) const; const char* GetFeature(const char* feature, const char* config); @@ -835,7 +837,7 @@ public: // push and pop variable scopes void PushScope(); void PopScope(); - void RaiseScope(const char *var, const char *value); + void RaiseScope(const cmStdString& var, const char *value); /** Helper class to push and pop scopes automatically. */ class ScopePushPop diff --git a/Source/cmProperty.cxx b/Source/cmProperty.cxx index 3b37cf3b8..40976db15 100644 --- a/Source/cmProperty.cxx +++ b/Source/cmProperty.cxx @@ -12,14 +12,15 @@ #include "cmProperty.h" #include "cmSystemTools.h" -void cmProperty::Set(const char *name, const char *value) +void cmProperty::Set(const std::string& name, const char *value) { this->Name = name; this->Value = value; this->ValueHasBeenSet = true; } -void cmProperty::Append(const char *name, const char *value, bool asString) +void cmProperty::Append(const std::string& name, const char *value, + bool asString) { this->Name = name; if(!this->Value.empty() && *value && !asString) diff --git a/Source/cmProperty.h b/Source/cmProperty.h index bb75bb0b9..789be1d0c 100644 --- a/Source/cmProperty.h +++ b/Source/cmProperty.h @@ -21,10 +21,11 @@ public: TEST, VARIABLE, CACHED_VARIABLE }; // set this property - void Set(const char *name, const char *value); + void Set(const std::string& name, const char *value); // append to this property - void Append(const char *name, const char *value, bool asString = false); + void Append(const std::string& name, const char *value, + bool asString = false); // get the value const char *GetValue() const; diff --git a/Source/cmPropertyDefinition.cxx b/Source/cmPropertyDefinition.cxx index abc57ce01..1af967c94 100644 --- a/Source/cmPropertyDefinition.cxx +++ b/Source/cmPropertyDefinition.cxx @@ -13,7 +13,7 @@ #include "cmSystemTools.h" void cmPropertyDefinition -::DefineProperty(const char *name, cmProperty::ScopeType scope, +::DefineProperty(const std::string& name, cmProperty::ScopeType scope, const char *shortDescription, const char *fullDescription, bool chain) diff --git a/Source/cmPropertyDefinition.h b/Source/cmPropertyDefinition.h index 1b6a7a6a1..9ca822206 100644 --- a/Source/cmPropertyDefinition.h +++ b/Source/cmPropertyDefinition.h @@ -27,7 +27,7 @@ class cmPropertyDefinition { public: /// Define this property - void DefineProperty(const char *name, cmProperty::ScopeType scope, + void DefineProperty(const std::string& name, cmProperty::ScopeType scope, const char *ShortDescription, const char *FullDescription, bool chained); diff --git a/Source/cmPropertyDefinitionMap.cxx b/Source/cmPropertyDefinitionMap.cxx index db2950461..9ebbaa4d4 100644 --- a/Source/cmPropertyDefinitionMap.cxx +++ b/Source/cmPropertyDefinitionMap.cxx @@ -14,16 +14,11 @@ #include "cmDocumentationSection.h" void cmPropertyDefinitionMap -::DefineProperty(const char *name, cmProperty::ScopeType scope, +::DefineProperty(const cmStdString& name, cmProperty::ScopeType scope, const char *ShortDescription, const char *FullDescription, bool chain) { - if (!name) - { - return; - } - cmPropertyDefinitionMap::iterator it = this->find(name); cmPropertyDefinition *prop; if (it == this->end()) @@ -34,13 +29,8 @@ void cmPropertyDefinitionMap } } -bool cmPropertyDefinitionMap::IsPropertyDefined(const char *name) +bool cmPropertyDefinitionMap::IsPropertyDefined(const cmStdString& name) { - if (!name) - { - return false; - } - cmPropertyDefinitionMap::iterator it = this->find(name); if (it == this->end()) { @@ -50,13 +40,8 @@ bool cmPropertyDefinitionMap::IsPropertyDefined(const char *name) return true; } -bool cmPropertyDefinitionMap::IsPropertyChained(const char *name) +bool cmPropertyDefinitionMap::IsPropertyChained(const cmStdString& name) { - if (!name) - { - return false; - } - cmPropertyDefinitionMap::iterator it = this->find(name); if (it == this->end()) { diff --git a/Source/cmPropertyDefinitionMap.h b/Source/cmPropertyDefinitionMap.h index 736e24371..68c3ff3cd 100644 --- a/Source/cmPropertyDefinitionMap.h +++ b/Source/cmPropertyDefinitionMap.h @@ -21,16 +21,16 @@ public std::map { public: // define the property - void DefineProperty(const char *name, cmProperty::ScopeType scope, + void DefineProperty(const cmStdString& name, cmProperty::ScopeType scope, const char *ShortDescription, const char *FullDescription, bool chain); // has a named property been defined - bool IsPropertyDefined(const char *name); + bool IsPropertyDefined(const cmStdString& name); // is a named property set to chain - bool IsPropertyChained(const char *name); + bool IsPropertyChained(const cmStdString& name); }; #endif diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index e94e3e972..e335b3b55 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -13,7 +13,7 @@ #include "cmSystemTools.h" #include "cmake.h" -cmProperty *cmPropertyMap::GetOrCreateProperty(const char *name) +cmProperty *cmPropertyMap::GetOrCreateProperty(const std::string& name) { cmPropertyMap::iterator it = this->find(name); cmProperty *prop; @@ -28,13 +28,9 @@ cmProperty *cmPropertyMap::GetOrCreateProperty(const char *name) return prop; } -void cmPropertyMap::SetProperty(const char *name, const char *value, +void cmPropertyMap::SetProperty(const std::string& name, const char *value, cmProperty::ScopeType scope) { - if (!name) - { - return; - } if(!value) { this->erase(name); @@ -46,11 +42,11 @@ void cmPropertyMap::SetProperty(const char *name, const char *value, prop->Set(name,value); } -void cmPropertyMap::AppendProperty(const char* name, const char* value, +void cmPropertyMap::AppendProperty(const std::string& name, const char* value, cmProperty::ScopeType scope, bool asString) { // Skip if nothing to append. - if(!name || !value || !*value) + if(!value || !*value) { return; } @@ -61,12 +57,12 @@ void cmPropertyMap::AppendProperty(const char* name, const char* value, } const char *cmPropertyMap -::GetPropertyValue(const char *name, +::GetPropertyValue(const std::string& name, cmProperty::ScopeType scope, bool &chain) const { chain = false; - if (!name) + if (name.empty()) { return 0; } diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 0c3aad461..a13ac351f 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -19,15 +19,15 @@ class cmake; class cmPropertyMap : public std::map { public: - cmProperty *GetOrCreateProperty(const char *name); + cmProperty *GetOrCreateProperty(const std::string& name); - void SetProperty(const char *name, const char *value, + void SetProperty(const std::string& name, const char *value, cmProperty::ScopeType scope); - void AppendProperty(const char* name, const char* value, + void AppendProperty(const std::string& name, const char* value, cmProperty::ScopeType scope, bool asString=false); - const char *GetPropertyValue(const char *name, + const char *GetPropertyValue(const std::string& name, cmProperty::ScopeType scope, bool &chain) const; diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index dfb310e54..7d0ce5f6d 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -105,7 +105,7 @@ static std::string extractSubDir(const std::string& absPath, static void copyTargetProperty(cmTarget* destinationTarget, cmTarget* sourceTarget, - const char* propertyName) + const std::string& propertyName) { const char* propertyValue = sourceTarget->GetProperty(propertyName); if (propertyValue) diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 23422a27e..dd95f23da 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -279,13 +279,8 @@ bool cmSourceFile::Matches(cmSourceFileLocation const& loc) } //---------------------------------------------------------------------------- -void cmSourceFile::SetProperty(const char* prop, const char* value) +void cmSourceFile::SetProperty(const std::string& prop, const char* value) { - if (!prop) - { - return; - } - this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE); std::string ext = @@ -293,7 +288,7 @@ void cmSourceFile::SetProperty(const char* prop, const char* value) if (ext == ".ui") { cmMakefile const* mf = this->Location.GetMakefile(); - if (strcmp(prop, "AUTOUIC_OPTIONS") == 0) + if (prop == "AUTOUIC_OPTIONS") { const_cast(mf)->AddQtUiFileWithOptions(this); } @@ -301,19 +296,15 @@ void cmSourceFile::SetProperty(const char* prop, const char* value) } //---------------------------------------------------------------------------- -void cmSourceFile::AppendProperty(const char* prop, const char* value, +void cmSourceFile::AppendProperty(const std::string& prop, const char* value, bool asString) { - if (!prop) - { - return; - } this->Properties.AppendProperty(prop, value, cmProperty::SOURCE_FILE, asString); } //---------------------------------------------------------------------------- -const char* cmSourceFile::GetPropertyForUser(const char *prop) +const char* cmSourceFile::GetPropertyForUser(const std::string& prop) { // This method is a consequence of design history and backwards // compatibility. GetProperty is (and should be) a const method. @@ -329,7 +320,7 @@ const char* cmSourceFile::GetPropertyForUser(const char *prop) // cmSourceFileLocation class to commit to a particular full path to // the source file as late as possible. If the users requests the // LOCATION property we must commit now. - if(strcmp(prop, "LOCATION") == 0) + if(prop == "LOCATION") { // Commit to a location. this->GetFullPath(); @@ -340,10 +331,10 @@ const char* cmSourceFile::GetPropertyForUser(const char *prop) } //---------------------------------------------------------------------------- -const char* cmSourceFile::GetProperty(const char* prop) const +const char* cmSourceFile::GetProperty(const std::string& prop) const { // Check for computed properties. - if(strcmp(prop, "LOCATION") == 0) + if(prop == "LOCATION") { if(this->FullPath.empty()) { @@ -368,7 +359,7 @@ const char* cmSourceFile::GetProperty(const char* prop) const } //---------------------------------------------------------------------------- -bool cmSourceFile::GetPropertyAsBool(const char* prop) const +bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const { return cmSystemTools::IsOn(this->GetProperty(prop)); } diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 4440b05f6..85d63323c 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -43,14 +43,15 @@ public: void SetCustomCommand(cmCustomCommand *cc); ///! Set/Get a property of this source file - void SetProperty(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; + void SetProperty(const std::string& prop, const char *value); + void AppendProperty(const std::string& prop, + const char* value,bool asString=false); + const char *GetProperty(const std::string& prop) const; + bool GetPropertyAsBool(const std::string& prop) const; /** Implement getting a property when called from a CMake language command like get_property or get_source_file_property. */ - const char* GetPropertyForUser(const char *prop); + const char* GetPropertyForUser(const std::string& prop); /** * The full path to the file. The non-const version of this method diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1c2b27a9e..fc2ab252a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1293,7 +1293,7 @@ void cmTarget::GatherDependencies( const cmMakefile& mf, } //---------------------------------------------------------------------------- -static bool whiteListedInterfaceProperty(const char *prop) +static bool whiteListedInterfaceProperty(const std::string& prop) { if(cmHasLiteralPrefix(prop, "INTERFACE_")) { @@ -1313,8 +1313,8 @@ static bool whiteListedInterfaceProperty(const char *prop) if (std::binary_search(cmArrayBegin(builtIns), cmArrayEnd(builtIns), - prop, - cmStrCmp(prop))) + prop.c_str(), + cmStrCmp(prop.c_str()))) { return true; } @@ -1328,12 +1328,8 @@ static bool whiteListedInterfaceProperty(const char *prop) } //---------------------------------------------------------------------------- -void cmTarget::SetProperty(const char* prop, const char* value) +void cmTarget::SetProperty(const std::string& prop, const char* value) { - if (!prop) - { - return; - } if (this->GetType() == INTERFACE_LIBRARY && !whiteListedInterfaceProperty(prop)) { @@ -1344,14 +1340,14 @@ void cmTarget::SetProperty(const char* prop, const char* value) return; } - if (strcmp(prop, "NAME") == 0) + if (prop == "NAME") { cmOStringStream e; e << "NAME property is read-only\n"; this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); return; } - if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0) + if(prop == "INCLUDE_DIRECTORIES") { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); @@ -1362,7 +1358,7 @@ void cmTarget::SetProperty(const char* prop, const char* value) new cmTargetInternals::TargetPropertyEntry(cge)); return; } - if(strcmp(prop,"COMPILE_OPTIONS") == 0) + if(prop == "COMPILE_OPTIONS") { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); @@ -1373,7 +1369,7 @@ void cmTarget::SetProperty(const char* prop, const char* value) new cmTargetInternals::TargetPropertyEntry(cge)); return; } - if(strcmp(prop,"COMPILE_DEFINITIONS") == 0) + if(prop == "COMPILE_DEFINITIONS") { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); @@ -1384,7 +1380,7 @@ void cmTarget::SetProperty(const char* prop, const char* value) new cmTargetInternals::TargetPropertyEntry(cge)); return; } - if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported()) + if(prop == "EXPORT_NAME" && this->IsImported()) { cmOStringStream e; e << "EXPORT_NAME property can't be set on imported targets (\"" @@ -1392,7 +1388,7 @@ void cmTarget::SetProperty(const char* prop, const char* value) this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); return; } - if (strcmp(prop, "LINK_LIBRARIES") == 0) + if (prop == "LINK_LIBRARIES") { this->Internal->LinkImplementationPropertyEntries.clear(); cmListFileBacktrace lfbt; @@ -1406,13 +1402,9 @@ void cmTarget::SetProperty(const char* prop, const char* value) } //---------------------------------------------------------------------------- -void cmTarget::AppendProperty(const char* prop, const char* value, +void cmTarget::AppendProperty(const std::string& prop, const char* value, bool asString) { - if (!prop) - { - return; - } if (this->GetType() == INTERFACE_LIBRARY && !whiteListedInterfaceProperty(prop)) { @@ -1422,14 +1414,14 @@ void cmTarget::AppendProperty(const char* prop, const char* value, this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); return; } - if (strcmp(prop, "NAME") == 0) + if (prop == "NAME") { cmOStringStream e; e << "NAME property is read-only\n"; this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); return; } - if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0) + if(prop == "INCLUDE_DIRECTORIES") { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); @@ -1438,7 +1430,7 @@ void cmTarget::AppendProperty(const char* prop, const char* value, new cmTargetInternals::TargetPropertyEntry(ge.Parse(value))); return; } - if(strcmp(prop,"COMPILE_OPTIONS") == 0) + if(prop == "COMPILE_OPTIONS") { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); @@ -1447,7 +1439,7 @@ void cmTarget::AppendProperty(const char* prop, const char* value, new cmTargetInternals::TargetPropertyEntry(ge.Parse(value))); return; } - if(strcmp(prop,"COMPILE_DEFINITIONS") == 0) + if(prop == "COMPILE_DEFINITIONS") { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); @@ -1456,7 +1448,7 @@ void cmTarget::AppendProperty(const char* prop, const char* value, new cmTargetInternals::TargetPropertyEntry(ge.Parse(value))); return; } - if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported()) + if(prop == "EXPORT_NAME" && this->IsImported()) { cmOStringStream e; e << "EXPORT_NAME property can't be set on imported targets (\"" @@ -1464,7 +1456,7 @@ void cmTarget::AppendProperty(const char* prop, const char* value, this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); return; } - if (strcmp(prop, "LINK_LIBRARIES") == 0) + if (prop == "LINK_LIBRARIES") { cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); @@ -2215,7 +2207,7 @@ void cmTarget::GetCompileDefinitions(std::vector &list, } //---------------------------------------------------------------------------- -void cmTarget::MaybeInvalidatePropertyCache(const char* prop) +void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop) { // Wipe out maps caching information affected by this property. if(this->IsImported() && cmHasLiteralPrefix(prop, "IMPORTED")) @@ -2230,8 +2222,8 @@ void cmTarget::MaybeInvalidatePropertyCache(const char* prop) //---------------------------------------------------------------------------- static void cmTargetCheckLINK_INTERFACE_LIBRARIES( - const char* prop, const char* value, cmMakefile* context, bool imported - ) + const std::string& prop, const char* value, cmMakefile* context, + bool imported) { // Look for link-type keywords in the value. static cmsys::RegularExpression @@ -2295,7 +2287,8 @@ static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value, } //---------------------------------------------------------------------------- -void cmTarget::CheckProperty(const char* prop, cmMakefile* context) const +void cmTarget::CheckProperty(const std::string& prop, + cmMakefile* context) const { // Certain properties need checking. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) @@ -2579,7 +2572,7 @@ const char* cmTarget::GetFeature(const char* feature, const char* config) const } //---------------------------------------------------------------------------- -const char *cmTarget::GetProperty(const char* prop) const +const char *cmTarget::GetProperty(const std::string& prop) const { return this->GetProperty(prop, cmProperty::TARGET); } @@ -2622,14 +2615,9 @@ bool cmTarget::HandleLocationPropertyPolicy() const } //---------------------------------------------------------------------------- -const char *cmTarget::GetProperty(const char* prop, +const char *cmTarget::GetProperty(const std::string& prop, cmProperty::ScopeType scope) const { - if(!prop) - { - return 0; - } - if (this->GetType() == INTERFACE_LIBRARY && !whiteListedInterfaceProperty(prop)) { @@ -2640,7 +2628,7 @@ const char *cmTarget::GetProperty(const char* prop, return 0; } - if (strcmp(prop, "NAME") == 0) + if (prop == "NAME") { return this->GetName(); } @@ -2653,7 +2641,7 @@ const char *cmTarget::GetProperty(const char* prop, this->GetType() == cmTarget::MODULE_LIBRARY || this->GetType() == cmTarget::UNKNOWN_LIBRARY) { - if(strcmp(prop,"LOCATION") == 0) + if(prop == "LOCATION") { if (!this->HandleLocationPropertyPolicy()) { @@ -2680,13 +2668,13 @@ const char *cmTarget::GetProperty(const char* prop, { return 0; } - std::string configName = prop+9; + const char* configName = prop.c_str() + 9; this->Properties.SetProperty(prop, - this->GetLocation(configName.c_str()), + this->GetLocation(configName), cmProperty::TARGET); } } - if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0) + if(prop == "INCLUDE_DIRECTORIES") { static std::string output; output = ""; @@ -2704,7 +2692,7 @@ const char *cmTarget::GetProperty(const char* prop, } return output.c_str(); } - if(strcmp(prop,"COMPILE_OPTIONS") == 0) + if(prop == "COMPILE_OPTIONS") { static std::string output; output = ""; @@ -2722,7 +2710,7 @@ const char *cmTarget::GetProperty(const char* prop, } return output.c_str(); } - if(strcmp(prop,"COMPILE_DEFINITIONS") == 0) + if(prop == "COMPILE_DEFINITIONS") { static std::string output; output = ""; @@ -2740,7 +2728,7 @@ const char *cmTarget::GetProperty(const char* prop, } return output.c_str(); } - if(strcmp(prop,"LINK_LIBRARIES") == 0) + if(prop == "LINK_LIBRARIES") { static std::string output; output = ""; @@ -2757,12 +2745,12 @@ const char *cmTarget::GetProperty(const char* prop, return output.c_str(); } - if (strcmp(prop,"IMPORTED") == 0) + if (prop == "IMPORTED") { return this->IsImported()?"TRUE":"FALSE"; } - if(!strcmp(prop,"SOURCES")) + if(prop == "SOURCES") { cmOStringStream ss; const char* sep = ""; @@ -2791,7 +2779,7 @@ const char *cmTarget::GetProperty(const char* prop, } // the type property returns what type the target is - if (!strcmp(prop,"TYPE")) + if (prop == "TYPE") { return cmTarget::GetTargetTypeName(this->GetType()); } @@ -2806,7 +2794,7 @@ const char *cmTarget::GetProperty(const char* prop, } //---------------------------------------------------------------------------- -bool cmTarget::GetPropertyAsBool(const char* prop) const +bool cmTarget::GetPropertyAsBool(const std::string& prop) const { return cmSystemTools::IsOn(this->GetProperty(prop)); } @@ -3804,7 +3792,7 @@ bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName, } //---------------------------------------------------------------------------- -void cmTarget::SetPropertyDefault(const char* property, +void cmTarget::SetPropertyDefault(const std::string& property, const char* default_value) { // Compute the name of the variable holding the default value. @@ -4740,7 +4728,7 @@ const char * cmTarget::GetLinkInterfaceDependentNumberMaxProperty( //---------------------------------------------------------------------------- bool isLinkDependentProperty(cmTarget const* tgt, const std::string &p, - const char *interfaceProperty, + const std::string& interfaceProperty, const char *config) { std::vector deps; @@ -5984,14 +5972,14 @@ std::string cmTarget::CheckCMP0004(std::string const& item) const template PropertyType getLinkInterfaceDependentProperty(cmTarget const* tgt, - const std::string prop, + const std::string& prop, const char *config, CompatibleType, PropertyType *); template<> bool getLinkInterfaceDependentProperty(cmTarget const* tgt, - const std::string prop, + const std::string& prop, const char *config, CompatibleType, bool *) { @@ -6000,7 +5988,7 @@ bool getLinkInterfaceDependentProperty(cmTarget const* tgt, template<> const char * getLinkInterfaceDependentProperty(cmTarget const* tgt, - const std::string prop, + const std::string& prop, const char *config, CompatibleType t, const char **) @@ -6025,7 +6013,7 @@ const char * getLinkInterfaceDependentProperty(cmTarget const* tgt, template void checkPropertyConsistency(cmTarget const* depender, cmTarget const* dependee, - const char *propName, + const cmStdString& propName, std::set &emitted, const char *config, CompatibleType t, @@ -6135,32 +6123,32 @@ void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info, } checkPropertyConsistency(this, li->Target, - "COMPATIBLE_INTERFACE_BOOL", - emittedBools, config, BoolType, 0); + std::string("COMPATIBLE_INTERFACE_BOOL"), + emittedBools, config, BoolType, 0); if (cmSystemTools::GetErrorOccuredFlag()) { return; } checkPropertyConsistency(this, li->Target, - "COMPATIBLE_INTERFACE_STRING", - emittedStrings, config, - StringType, 0); + std::string("COMPATIBLE_INTERFACE_STRING"), + emittedStrings, config, + StringType, 0); if (cmSystemTools::GetErrorOccuredFlag()) { return; } checkPropertyConsistency(this, li->Target, - "COMPATIBLE_INTERFACE_NUMBER_MIN", - emittedMinNumbers, config, - NumberMinType, 0); + std::string("COMPATIBLE_INTERFACE_NUMBER_MIN"), + emittedMinNumbers, config, + NumberMinType, 0); if (cmSystemTools::GetErrorOccuredFlag()) { return; } checkPropertyConsistency(this, li->Target, - "COMPATIBLE_INTERFACE_NUMBER_MAX", - emittedMaxNumbers, config, - NumberMaxType, 0); + std::string("COMPATIBLE_INTERFACE_NUMBER_MAX"), + emittedMaxNumbers, config, + NumberMaxType, 0); if (cmSystemTools::GetErrorOccuredFlag()) { return; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 471ea94a9..f0dd7087e 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -223,12 +223,14 @@ public: void FinishConfigure(); ///! Set/Get a property of this target file - void SetProperty(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, cmProperty::ScopeType scope) const; - bool GetPropertyAsBool(const char *prop) const; - void CheckProperty(const char* prop, cmMakefile* context) const; + void SetProperty(const std::string& prop, const char *value); + void AppendProperty(const std::string& prop, const char* value, + bool asString=false); + const char *GetProperty(const std::string& prop) const; + const char *GetProperty(const std::string& prop, + cmProperty::ScopeType scope) const; + bool GetPropertyAsBool(const std::string& prop) const; + void CheckProperty(const std::string& prop, cmMakefile* context) const; const char* GetFeature(const char* feature, const char* config) const; @@ -632,7 +634,8 @@ private: // Use a makefile variable to set a default for the given property. // If the variable is not defined use the given default instead. - void SetPropertyDefault(const char* property, const char* default_value); + void SetPropertyDefault(const std::string& property, + const char* default_value); // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type. const char* GetOutputTargetType(bool implib) const; @@ -729,7 +732,7 @@ private: void ClearLinkMaps(); - void MaybeInvalidatePropertyCache(const char* prop); + void MaybeInvalidatePropertyCache(const std::string& prop); void ProcessSourceExpression(std::string const& expr); diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 195690e7f..2a20516ac 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -16,8 +16,9 @@ //---------------------------------------------------------------------------- bool cmTargetPropCommandBase -::HandleArguments(std::vector const& args, const char *prop, - ArgumentFlags flags) +::HandleArguments(std::vector const& args, + const std::string& prop, + ArgumentFlags flags) { if(args.size() < 2) { diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h index c4028365c..555a08a36 100644 --- a/Source/cmTargetPropCommandBase.h +++ b/Source/cmTargetPropCommandBase.h @@ -29,7 +29,8 @@ public: }; bool HandleArguments(std::vector const& args, - const char *prop, ArgumentFlags flags = NO_FLAGS); + const std::string& prop, + ArgumentFlags flags = NO_FLAGS); cmTypeMacro(cmTargetPropCommandBase, cmCommand); protected: diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx index 9cda97894..4ff71ac9a 100644 --- a/Source/cmTest.cxx +++ b/Source/cmTest.cxx @@ -54,7 +54,7 @@ void cmTest::SetCommand(std::vector const& command) } //---------------------------------------------------------------------------- -const char *cmTest::GetProperty(const char* prop) const +const char *cmTest::GetProperty(const std::string& prop) const { bool chain = false; const char *retVal = @@ -67,28 +67,20 @@ const char *cmTest::GetProperty(const char* prop) const } //---------------------------------------------------------------------------- -bool cmTest::GetPropertyAsBool(const char* prop) const +bool cmTest::GetPropertyAsBool(const std::string& prop) const { return cmSystemTools::IsOn(this->GetProperty(prop)); } //---------------------------------------------------------------------------- -void cmTest::SetProperty(const char* prop, const char* value) +void cmTest::SetProperty(const std::string& prop, const char* value) { - if (!prop) - { - return; - } - this->Properties.SetProperty(prop, value, cmProperty::TEST); } //---------------------------------------------------------------------------- -void cmTest::AppendProperty(const char* prop, const char* value, bool asString) +void cmTest::AppendProperty(const std::string& prop, + const char* value, bool asString) { - if (!prop) - { - return; - } this->Properties.AppendProperty(prop, value, cmProperty::TEST, asString); } diff --git a/Source/cmTest.h b/Source/cmTest.h index 1fe8fc0cc..1becbf79e 100644 --- a/Source/cmTest.h +++ b/Source/cmTest.h @@ -46,10 +46,11 @@ public: void Print() const; ///! Set/Get a property of this source file - void SetProperty(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; + void SetProperty(const std::string& prop, const char *value); + void AppendProperty(const std::string& prop, + const char* value,bool asString=false); + const char *GetProperty(const std::string& prop) const; + bool GetPropertyAsBool(const std::string& prop) const; cmPropertyMap &GetProperties() { return this->Properties; }; /** Get the cmMakefile instance that owns this test. */ diff --git a/Source/cmake.cxx b/Source/cmake.cxx index abbabe762..149e299b5 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2144,7 +2144,8 @@ void cmake::GenerateGraphViz(const char* fileName) const #endif } -void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope, +void cmake::DefineProperty(const std::string& name, + cmProperty::ScopeType scope, const char *ShortDescription, const char *FullDescription, bool chained) @@ -2155,7 +2156,7 @@ void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope, } cmPropertyDefinition *cmake -::GetPropertyDefinition(const char *name, +::GetPropertyDefinition(const std::string& name, cmProperty::ScopeType scope) { if (this->IsPropertyDefined(name,scope)) @@ -2165,25 +2166,22 @@ cmPropertyDefinition *cmake return 0; } -bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope) +bool cmake::IsPropertyDefined(const std::string& name, + cmProperty::ScopeType scope) { return this->PropertyDefinitions[scope].IsPropertyDefined(name); } -bool cmake::IsPropertyChained(const char *name, cmProperty::ScopeType scope) +bool cmake::IsPropertyChained(const std::string& name, + cmProperty::ScopeType scope) { return this->PropertyDefinitions[scope].IsPropertyChained(name); } -void cmake::SetProperty(const char* prop, const char* value) +void cmake::SetProperty(const std::string& prop, const char* value) { - if (!prop) - { - return; - } - // Special hook to invalidate cached value. - if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0) + if(prop == "DEBUG_CONFIGURATIONS") { this->DebugConfigs.clear(); } @@ -2191,15 +2189,11 @@ 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, bool asString) +void cmake::AppendProperty(const std::string& prop, + const char* value, bool asString) { - if (!prop) - { - return; - } - // Special hook to invalidate cached value. - if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0) + if(prop == "DEBUG_CONFIGURATIONS") { this->DebugConfigs.clear(); } @@ -2207,23 +2201,19 @@ void cmake::AppendProperty(const char* prop, const char* value, bool asString) this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString); } -const char *cmake::GetProperty(const char* prop) +const char *cmake::GetProperty(const std::string& prop) { return this->GetProperty(prop, cmProperty::GLOBAL); } -const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope) +const char *cmake::GetProperty(const std::string& prop, + cmProperty::ScopeType scope) { - if(!prop) - { - return 0; - } bool chain = false; // watch for special properties - std::string propname = prop; std::string output = ""; - if ( propname == "CACHE_VARIABLES" ) + if ( prop == "CACHE_VARIABLES" ) { cmCacheManager::CacheIterator cit = this->GetCacheManager()->GetCacheIterator(); @@ -2237,7 +2227,7 @@ const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope) } this->SetProperty("CACHE_VARIABLES", output.c_str()); } - else if ( propname == "COMMANDS" ) + else if ( prop == "COMMANDS" ) { cmake::RegisteredCommandsMap::iterator cmds = this->GetCommands()->begin(); @@ -2252,12 +2242,12 @@ const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope) } this->SetProperty("COMMANDS",output.c_str()); } - else if ( propname == "IN_TRY_COMPILE" ) + else if ( prop == "IN_TRY_COMPILE" ) { this->SetProperty("IN_TRY_COMPILE", this->GetIsInTryCompile()? "1":"0"); } - else if ( propname == "ENABLED_LANGUAGES" ) + else if ( prop == "ENABLED_LANGUAGES" ) { std::string lang; if(this->GlobalGenerator) @@ -2278,7 +2268,7 @@ const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope) return this->Properties.GetPropertyValue(prop, scope, chain); } -bool cmake::GetPropertyAsBool(const char* prop) +bool cmake::GetPropertyAsBool(const std::string& prop) { return cmSystemTools::IsOn(this->GetProperty(prop)); } diff --git a/Source/cmake.h b/Source/cmake.h index dfec55c5c..e89868c7b 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -269,11 +269,13 @@ class cmake void GetGeneratorDocumentation(std::vector&); ///! Set/Get a property of this target file - void SetProperty(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); + void SetProperty(const std::string& prop, const char *value); + void AppendProperty(const std::string& prop, + const char *value,bool asString=false); + const char *GetProperty(const std::string& prop); + const char *GetProperty(const std::string& prop, + cmProperty::ScopeType scope); + bool GetPropertyAsBool(const std::string& prop); // Get the properties cmPropertyMap &GetProperties() { return this->Properties; }; @@ -317,18 +319,18 @@ class cmake void MarkCliAsUsed(const std::string& variable); // Define a property - void DefineProperty(const char *name, cmProperty::ScopeType scope, + void DefineProperty(const std::string& name, cmProperty::ScopeType scope, const char *ShortDescription, const char *FullDescription, bool chain = false); // get property definition cmPropertyDefinition *GetPropertyDefinition - (const char *name, cmProperty::ScopeType scope); + (const std::string& name, cmProperty::ScopeType scope); // Is a property defined? - bool IsPropertyDefined(const char *name, cmProperty::ScopeType scope); - bool IsPropertyChained(const char *name, cmProperty::ScopeType scope); + bool IsPropertyDefined(const std::string& name, cmProperty::ScopeType scope); + bool IsPropertyChained(const std::string& name, cmProperty::ScopeType scope); /** Get the list of configurations (in upper case) considered to be debugging configurations.*/