mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Reduce the scope of temporary cmProp variables and other improvements
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestUpdateHandler.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmProperty.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
|
||||
@@ -18,7 +17,7 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
|
||||
this->CTest->SetCTestConfiguration(
|
||||
"SourceDirectory",
|
||||
cmSystemTools::CollapseFullPath(
|
||||
cmToCStrSafe(this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY"))),
|
||||
this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY")),
|
||||
this->Quiet);
|
||||
}
|
||||
std::string source_dir =
|
||||
|
||||
@@ -583,14 +583,12 @@ const char* CCONV cmSourceFileGetProperty(void* arg, const char* prop)
|
||||
{
|
||||
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
||||
if (cmSourceFile* rsf = sf->RealSourceFile) {
|
||||
cmProp p = rsf->GetProperty(prop);
|
||||
return cmToCStr(p);
|
||||
return cmToCStr(rsf->GetProperty(prop));
|
||||
}
|
||||
if (!strcmp(prop, "LOCATION")) {
|
||||
return sf->FullPath.c_str();
|
||||
}
|
||||
cmProp retVal = sf->Properties.GetPropertyValue(prop);
|
||||
return cmToCStr(retVal);
|
||||
return cmToCStr(sf->Properties.GetPropertyValue(prop));
|
||||
}
|
||||
|
||||
int CCONV cmSourceFileGetPropertyAsBool(void* arg, const char* prop)
|
||||
|
||||
@@ -990,9 +990,8 @@ cmProp cmGeneratorTarget::GetLanguageExtensions(std::string const& lang) const
|
||||
bool cmGeneratorTarget::GetLanguageStandardRequired(
|
||||
std::string const& lang) const
|
||||
{
|
||||
cmProp p =
|
||||
this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED");
|
||||
return cmIsOn(p);
|
||||
return cmIsOn(
|
||||
this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED"));
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::GetModuleDefinitionSources(
|
||||
|
||||
@@ -280,8 +280,9 @@ bool HandleGlobalMode(cmExecutionStatus& status, const std::string& name,
|
||||
|
||||
// Get the property.
|
||||
cmake* cm = status.GetMakefile().GetCMakeInstance();
|
||||
cmProp p = cm->GetState()->GetGlobalProperty(propertyName);
|
||||
return StoreResult(infoType, status.GetMakefile(), variable, cmToCStr(p));
|
||||
return StoreResult(
|
||||
infoType, status.GetMakefile(), variable,
|
||||
cmToCStr(cm->GetState()->GetGlobalProperty(propertyName)));
|
||||
}
|
||||
|
||||
bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name,
|
||||
@@ -327,8 +328,8 @@ bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name,
|
||||
}
|
||||
|
||||
// Get the property.
|
||||
cmProp p = mf->GetProperty(propertyName);
|
||||
return StoreResult(infoType, status.GetMakefile(), variable, cmToCStr(p));
|
||||
return StoreResult(infoType, status.GetMakefile(), variable,
|
||||
cmToCStr(mf->GetProperty(propertyName)));
|
||||
}
|
||||
|
||||
bool HandleTargetMode(cmExecutionStatus& status, const std::string& name,
|
||||
@@ -358,15 +359,14 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name,
|
||||
}
|
||||
return StoreResult(infoType, status.GetMakefile(), variable, nullptr);
|
||||
}
|
||||
cmProp prop_cstr = nullptr;
|
||||
cmListFileBacktrace bt = status.GetMakefile().GetBacktrace();
|
||||
cmMessenger* messenger = status.GetMakefile().GetMessenger();
|
||||
prop_cstr = target->GetComputedProperty(propertyName, messenger, bt);
|
||||
if (!prop_cstr) {
|
||||
prop_cstr = target->GetProperty(propertyName);
|
||||
cmProp prop = target->GetComputedProperty(propertyName, messenger, bt);
|
||||
if (!prop) {
|
||||
prop = target->GetProperty(propertyName);
|
||||
}
|
||||
return StoreResult(infoType, status.GetMakefile(), variable,
|
||||
prop_cstr ? prop_cstr->c_str() : nullptr);
|
||||
cmToCStr(prop));
|
||||
}
|
||||
status.SetError(cmStrCat("could not find TARGET ", name,
|
||||
". Perhaps it has not yet been created."));
|
||||
|
||||
@@ -721,8 +721,7 @@ void cmGhsMultiTargetGenerator::WriteObjectLangOverride(
|
||||
|
||||
bool cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()
|
||||
{
|
||||
cmProp p = this->GeneratorTarget->GetProperty("ghs_integrity_app");
|
||||
if (p) {
|
||||
if (cmProp p = this->GeneratorTarget->GetProperty("ghs_integrity_app")) {
|
||||
return cmIsOn(*p);
|
||||
}
|
||||
std::vector<cmSourceFile*> sources;
|
||||
|
||||
@@ -380,9 +380,10 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
|
||||
std::string project = target->GetName();
|
||||
std::string location = *expath;
|
||||
|
||||
cmProp p = target->GetProperty("VS_PROJECT_TYPE");
|
||||
this->WriteExternalProject(fout, project, location, cmToCStr(p),
|
||||
target->GetUtilities());
|
||||
this->WriteExternalProject(
|
||||
fout, project, location,
|
||||
cmToCStr(target->GetProperty("VS_PROJECT_TYPE")),
|
||||
target->GetUtilities());
|
||||
written = true;
|
||||
} else {
|
||||
cmProp vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
|
||||
|
||||
@@ -3523,11 +3523,11 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
|
||||
// we don't end up having:
|
||||
// CMakeFiles/<target>.dir/CMakeFiles/<target>.dir/generated_source_file.obj
|
||||
cmProp unitySourceFile = source.GetProperty("UNITY_SOURCE_FILE");
|
||||
cmProp psExtension = source.GetProperty("PCH_EXTENSION");
|
||||
cmProp pchExtension = source.GetProperty("PCH_EXTENSION");
|
||||
const bool isPchObject = objectName.find("cmake_pch") != std::string::npos;
|
||||
if (unitySourceFile || psExtension || isPchObject) {
|
||||
if (psExtension) {
|
||||
customOutputExtension = psExtension->c_str();
|
||||
if (unitySourceFile || pchExtension || isPchObject) {
|
||||
if (pchExtension) {
|
||||
customOutputExtension = pchExtension->c_str();
|
||||
}
|
||||
|
||||
cmsys::RegularExpression var("(CMakeFiles/[^/]+.dir/)");
|
||||
|
||||
@@ -1482,15 +1482,14 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
|
||||
// Include transform property. There is no per-config version.
|
||||
{
|
||||
const char* prop = "IMPLICIT_DEPENDS_INCLUDE_TRANSFORM";
|
||||
cmProp p = parent->GetProperty(prop);
|
||||
this->SetProperty(prop, cmToCStr(p));
|
||||
this->SetProperty(prop, cmToCStr(parent->GetProperty(prop)));
|
||||
}
|
||||
|
||||
// compile definitions property and per-config versions
|
||||
cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043);
|
||||
if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
|
||||
cmProp p = parent->GetProperty("COMPILE_DEFINITIONS");
|
||||
this->SetProperty("COMPILE_DEFINITIONS", cmToCStr(p));
|
||||
this->SetProperty("COMPILE_DEFINITIONS",
|
||||
cmToCStr(parent->GetProperty("COMPILE_DEFINITIONS")));
|
||||
std::vector<std::string> configs =
|
||||
this->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
|
||||
for (std::string const& config : configs) {
|
||||
@@ -1502,12 +1501,11 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
|
||||
}
|
||||
|
||||
// labels
|
||||
cmProp p = parent->GetProperty("LABELS");
|
||||
this->SetProperty("LABELS", cmToCStr(p));
|
||||
this->SetProperty("LABELS", cmToCStr(parent->GetProperty("LABELS")));
|
||||
|
||||
// link libraries
|
||||
p = parent->GetProperty("LINK_LIBRARIES");
|
||||
this->SetProperty("LINK_LIBRARIES", cmToCStr(p));
|
||||
this->SetProperty("LINK_LIBRARIES",
|
||||
cmToCStr(parent->GetProperty("LINK_LIBRARIES")));
|
||||
|
||||
// the initial project name
|
||||
this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName());
|
||||
|
||||
@@ -401,8 +401,7 @@ public:
|
||||
}
|
||||
const char* GetIncludeRegularExpression() const
|
||||
{
|
||||
cmProp p = this->GetProperty("INCLUDE_REGULAR_EXPRESSION");
|
||||
return p ? p->c_str() : nullptr;
|
||||
return cmToCStr(this->GetProperty("INCLUDE_REGULAR_EXPRESSION"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,8 +40,7 @@ bool cmQTWrapCPPCommand(std::vector<std::string> const& args,
|
||||
cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
|
||||
cmSourceFile* sf = mf.GetOrCreateSource(newName, true);
|
||||
if (curr) {
|
||||
cmProp p = curr->GetProperty("ABSTRACT");
|
||||
sf->SetProperty("ABSTRACT", cmToCStr(p));
|
||||
sf->SetProperty("ABSTRACT", cmToCStr(curr->GetProperty("ABSTRACT")));
|
||||
}
|
||||
|
||||
// Compute the name of the header from which to generate the file.
|
||||
|
||||
@@ -1020,9 +1020,9 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
|
||||
cm::string_view tagName =
|
||||
cm::string_view(p).substr(propNamePrefix.length());
|
||||
if (!tagName.empty()) {
|
||||
const std::string& value = *props.GetPropertyValue(p);
|
||||
if (!value.empty()) {
|
||||
e2.Element(tagName, value);
|
||||
cmProp value = props.GetPropertyValue(p);
|
||||
if (cmNonempty(value)) {
|
||||
e2.Element(tagName, *value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4210,8 +4210,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
|
||||
cmLocalGenerator* lg = dt->GetLocalGenerator();
|
||||
std::string name = dt->GetName();
|
||||
std::string path;
|
||||
cmProp p = dt->GetProperty("EXTERNAL_MSPROJECT");
|
||||
if (p) {
|
||||
if (cmProp p = dt->GetProperty("EXTERNAL_MSPROJECT")) {
|
||||
path = *p;
|
||||
} else {
|
||||
path = cmStrCat(lg->GetCurrentBinaryDirectory(), '/', dt->GetName(),
|
||||
@@ -4999,9 +4998,9 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
|
||||
if (cmHasPrefix(p, propNamePrefix)) {
|
||||
std::string tagName = p.substr(propNamePrefix.length());
|
||||
if (!tagName.empty()) {
|
||||
const std::string& val = *props.GetPropertyValue(p);
|
||||
if (!val.empty()) {
|
||||
tags[tagName] = val;
|
||||
cmProp val = props.GetPropertyValue(p);
|
||||
if (cmNonempty(val)) {
|
||||
tags[tagName] = *val;
|
||||
} else {
|
||||
tags.erase(tagName);
|
||||
}
|
||||
|
||||
@@ -2571,8 +2571,7 @@ int cmake::CheckBuildSystem()
|
||||
|
||||
if (this->ClearBuildSystem) {
|
||||
// Get the generator used for this build system.
|
||||
const char* genName =
|
||||
cmToCStr(mf.GetDefinition("CMAKE_DEPENDS_GENERATOR"));
|
||||
std::string genName = mf.GetSafeDefinition("CMAKE_DEPENDS_GENERATOR");
|
||||
if (!cmNonempty(genName)) {
|
||||
genName = "Unix Makefiles";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user