Merge topic 'safe_property'

42cc0644d5 Autogen: Use default and remove custom GetSafeProperty functions
127094f2f0 Add GetSafeProperty method to cmTarget, cmGeneratorTarget and cmSourceFile

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2185
This commit is contained in:
Brad King 2018-07-03 14:56:25 +00:00 committed by Kitware Robot
commit 4330f10186
7 changed files with 47 additions and 23 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

@ -42,18 +42,6 @@ inline static const char* SafeString(const char* value)
return (value != nullptr) ? value : "";
}
inline static std::string GetSafeProperty(cmGeneratorTarget const* target,
const char* key)
{
return std::string(SafeString(target->GetProperty(key)));
}
inline static std::string GetSafeProperty(cmSourceFile const* sf,
const char* key)
{
return std::string(SafeString(sf->GetProperty(key)));
}
static std::size_t GetParallelCPUCount()
{
static std::size_t count = 0;
@ -249,7 +237,7 @@ void cmQtAutoGenInitializer::InitCustomTargets()
cmSystemTools::ConvertToUnixSlashes(this->DirInfo);
// Autogen build dir
this->DirBuild = GetSafeProperty(this->Target, "AUTOGEN_BUILD_DIR");
this->DirBuild = this->Target->GetSafeProperty("AUTOGEN_BUILD_DIR");
if (this->DirBuild.empty()) {
this->DirBuild = cbd;
this->DirBuild += '/';
@ -281,7 +269,7 @@ void cmQtAutoGenInitializer::InitCustomTargets()
}
// Inherit FOLDER property from target (#13688)
if (folder == nullptr) {
folder = SafeString(this->Target->Target->GetProperty("FOLDER"));
folder = this->Target->GetProperty("FOLDER");
}
if (folder != nullptr) {
this->AutogenFolder = folder;
@ -432,7 +420,7 @@ void cmQtAutoGenInitializer::InitCustomTargets()
qrc.Generated = sf->GetPropertyAsBool("GENERATED");
// RCC options
{
std::string const opts = GetSafeProperty(sf, "AUTORCC_OPTIONS");
std::string const opts = sf->GetSafeProperty("AUTORCC_OPTIONS");
if (!opts.empty()) {
cmSystemTools::ExpandListArgument(opts, qrc.Options);
}
@ -568,7 +556,7 @@ void cmQtAutoGenInitializer::InitCustomTargets()
// Target rcc options
std::vector<std::string> optionsTarget;
cmSystemTools::ExpandListArgument(
GetSafeProperty(this->Target, "AUTORCC_OPTIONS"), optionsTarget);
this->Target->GetSafeProperty("AUTORCC_OPTIONS"), optionsTarget);
// Check if file name is unique
for (Qrc& qrc : this->Qrcs) {
@ -734,7 +722,7 @@ void cmQtAutoGenInitializer::InitCustomTargets()
// Add user defined autogen target dependencies
{
std::string const deps =
GetSafeProperty(this->Target, "AUTOGEN_TARGET_DEPENDS");
this->Target->GetSafeProperty("AUTOGEN_TARGET_DEPENDS");
if (!deps.empty()) {
std::vector<std::string> extraDeps;
cmSystemTools::ExpandListArgument(deps, extraDeps);
@ -907,7 +895,7 @@ void cmQtAutoGenInitializer::SetupCustomTargets()
}
// Parallel processing
this->Parallel = GetSafeProperty(this->Target, "AUTOGEN_PARALLEL");
this->Parallel = this->Target->GetSafeProperty("AUTOGEN_PARALLEL");
if (this->Parallel.empty() || (this->Parallel == "AUTO")) {
// Autodetect number of CPUs
this->Parallel = std::to_string(GetParallelCPUCount());
@ -1000,12 +988,12 @@ void cmQtAutoGenInitializer::SetupCustomTargets()
CWrite("AM_MOC_INCLUDES", this->MocIncludes);
CWriteMap("AM_MOC_INCLUDES", this->MocIncludesConfig);
CWrite("AM_MOC_OPTIONS",
GetSafeProperty(this->Target, "AUTOMOC_MOC_OPTIONS"));
this->Target->GetSafeProperty("AUTOMOC_MOC_OPTIONS"));
CWrite("AM_MOC_RELAXED_MODE", MfDef("CMAKE_AUTOMOC_RELAXED_MODE"));
CWrite("AM_MOC_MACRO_NAMES",
GetSafeProperty(this->Target, "AUTOMOC_MACRO_NAMES"));
this->Target->GetSafeProperty("AUTOMOC_MACRO_NAMES"));
CWrite("AM_MOC_DEPEND_FILTERS",
GetSafeProperty(this->Target, "AUTOMOC_DEPEND_FILTERS"));
this->Target->GetSafeProperty("AUTOMOC_DEPEND_FILTERS"));
CWrite("AM_MOC_PREDEFS_CMD", this->MocPredefsCmd);
}
@ -1182,7 +1170,7 @@ void cmQtAutoGenInitializer::SetupCustomTargetsUic()
// Uic search paths
{
std::string const usp =
GetSafeProperty(this->Target, "AUTOUIC_SEARCH_PATHS");
this->Target->GetSafeProperty("AUTOUIC_SEARCH_PATHS");
if (!usp.empty()) {
cmSystemTools::ExpandListArgument(usp, this->UicSearchPaths);
std::string const srcDir = makefile->GetCurrentSourceDirectory();
@ -1231,7 +1219,7 @@ void cmQtAutoGenInitializer::SetupCustomTargetsUic()
this->UicSkip.insert(absFile);
}
// Check if the .ui file has uic options
std::string const uicOpts = GetSafeProperty(sf, "AUTOUIC_OPTIONS");
std::string const uicOpts = sf->GetSafeProperty("AUTOUIC_OPTIONS");
if (!uicOpts.empty()) {
// Check if file isn't skipped
if (this->UicSkip.count(absFile) == 0) {

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,