diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 9 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 3 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 9 | ||||
-rw-r--r-- | Source/cmSourceFile.h | 3 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 9 | ||||
-rw-r--r-- | Source/cmTarget.h | 3 |
6 files changed, 36 insertions, 0 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 41e55a5..02f181e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -221,6 +221,15 @@ const char* cmGeneratorTarget::GetProperty(const std::string& prop) const return this->Target->GetProperty(prop); } +const char* cmGeneratorTarget::GetSafeProperty(const std::string& prop) const +{ + const char* ret = this->GetProperty(prop); + if (!ret) { + return ""; + } + return ret; +} + const char* cmGeneratorTarget::GetOutputTargetType( cmStateEnums::ArtifactType artifact) const { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index aa36823..5b77610 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -68,7 +68,10 @@ public: std::string GetExportName() const; std::vector<std::string> GetPropertyKeys() const; + ///! Might return a nullptr if the property is not set or invalid const char* GetProperty(const std::string& prop) const; + ///! Always returns a valid pointer + const char* GetSafeProperty(const std::string& prop) const; bool GetPropertyAsBool(const std::string& prop) const; void GetSourceFiles(std::vector<cmSourceFile*>& files, const std::string& config) const; diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 6792d66..05e26ea 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -296,6 +296,15 @@ const char* cmSourceFile::GetProperty(const std::string& prop) const return retVal; } +const char* cmSourceFile::GetSafeProperty(const std::string& prop) const +{ + const char* ret = this->GetProperty(prop); + if (!ret) { + return ""; + } + return ret; +} + 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 1516d98..ab0f229 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -45,7 +45,10 @@ public: void SetProperty(const std::string& prop, const char* value); void AppendProperty(const std::string& prop, const char* value, bool asString = false); + ///! Might return a nullptr if the property is not set or invalid const char* GetProperty(const std::string& prop) const; + ///! Always returns a valid pointer + const char* GetSafeProperty(const std::string& prop) const; bool GetPropertyAsBool(const std::string& prop) const; /** Implement getting a property when called from a CMake language diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1a6e1d1..803a0a9 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1412,6 +1412,15 @@ const char* cmTarget::GetProperty(const std::string& prop) const return retVal; } +const char* cmTarget::GetSafeProperty(const std::string& prop) const +{ + const char* ret = this->GetProperty(prop); + if (!ret) { + return ""; + } + return ret; +} + bool cmTarget::GetPropertyAsBool(const std::string& prop) const { return cmSystemTools::IsOn(this->GetProperty(prop)); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 5f0b33c..7a3ab65 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -200,7 +200,10 @@ public: void SetProperty(const std::string& prop, const char* value); void AppendProperty(const std::string& prop, const char* value, bool asString = false); + ///! Might return a nullptr if the property is not set or invalid const char* GetProperty(const std::string& prop) const; + ///! Always returns a valid pointer + const char* GetSafeProperty(const std::string& prop) const; bool GetPropertyAsBool(const std::string& prop) const; void CheckProperty(const std::string& prop, cmMakefile* context) const; const char* GetComputedProperty(const std::string& prop, |