mirror of
https://github.com/Kitware/CMake.git
synced 2025-06-11 08:32:37 +08:00
GetSafeProperty: return std::string const&
This commit is contained in:
parent
c09efe074d
commit
53675adbcf
@ -77,7 +77,7 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags(
|
||||
cmOutputConverter::FortranFormat format =
|
||||
cmOutputConverter::GetFortranFormat(srcfmt);
|
||||
if (format == cmOutputConverter::FortranFormatNone) {
|
||||
const std::string tgtfmt =
|
||||
std::string const& tgtfmt =
|
||||
this->GeneratorTarget->GetSafeProperty("Fortran_FORMAT");
|
||||
format = cmOutputConverter::GetFortranFormat(tgtfmt);
|
||||
}
|
||||
|
@ -388,14 +388,16 @@ cmProp cmGeneratorTarget::GetProperty(const std::string& prop) const
|
||||
return this->Target->GetProperty(prop);
|
||||
}
|
||||
|
||||
const char* cmGeneratorTarget::GetSafeProperty(const std::string& prop) const
|
||||
std::string const& cmGeneratorTarget::GetSafeProperty(
|
||||
std::string const& 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;
|
||||
}
|
||||
|
||||
const char* cmGeneratorTarget::GetOutputTargetType(
|
||||
@ -3988,7 +3990,8 @@ std::string cmGeneratorTarget::GetPchUseCompileOptions(
|
||||
const std::string useOptVar =
|
||||
cmStrCat(language, "_COMPILE_OPTIONS_USE_PCH");
|
||||
|
||||
const std::string useOptionListProperty = this->GetSafeProperty(useOptVar);
|
||||
std::string const& useOptionListProperty =
|
||||
this->GetSafeProperty(useOptVar);
|
||||
|
||||
useOptionList = cmStrCat(
|
||||
useOptionList, ";",
|
||||
|
@ -80,7 +80,7 @@ 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;
|
||||
std::string const& GetSafeProperty(std::string const& prop) const;
|
||||
bool GetPropertyAsBool(const std::string& prop) const;
|
||||
void GetSourceFiles(std::vector<cmSourceFile*>& files,
|
||||
const std::string& config) const;
|
||||
|
@ -384,9 +384,9 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const
|
||||
}
|
||||
}
|
||||
|
||||
const std::string reuseFrom =
|
||||
std::string const& reuseFrom =
|
||||
target->GetSafeProperty("PRECOMPILE_HEADERS_REUSE_FROM");
|
||||
const std::string compilePdb =
|
||||
std::string const& compilePdb =
|
||||
target->GetSafeProperty("COMPILE_PDB_NAME");
|
||||
|
||||
if (!reuseFrom.empty() && reuseFrom != compilePdb) {
|
||||
|
@ -808,7 +808,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
|
||||
|
||||
// Add flags from target and source file properties.
|
||||
std::string flags;
|
||||
const std::string srcfmt = sf->GetSafeProperty("Fortran_FORMAT");
|
||||
std::string const& srcfmt = sf->GetSafeProperty("Fortran_FORMAT");
|
||||
switch (cmOutputConverter::GetFortranFormat(srcfmt)) {
|
||||
case cmOutputConverter::FortranFormatFixed:
|
||||
flags = "-fixed " + flags;
|
||||
@ -2289,7 +2289,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
|
||||
// Add Fortran source format attribute if property is set.
|
||||
const char* format = nullptr;
|
||||
const std::string tgtfmt = gtgt->GetSafeProperty("Fortran_FORMAT");
|
||||
std::string const& tgtfmt = gtgt->GetSafeProperty("Fortran_FORMAT");
|
||||
switch (cmOutputConverter::GetFortranFormat(tgtfmt)) {
|
||||
case cmOutputConverter::FortranFormatFixed:
|
||||
format = "fixed";
|
||||
@ -2416,7 +2416,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
std::string attribute = prop.substr(16);
|
||||
this->FilterConfigurationAttribute(configName, attribute);
|
||||
if (!attribute.empty()) {
|
||||
const std::string pr = gtgt->GetSafeProperty(prop);
|
||||
std::string const& pr = gtgt->GetSafeProperty(prop);
|
||||
std::string processed = cmGeneratorExpression::Evaluate(
|
||||
pr, this->CurrentLocalGenerator, configName);
|
||||
buildSettings->AddAttribute(attribute,
|
||||
|
@ -2670,7 +2670,8 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
|
||||
|
||||
std::string dest_file = to_file;
|
||||
|
||||
const std::string prefix = target->GetSafeProperty("PREFIX");
|
||||
std::string const& prefix =
|
||||
target->GetSafeProperty("PREFIX");
|
||||
if (!prefix.empty()) {
|
||||
dest_file =
|
||||
cmStrCat(to_dir, prefix, *ReuseFrom, extension);
|
||||
|
@ -95,11 +95,11 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
|
||||
bool const uic = target->GetPropertyAsBool(kw().AUTOUIC);
|
||||
bool const rcc = target->GetPropertyAsBool(kw().AUTORCC);
|
||||
if (moc || uic || rcc) {
|
||||
std::string const mocExec =
|
||||
std::string const& mocExec =
|
||||
target->GetSafeProperty(kw().AUTOMOC_EXECUTABLE);
|
||||
std::string const uicExec =
|
||||
std::string const& uicExec =
|
||||
target->GetSafeProperty(kw().AUTOUIC_EXECUTABLE);
|
||||
std::string const rccExec =
|
||||
std::string const& rccExec =
|
||||
target->GetSafeProperty(kw().AUTORCC_EXECUTABLE);
|
||||
|
||||
// We support Qt4, Qt5 and Qt6
|
||||
|
@ -440,7 +440,8 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
|
||||
|
||||
// Autogen target parallel processing
|
||||
{
|
||||
std::string prop = this->GenTarget->GetSafeProperty("AUTOGEN_PARALLEL");
|
||||
std::string const& prop =
|
||||
this->GenTarget->GetSafeProperty("AUTOGEN_PARALLEL");
|
||||
if (prop.empty() || (prop == "AUTO")) {
|
||||
// Autodetect number of CPUs
|
||||
this->AutogenTarget.Parallel = GetParallelCPUCount();
|
||||
@ -471,7 +472,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
|
||||
this->AutogenTarget.DependOrigin =
|
||||
this->GenTarget->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS");
|
||||
|
||||
std::string const deps =
|
||||
std::string const& deps =
|
||||
this->GenTarget->GetSafeProperty("AUTOGEN_TARGET_DEPENDS");
|
||||
if (!deps.empty()) {
|
||||
for (std::string const& depName : cmExpandedList(deps)) {
|
||||
@ -654,7 +655,7 @@ bool cmQtAutoGenInitializer::InitUic()
|
||||
{
|
||||
// Uic search paths
|
||||
{
|
||||
std::string const usp =
|
||||
std::string const& usp =
|
||||
this->GenTarget->GetSafeProperty("AUTOUIC_SEARCH_PATHS");
|
||||
if (!usp.empty()) {
|
||||
this->Uic.SearchPaths =
|
||||
@ -1794,7 +1795,7 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
|
||||
// Custom executable
|
||||
{
|
||||
std::string const prop = cmStrCat(genVars.GenNameUpper, "_EXECUTABLE");
|
||||
std::string const val = this->GenTarget->Target->GetSafeProperty(prop);
|
||||
std::string const& val = this->GenTarget->Target->GetSafeProperty(prop);
|
||||
if (!val.empty()) {
|
||||
// Evaluate generator expression
|
||||
{
|
||||
|
@ -1789,13 +1789,15 @@ cmProp cmTarget::GetProperty(const std::string& prop) const
|
||||
return retVal;
|
||||
}
|
||||
|
||||
const char* cmTarget::GetSafeProperty(const std::string& prop) const
|
||||
std::string const& cmTarget::GetSafeProperty(std::string const& 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 cmTarget::GetPropertyAsBool(const std::string& prop) const
|
||||
|
@ -174,7 +174,7 @@ 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;
|
||||
std::string const& GetSafeProperty(std::string const& prop) const;
|
||||
bool GetPropertyAsBool(const std::string& prop) const;
|
||||
void CheckProperty(const std::string& prop, cmMakefile* context) const;
|
||||
cmProp GetComputedProperty(const std::string& prop, cmMessenger* messenger,
|
||||
|
@ -909,7 +909,7 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags(
|
||||
|
||||
void cmVisualStudio10TargetGenerator::WriteDotNetDocumentationFile(Elem& e0)
|
||||
{
|
||||
std::string const documentationFile =
|
||||
std::string const& documentationFile =
|
||||
this->GeneratorTarget->GetSafeProperty("VS_DOTNET_DOCUMENTATION_FILE");
|
||||
|
||||
if (this->ProjectType == csproj && !documentationFile.empty()) {
|
||||
|
@ -405,8 +405,9 @@ void cmXCodeScheme::WriteBuildableReference(cmXMLWriter& xout,
|
||||
void cmXCodeScheme::WriteCustomWorkingDirectory(
|
||||
cmXMLWriter& xout, const std::string& configuration)
|
||||
{
|
||||
std::string propertyValue = this->Target->GetTarget()->GetSafeProperty(
|
||||
"XCODE_SCHEME_WORKING_DIRECTORY");
|
||||
std::string const& propertyValue =
|
||||
this->Target->GetTarget()->GetSafeProperty(
|
||||
"XCODE_SCHEME_WORKING_DIRECTORY");
|
||||
if (propertyValue.empty()) {
|
||||
xout.Attribute("useCustomWorkingDirectory", "NO");
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user