1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 11:18:40 +08:00

GetDefinition: avoid duplicate calls

This commit is contained in:
Vitaly Stakhovsky
2020-05-29 00:00:00 -04:00
parent 1336d11d9c
commit 1e805f53f5
5 changed files with 14 additions and 15 deletions

View File

@@ -921,11 +921,11 @@ int cmCPackGenerator::InstallCMakeProject(
} }
} }
if (nullptr != mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { if (auto d = mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
if (!absoluteDestFiles.empty()) { if (!absoluteDestFiles.empty()) {
absoluteDestFiles += ";"; absoluteDestFiles += ";";
} }
absoluteDestFiles += mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); absoluteDestFiles += d;
cmCPackLogger(cmCPackLog::LOG_DEBUG, cmCPackLogger(cmCPackLog::LOG_DEBUG,
"Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles "Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles
<< std::endl); << std::endl);
@@ -936,8 +936,7 @@ int cmCPackGenerator::InstallCMakeProject(
GetComponentInstallDirNameSuffix(component); GetComponentInstallDirNameSuffix(component);
if (nullptr != this->GetOption(absoluteDestFileComponent)) { if (nullptr != this->GetOption(absoluteDestFileComponent)) {
std::string absoluteDestFilesListComponent = std::string absoluteDestFilesListComponent =
cmStrCat(this->GetOption(absoluteDestFileComponent), ';', cmStrCat(this->GetOption(absoluteDestFileComponent), ';', d);
mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"));
this->SetOption(absoluteDestFileComponent, this->SetOption(absoluteDestFileComponent,
absoluteDestFilesListComponent.c_str()); absoluteDestFilesListComponent.c_str());
} else { } else {

View File

@@ -113,8 +113,8 @@ bool cmForEachFunctionBlocker::ReplayItems(
// At end of for each execute recorded commands // At end of for each execute recorded commands
// store the old value // store the old value
std::string oldDef; std::string oldDef;
if (mf.GetDefinition(this->Args.front())) { if (auto d = mf.GetDefinition(this->Args.front())) {
oldDef = mf.GetDefinition(this->Args.front()); oldDef = d;
} }
auto restore = false; auto restore = false;
@@ -186,8 +186,8 @@ bool cmForEachFunctionBlocker::ReplayZipLists(
// Store old values for iteration variables // Store old values for iteration variables
std::map<std::string, std::string> oldDefs; std::map<std::string, std::string> oldDefs;
for (auto i = 0u; i < values.size(); ++i) { for (auto i = 0u; i < values.size(); ++i) {
if (mf.GetDefinition(iterationVars[i])) { if (auto d = mf.GetDefinition(iterationVars[i])) {
oldDefs.emplace(iterationVars[i], mf.GetDefinition(iterationVars[i])); oldDefs.emplace(iterationVars[i], d);
} }
} }

View File

@@ -1027,8 +1027,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
gt->GetFullNameComponents(prefix, base, suffix, config); gt->GetFullNameComponents(prefix, base, suffix, config);
std::string dbg_suffix = ".dbg"; std::string dbg_suffix = ".dbg";
// TODO: Where to document? // TODO: Where to document?
if (mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX")) { if (auto d = mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX")) {
dbg_suffix = mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX"); dbg_suffix = d;
} }
vars["TARGET_PDB"] = base + suffix + dbg_suffix; vars["TARGET_PDB"] = base + suffix + dbg_suffix;
} }

View File

@@ -749,9 +749,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
if (!mf->GetIsSourceFileTryCompile()) { if (!mf->GetIsSourceFileTryCompile()) {
rule.DepType = "gcc"; rule.DepType = "gcc";
rule.DepFile = "$DEP_FILE"; rule.DepFile = "$DEP_FILE";
const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER") auto d = mf->GetDefinition("CMAKE_C_COMPILER");
? mf->GetSafeDefinition("CMAKE_C_COMPILER") const std::string cl =
: mf->GetSafeDefinition("CMAKE_CXX_COMPILER"); d ? d : mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
cldeps = cmStrCat('"', cmSystemTools::GetCMClDepsCommand(), "\" ", lang, cldeps = cmStrCat('"', cmSystemTools::GetCMClDepsCommand(), "\" ", lang,
' ', vars.Source, " $DEP_FILE $out \"", ' ', vars.Source, " $DEP_FILE $out \"",
mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"), mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"),

View File

@@ -84,8 +84,8 @@ bool cmUtilitySourceCommand(std::vector<std::string> const& args,
std::string utilityDirectory = std::string utilityDirectory =
status.GetMakefile().GetCurrentBinaryDirectory(); status.GetMakefile().GetCurrentBinaryDirectory();
std::string exePath; std::string exePath;
if (status.GetMakefile().GetDefinition("EXECUTABLE_OUTPUT_PATH")) { if (auto d = status.GetMakefile().GetDefinition("EXECUTABLE_OUTPUT_PATH")) {
exePath = status.GetMakefile().GetDefinition("EXECUTABLE_OUTPUT_PATH"); exePath = d;
} }
if (!exePath.empty()) { if (!exePath.empty()) {
utilityDirectory = exePath; utilityDirectory = exePath;