cmSourceFile::GetPropertyForUser: return cmProp

also fix GetSafeProperty() return type
This commit is contained in:
Vitaly Stakhovsky
2020-11-04 10:00:00 -05:00
parent 622ac065d2
commit c7b50349de
5 changed files with 17 additions and 15 deletions

View File

@@ -391,7 +391,7 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name,
if (cmSourceFile* sf =
directory_makefile.GetOrCreateSource(source_file_absolute_path)) {
return StoreResult(infoType, status.GetMakefile(), variable,
sf->GetPropertyForUser(propertyName));
cmToCStr(sf->GetPropertyForUser(propertyName)));
}
status.SetError(
cmStrCat("given SOURCE name that could not be found or created: ",

View File

@@ -4,6 +4,7 @@
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmProperty.h"
#include "cmSetPropertyCommand.h"
#include "cmSourceFile.h"
@@ -57,14 +58,14 @@ bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args,
}
if (sf) {
const char* prop = nullptr;
cmProp prop = nullptr;
if (!args[property_arg_index].empty()) {
prop = sf->GetPropertyForUser(args[property_arg_index]);
}
if (prop) {
// Set the value on the original Makefile scope, not the scope of the
// requested directory.
status.GetMakefile().AddDefinition(var, prop);
status.GetMakefile().AddDefinition(var, *prop);
return true;
}
}

View File

@@ -807,7 +807,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
qrc.Generated = sf->GetIsGenerated();
// RCC options
{
std::string const opts = sf->GetSafeProperty(kw.AUTORCC_OPTIONS);
std::string const& opts = sf->GetSafeProperty(kw.AUTORCC_OPTIONS);
if (!opts.empty()) {
cmExpandList(opts, qrc.Options);
}

View File

@@ -310,7 +310,7 @@ void cmSourceFile::AppendProperty(const std::string& prop,
}
}
const char* cmSourceFile::GetPropertyForUser(const std::string& prop)
cmProp 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.
@@ -334,13 +334,12 @@ const char* cmSourceFile::GetPropertyForUser(const std::string& prop)
// Similarly, LANGUAGE can be determined by the file extension
// if it is requested by the user.
if (prop == propLANGUAGE) {
// The c_str pointer is valid until `this->Language` is modified.
return this->GetOrDetermineLanguage().c_str();
// The pointer is valid until `this->Language` is modified.
return &this->GetOrDetermineLanguage();
}
// Perform the normal property lookup.
cmProp p = this->GetProperty(prop);
return p ? p->c_str() : nullptr;
return this->GetProperty(prop);
}
cmProp cmSourceFile::GetProperty(const std::string& prop) const
@@ -398,13 +397,15 @@ cmProp cmSourceFile::GetProperty(const std::string& prop) const
return retVal;
}
const char* cmSourceFile::GetSafeProperty(const std::string& prop) const
const std::string& cmSourceFile::GetSafeProperty(const std::string& prop) const
{
cmProp ret = this->GetProperty(prop);
if (!ret) {
return "";
if (ret) {
return *ret;
}
return ret->c_str();
static std::string const s_empty;
return s_empty;
}
bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const

View File

@@ -47,12 +47,12 @@ public:
//! Might return a nullptr if the property is not set or invalid
cmProp GetProperty(const std::string& prop) const;
//! Always returns a valid pointer
const char* GetSafeProperty(const std::string& prop) const;
const std::string& GetSafeProperty(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 std::string& prop);
cmProp GetPropertyForUser(const std::string& prop);
//! Checks is the GENERATED property is set and true
/// @return Equivalent to GetPropertyAsBool("GENERATED")