Add GetSafeProperty method to cmTarget, cmGeneratorTarget and cmSourceFile

This commit is contained in:
Sebastian Holtermann 2018-07-02 12:39:54 +02:00
parent 752c2721a1
commit 127094f2f0
6 changed files with 36 additions and 0 deletions

View File

@ -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
{

View File

@ -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;

View File

@ -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));

View File

@ -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

View File

@ -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));

View File

@ -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,