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