1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-20 12:53:55 +08:00

cmLocalGenerator: Populate a container of mappings for replacements

The same variables are replaced/retrieved from cmMakefile again and
again.  Use a container so that they don't have to be retrieved
repeatedly, and to simplify the nested loop.
This commit is contained in:
Stephen Kelly
2016-10-09 10:34:49 +02:00
parent f009d8f5e2
commit b29425f7aa

View File

@@ -693,6 +693,12 @@ std::string cmLocalGenerator::ExpandRuleVariable(
this->GetState()->GetEnabledLanguages(); this->GetState()->GetEnabledLanguages();
std::map<std::string, std::string> compilers; std::map<std::string, std::string> compilers;
std::map<std::string, std::string> variableMappings;
std::string compilerSysroot =
this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
for (std::vector<std::string>::iterator i = enabledLanguages.begin(); for (std::vector<std::string>::iterator i = enabledLanguages.begin();
i != enabledLanguages.end(); ++i) { i != enabledLanguages.end(); ++i) {
std::string const& lang = *i; std::string const& lang = *i;
@@ -700,6 +706,33 @@ std::string cmLocalGenerator::ExpandRuleVariable(
continue; continue;
} }
compilers["CMAKE_" + lang + "_COMPILER"] = lang; compilers["CMAKE_" + lang + "_COMPILER"] = lang;
variableMappings["CMAKE_" + lang + "_COMPILER"] =
this->Makefile->GetSafeDefinition("CMAKE_" + lang + "_COMPILER");
std::string const& compilerArg1 = "CMAKE_" + lang + "_COMPILER_ARG1";
std::string const& compilerTarget = "CMAKE_" + lang + "_COMPILER_TARGET";
std::string const& compilerOptionTarget =
"CMAKE_" + lang + "_COMPILE_OPTIONS_TARGET";
std::string const& compilerExternalToolchain =
"CMAKE_" + lang + "_COMPILER_EXTERNAL_TOOLCHAIN";
std::string const& compilerOptionExternalToolchain =
"CMAKE_" + lang + "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN";
std::string const& compilerOptionSysroot =
"CMAKE_" + lang + "_COMPILE_OPTIONS_SYSROOT";
variableMappings[compilerArg1] =
this->Makefile->GetSafeDefinition(compilerArg1);
variableMappings[compilerTarget] =
this->Makefile->GetSafeDefinition(compilerTarget);
variableMappings[compilerOptionTarget] =
this->Makefile->GetSafeDefinition(compilerOptionTarget);
variableMappings[compilerExternalToolchain] =
this->Makefile->GetSafeDefinition(compilerExternalToolchain);
variableMappings[compilerOptionExternalToolchain] =
this->Makefile->GetSafeDefinition(compilerOptionExternalToolchain);
variableMappings[compilerOptionSysroot] =
this->Makefile->GetSafeDefinition(compilerOptionSysroot);
} }
// loop over language specific replace variables // loop over language specific replace variables
@@ -707,17 +740,8 @@ std::string cmLocalGenerator::ExpandRuleVariable(
replaceIter != cmArrayEnd(ruleReplaceVars); ++replaceIter) { replaceIter != cmArrayEnd(ruleReplaceVars); ++replaceIter) {
for (std::vector<std::string>::iterator i = enabledLanguages.begin(); for (std::vector<std::string>::iterator i = enabledLanguages.begin();
i != enabledLanguages.end(); ++i) { i != enabledLanguages.end(); ++i) {
const char* lang = i->c_str(); std::string const& lang = *i;
std::string actualReplace = *replaceIter; std::string actualReplace = *replaceIter;
// If this is the compiler then look for the extra variable
// _COMPILER_ARG1 which must be the first argument to the compiler
const char* compilerArg1 = CM_NULLPTR;
const char* compilerTarget = CM_NULLPTR;
const char* compilerOptionTarget = CM_NULLPTR;
const char* compilerExternalToolchain = CM_NULLPTR;
const char* compilerOptionExternalToolchain = CM_NULLPTR;
const char* compilerSysroot = CM_NULLPTR;
const char* compilerOptionSysroot = CM_NULLPTR;
std::map<std::string, std::string>::iterator compIt = std::map<std::string, std::string>::iterator compIt =
compilers.find(variable); compilers.find(variable);
@@ -725,40 +749,43 @@ std::string cmLocalGenerator::ExpandRuleVariable(
std::string replace = this->Makefile->GetSafeDefinition(variable); std::string replace = this->Makefile->GetSafeDefinition(variable);
if (compIt != compilers.end()) { if (compIt != compilers.end()) {
std::string arg1 = compIt->first + "_ARG1"; std::string ret = this->ConvertToOutputForExisting(
compilerArg1 = this->Makefile->GetDefinition(arg1); variableMappings["CMAKE_" + compIt->second + "_COMPILER"]);
compilerTarget = this->Makefile->GetDefinition( std::string const& compilerArg1 =
std::string("CMAKE_") + compIt->second + "_COMPILER_TARGET"); variableMappings[compIt->first + "_COMPILER_ARG1"];
compilerOptionTarget = this->Makefile->GetDefinition( std::string const& compilerTarget =
std::string("CMAKE_") + compIt->second + "_COMPILE_OPTIONS_TARGET"); variableMappings["CMAKE_" + compIt->second + "_COMPILER_TARGET"];
compilerExternalToolchain = this->Makefile->GetDefinition( std::string const& compilerOptionTarget =
std::string("CMAKE_") + compIt->second + variableMappings["CMAKE_" + compIt->second +
"_COMPILER_EXTERNAL_TOOLCHAIN"); "_COMPILE_OPTIONS_TARGET"];
compilerOptionExternalToolchain = this->Makefile->GetDefinition( std::string const& compilerExternalToolchain =
std::string("CMAKE_") + compIt->second + variableMappings["CMAKE_" + compIt->second +
"_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN"); "_COMPILER_EXTERNAL_TOOLCHAIN"];
compilerSysroot = this->Makefile->GetDefinition("CMAKE_SYSROOT"); std::string const& compilerOptionExternalToolchain =
compilerOptionSysroot = this->Makefile->GetDefinition( variableMappings["CMAKE_" + compIt->second +
std::string("CMAKE_") + compIt->second + "_COMPILE_OPTIONS_SYSROOT"); "_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN"];
std::string const& compilerOptionSysroot =
variableMappings["CMAKE_" + compIt->second +
"_COMPILE_OPTIONS_SYSROOT"];
std::string ret = this->ConvertToOutputForExisting(replace);
// if there is a required first argument to the compiler add it // if there is a required first argument to the compiler add it
// to the compiler string // to the compiler string
if (compilerArg1) { if (!compilerArg1.empty()) {
ret += " "; ret += " ";
ret += compilerArg1; ret += compilerArg1;
} }
if (compilerTarget && compilerOptionTarget) { if (!compilerTarget.empty() && !compilerOptionTarget.empty()) {
ret += " "; ret += " ";
ret += compilerOptionTarget; ret += compilerOptionTarget;
ret += compilerTarget; ret += compilerTarget;
} }
if (compilerExternalToolchain && compilerOptionExternalToolchain) { if (!compilerExternalToolchain.empty() &&
!compilerOptionExternalToolchain.empty()) {
ret += " "; ret += " ";
ret += compilerOptionExternalToolchain; ret += compilerOptionExternalToolchain;
ret += this->EscapeForShell(compilerExternalToolchain, true); ret += this->EscapeForShell(compilerExternalToolchain, true);
} }
if (compilerSysroot && compilerOptionSysroot) { if (!compilerSysroot.empty() && !compilerOptionSysroot.empty()) {
ret += " "; ret += " ";
ret += compilerOptionSysroot; ret += compilerOptionSysroot;
ret += this->EscapeForShell(compilerSysroot, true); ret += this->EscapeForShell(compilerSysroot, true);