summaryrefslogtreecommitdiff
path: root/Source/cmNinjaNormalTargetGenerator.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2019-11-14 11:38:35 -0500
committerKyle Edwards <kyle.edwards@kitware.com>2019-12-13 10:51:46 -0500
commit3bc63e99e44b3ef82c19d018f939ea839882a131 (patch)
tree3cc8752c0850fc19ec1962580dc91c7cabdeebaf /Source/cmNinjaNormalTargetGenerator.cxx
parent4047056a5432b6e9f3fb65a1f846a9373cb25460 (diff)
downloadcmake-3bc63e99e44b3ef82c19d018f939ea839882a131.tar.gz
Refactor: Prepare Ninja generator for multi-config
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx321
1 files changed, 175 insertions, 146 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 72bef215ea..5601a33d43 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -41,33 +41,25 @@
cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
cmGeneratorTarget* target)
: cmNinjaTargetGenerator(target)
- , TargetLinkLanguage("")
{
- this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName());
- if (target->GetType() == cmStateEnums::EXECUTABLE) {
- this->TargetNames = this->GetGeneratorTarget()->GetExecutableNames(
- GetLocalGenerator()->GetConfigName());
- } else {
- this->TargetNames = this->GetGeneratorTarget()->GetLibraryNames(
- GetLocalGenerator()->GetConfigName());
- }
-
if (target->GetType() != cmStateEnums::OBJECT_LIBRARY) {
// on Windows the output dir is already needed at compile time
// ensure the directory exists (OutDir test)
- EnsureDirectoryExists(target->GetDirectory(this->GetConfigName()));
+ for (auto const& config : this->GetConfigNames()) {
+ EnsureDirectoryExists(target->GetDirectory(config));
+ }
}
- this->OSXBundleGenerator =
- cm::make_unique<cmOSXBundleGenerator>(target, this->GetConfigName());
+ this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(target);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() = default;
-void cmNinjaNormalTargetGenerator::Generate()
+void cmNinjaNormalTargetGenerator::Generate(const std::string& config)
{
- if (this->TargetLinkLanguage.empty()) {
+ std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
+ if (this->TargetLinkLanguage(config).empty()) {
cmSystemTools::Error("CMake can not determine linker language for "
"target: " +
this->GetGeneratorTarget()->GetName());
@@ -75,25 +67,26 @@ void cmNinjaNormalTargetGenerator::Generate()
}
// Write the rules for each language.
- this->WriteLanguagesRules();
+ this->WriteLanguagesRules(config);
// Write the build statements
- this->WriteObjectBuildStatements();
+ this->WriteObjectBuildStatements(config);
if (this->GetGeneratorTarget()->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- this->WriteObjectLibStatement();
+ this->WriteObjectLibStatement(config);
} else {
// If this target has cuda language link inputs, and we need to do
// device linking
- this->WriteDeviceLinkStatement();
- this->WriteLinkStatement();
+ this->WriteDeviceLinkStatement(config);
+ this->WriteLinkStatement(config);
}
// Find ADDITIONAL_CLEAN_FILES
- this->AdditionalCleanFiles();
+ this->AdditionalCleanFiles(config);
}
-void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
+void cmNinjaNormalTargetGenerator::WriteLanguagesRules(
+ const std::string& config)
{
#ifdef NINJA_GEN_VERBOSE_FILES
cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
@@ -106,8 +99,7 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
// Write rules for languages compiled in this target.
std::set<std::string> languages;
std::vector<cmSourceFile const*> sourceFiles;
- this->GetGeneratorTarget()->GetObjectSources(
- sourceFiles, this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ this->GetGeneratorTarget()->GetObjectSources(sourceFiles, config);
for (cmSourceFile const* sf : sourceFiles) {
std::string const lang = sf->GetLanguage();
if (!lang.empty()) {
@@ -139,18 +131,20 @@ const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
}
}
-std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule() const
+std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule(
+ const std::string& config) const
{
- return this->TargetLinkLanguage + "_" +
+ return this->TargetLinkLanguage(config) + "_" +
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) +
"_LINKER__" +
cmGlobalNinjaGenerator::EncodeRuleName(
this->GetGeneratorTarget()->GetName());
}
-std::string cmNinjaNormalTargetGenerator::LanguageLinkerDeviceRule() const
+std::string cmNinjaNormalTargetGenerator::LanguageLinkerDeviceRule(
+ const std::string& config) const
{
- return this->TargetLinkLanguage + "_" +
+ return this->TargetLinkLanguage(config) + "_" +
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) +
"_DEVICE_LINKER__" +
cmGlobalNinjaGenerator::EncodeRuleName(
@@ -165,9 +159,10 @@ struct cmNinjaRemoveNoOpCommands
}
};
-void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
+void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(
+ bool useResponseFile, const std::string& config)
{
- cmNinjaRule rule(this->LanguageLinkerDeviceRule());
+ cmNinjaRule rule(this->LanguageLinkerDeviceRule(config));
if (!this->GetGlobalGenerator()->HasRule(rule.Name)) {
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
@@ -241,30 +236,34 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds);
// Write the linker rule with response file if needed.
- rule.Comment = cmStrCat("Rule for linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), '.');
- rule.Description = cmStrCat("Linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), " $TARGET_FILE");
+ rule.Comment =
+ cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), '.');
+ rule.Description =
+ cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), " $TARGET_FILE");
rule.Restat = "$RESTAT";
this->GetGlobalGenerator()->AddRule(rule);
}
}
-void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
+void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
+ const std::string& config)
{
cmStateEnums::TargetType targetType = this->GetGeneratorTarget()->GetType();
- std::string linkRuleName = this->LanguageLinkerRule();
+ std::string linkRuleName = this->LanguageLinkerRule(config);
if (!this->GetGlobalGenerator()->HasRule(linkRuleName)) {
cmNinjaRule rule(std::move(linkRuleName));
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
vars.CMTargetType = cmState::GetTargetTypeName(targetType);
- vars.Language = this->TargetLinkLanguage.c_str();
+ std::string lang = this->TargetLinkLanguage(config);
+ vars.Language = config.c_str();
- if (this->TargetLinkLanguage == "Swift") {
+ if (this->TargetLinkLanguage(config) == "Swift") {
vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME";
vars.SwiftModule = "$SWIFT_MODULE";
vars.SwiftModuleName = "$SWIFT_MODULE_NAME";
@@ -278,7 +277,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
std::string responseFlag;
- std::string cmakeVarLang = cmStrCat("CMAKE_", this->TargetLinkLanguage);
+ std::string cmakeVarLang =
+ cmStrCat("CMAKE_", this->TargetLinkLanguage(config));
// build response file name
std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
@@ -286,7 +286,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
if (flag) {
responseFlag = flag;
- } else if (this->TargetLinkLanguage != "CUDA") {
+ } else if (this->TargetLinkLanguage(config) != "CUDA") {
responseFlag = "@";
}
@@ -304,7 +304,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
rule.RspContent = "$in_newline";
}
rule.RspContent += " $LINK_PATH $LINK_LIBRARIES";
- if (this->TargetLinkLanguage == "Swift") {
+ if (this->TargetLinkLanguage(config) == "Swift") {
vars.SwiftSources = responseFlag.c_str();
} else {
vars.Objects = responseFlag.c_str();
@@ -359,7 +359,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
// Rule for linking library/executable.
- std::vector<std::string> linkCmds = this->ComputeLinkCmd();
+ std::vector<std::string> linkCmds = this->ComputeLinkCmd(config);
for (std::string& linkCmd : linkCmds) {
linkCmd = cmStrCat(launcher, linkCmd);
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
@@ -374,15 +374,18 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds);
// Write the linker rule with response file if needed.
- rule.Comment = cmStrCat("Rule for linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), '.');
- rule.Description = cmStrCat("Linking ", this->TargetLinkLanguage, ' ',
- this->GetVisibleTypeName(), " $TARGET_FILE");
+ rule.Comment =
+ cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), '.');
+ rule.Description =
+ cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
+ this->GetVisibleTypeName(), " $TARGET_FILE");
rule.Restat = "$RESTAT";
this->GetGlobalGenerator()->AddRule(rule);
}
- if (this->TargetNames.Output != this->TargetNames.Real &&
+ auto const tgtNames = this->TargetNames(config);
+ if (tgtNames.Output != tgtNames.Real &&
!this->GetGeneratorTarget()->IsFrameworkOnApple()) {
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
@@ -441,7 +444,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeDeviceLinkCmd()
return linkCmds;
}
-std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
+std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd(
+ const std::string& config)
{
std::vector<std::string> linkCmds;
cmMakefile* mf = this->GetMakefile();
@@ -450,14 +454,14 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
// this occurs when things like IPO is enabled, and we need to use the
// CMAKE_<lang>_CREATE_STATIC_LIBRARY_IPO define instead.
std::string linkCmdVar = this->GetGeneratorTarget()->GetCreateRuleVariable(
- this->TargetLinkLanguage, this->GetConfigName());
+ this->TargetLinkLanguage(config), config);
const char* linkCmd = mf->GetDefinition(linkCmdVar);
if (linkCmd) {
std::string linkCmdStr = linkCmd;
- if (this->GetGeneratorTarget()->HasImplibGNUtoMS(this->ConfigName)) {
- std::string ruleVar = cmStrCat(
- "CMAKE_", this->GeneratorTarget->GetLinkerLanguage(this->ConfigName),
- "_GNUtoMS_RULE");
+ if (this->GetGeneratorTarget()->HasImplibGNUtoMS(config)) {
+ std::string ruleVar =
+ cmStrCat("CMAKE_", this->GeneratorTarget->GetLinkerLanguage(config),
+ "_GNUtoMS_RULE");
if (const char* rule = this->Makefile->GetDefinition(ruleVar)) {
linkCmdStr += rule;
}
@@ -469,9 +473,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL),
" -E __run_co_compile --lwyu=");
cmGeneratorTarget& gt = *this->GetGeneratorTarget();
- const std::string cfgName = this->GetConfigName();
std::string targetOutputReal = this->ConvertToNinjaPath(
- gt.GetFullPath(cfgName, cmStateEnums::RuntimeBinaryArtifact,
+ gt.GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact,
/*realname=*/true));
cmakeCommand += targetOutputReal;
linkCmds.push_back(std::move(cmakeCommand));
@@ -490,21 +493,21 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
}
// TODO: Use ARCHIVE_APPEND for archives over a certain size.
{
- std::string linkCmdVar =
- cmStrCat("CMAKE_", this->TargetLinkLanguage, "_ARCHIVE_CREATE");
+ std::string linkCmdVar = cmStrCat(
+ "CMAKE_", this->TargetLinkLanguage(config), "_ARCHIVE_CREATE");
linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- linkCmdVar, this->TargetLinkLanguage, this->GetConfigName());
+ linkCmdVar, this->TargetLinkLanguage(config), config);
std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
cmExpandList(linkCmd, linkCmds);
}
{
- std::string linkCmdVar =
- cmStrCat("CMAKE_", this->TargetLinkLanguage, "_ARCHIVE_FINISH");
+ std::string linkCmdVar = cmStrCat(
+ "CMAKE_", this->TargetLinkLanguage(config), "_ARCHIVE_FINISH");
linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- linkCmdVar, this->TargetLinkLanguage, this->GetConfigName());
+ linkCmdVar, this->TargetLinkLanguage(config), config);
std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
cmExpandList(linkCmd, linkCmds);
@@ -535,7 +538,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
return std::vector<std::string>();
}
-void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
+void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement(
+ const std::string& config)
{
cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
if (!globalGen->GetLanguageEnabled("CUDA")) {
@@ -545,7 +549,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
cmGeneratorTarget* genTarget = this->GetGeneratorTarget();
bool requiresDeviceLinking = requireDeviceLinking(
- *this->GeneratorTarget, *this->GetLocalGenerator(), this->ConfigName);
+ *this->GeneratorTarget, *this->GetLocalGenerator(), config);
if (!requiresDeviceLinking) {
return;
}
@@ -558,12 +562,11 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
std::string const& objExt =
this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION");
- std::string const cfgName = this->GetConfigName();
std::string const targetOutputReal = ConvertToNinjaPath(
genTarget->ObjectDirectory + "cmake_device_link" + objExt);
std::string const targetOutputImplib = ConvertToNinjaPath(
- genTarget->GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
+ genTarget->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
this->DeviceLinkObject = targetOutputReal;
@@ -575,7 +578,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
<< " target " << this->GetTargetName() << "\n\n";
// Compute the comment.
- cmNinjaBuild build(this->LanguageLinkerDeviceRule());
+ cmNinjaBuild build(this->LanguageLinkerDeviceRule(config));
build.Comment =
cmStrCat("Link the ", this->GetVisibleTypeName(), ' ', targetOutputReal);
@@ -585,13 +588,14 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
build.Outputs.push_back(targetOutputReal);
// Compute specific libraries to link with.
build.ExplicitDeps = this->GetObjects();
- build.ImplicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage);
+ build.ImplicitDeps =
+ this->ComputeLinkDeps(this->TargetLinkLanguage(config), config);
std::string frameworkPath;
std::string linkPath;
- std::string createRule = genTarget->GetCreateRuleVariable(
- this->TargetLinkLanguage, this->GetConfigName());
+ std::string createRule =
+ genTarget->GetCreateRuleVariable(this->TargetLinkLanguage(config), config);
const bool useWatcomQuote =
this->GetMakefile()->IsOn(createRule + "_USE_WATCOM_QUOTE");
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
@@ -607,15 +611,15 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
localGen.GetTargetFlags(
- linkLineComputer.get(), this->GetConfigName(), vars["LINK_LIBRARIES"],
- vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath, genTarget);
+ linkLineComputer.get(), config, vars["LINK_LIBRARIES"], vars["FLAGS"],
+ vars["LINK_FLAGS"], frameworkPath, linkPath, genTarget);
this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars);
vars["LINK_FLAGS"] =
cmGlobalNinjaGenerator::EncodeLiteral(vars["LINK_FLAGS"]);
- vars["MANIFESTS"] = this->GetManifests();
+ vars["MANIFESTS"] = this->GetManifests(config);
vars["LINK_PATH"] = frameworkPath + linkPath;
@@ -624,24 +628,25 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// code between the Makefile executable and library generators.
if (targetType == cmStateEnums::EXECUTABLE) {
std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, config);
vars["FLAGS"] = t;
} else {
std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, config);
vars["ARCH_FLAGS"] = t;
t.clear();
localGen.AddLanguageFlagsForLinking(t, genTarget, cudaLinkLanguage,
- cfgName);
+ config);
vars["LANGUAGE_COMPILE_FLAGS"] = t;
}
- if (genTarget->HasSOName(cfgName)) {
+ auto const tgtNames = this->TargetNames(config);
+ if (genTarget->HasSOName(config)) {
vars["SONAME_FLAG"] =
- this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage);
- vars["SONAME"] = this->TargetNames.SharedObject;
+ this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage(config));
+ vars["SONAME"] = tgtNames.SharedObject;
if (targetType == cmStateEnums::SHARED_LIBRARY) {
std::string install_dir =
- this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName);
+ this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(config);
if (!install_dir.empty()) {
vars["INSTALLNAME_DIR"] = localGen.ConvertToOutputFormat(
install_dir, cmOutputConverter::SHELL);
@@ -649,7 +654,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
}
}
- if (!this->TargetNames.ImportLibrary.empty()) {
+ if (!tgtNames.ImportLibrary.empty()) {
const std::string impLibPath = localGen.ConvertToOutputFormat(
targetOutputImplib, cmOutputConverter::SHELL);
vars["TARGET_IMPLIB"] = impLibPath;
@@ -661,7 +666,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL);
EnsureDirectoryExists(objPath);
- this->SetMsvcTargetPdbVariable(vars);
+ this->SetMsvcTargetPdbVariable(vars, config);
if (globalGen->IsGCCOnWindows()) {
// ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
@@ -675,55 +680,56 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// do not check if the user has explicitly forced a response file.
int const commandLineLengthLimit =
static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
- globalGen->GetRuleCmdLength(this->LanguageLinkerDeviceRule());
+ globalGen->GetRuleCmdLength(this->LanguageLinkerDeviceRule(config));
build.RspFile = this->ConvertToNinjaPath(std::string("CMakeFiles/") +
genTarget->GetName() + ".rsp");
// Gather order-only dependencies.
this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
- build.OrderOnlyDeps);
+ build.OrderOnlyDeps, config);
// Write the build statement for this target.
bool usedResponseFile = false;
globalGen->WriteBuild(this->GetBuildFileStream(), build,
commandLineLengthLimit, &usedResponseFile);
- this->WriteDeviceLinkRule(usedResponseFile);
+ this->WriteDeviceLinkRule(usedResponseFile, config);
}
-void cmNinjaNormalTargetGenerator::WriteLinkStatement()
+void cmNinjaNormalTargetGenerator::WriteLinkStatement(
+ const std::string& config)
{
cmMakefile* mf = this->GetMakefile();
cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
cmGeneratorTarget* gt = this->GetGeneratorTarget();
- const std::string cfgName = this->GetConfigName();
- std::string targetOutput = ConvertToNinjaPath(gt->GetFullPath(cfgName));
+ std::string targetOutput = ConvertToNinjaPath(gt->GetFullPath(config));
std::string targetOutputReal = ConvertToNinjaPath(
- gt->GetFullPath(cfgName, cmStateEnums::RuntimeBinaryArtifact,
+ gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact,
/*realname=*/true));
std::string targetOutputImplib = ConvertToNinjaPath(
- gt->GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
+ gt->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
+ auto const tgtNames = this->TargetNames(config);
if (gt->IsAppBundleOnApple()) {
// Create the app bundle
- std::string outpath = gt->GetDirectory(cfgName);
- this->OSXBundleGenerator->CreateAppBundle(this->TargetNames.Output,
- outpath);
+ std::string outpath = gt->GetDirectory(config);
+ this->OSXBundleGenerator->CreateAppBundle(tgtNames.Output, outpath,
+ config);
// Calculate the output path
- targetOutput = cmStrCat(outpath, '/', this->TargetNames.Output);
+ targetOutput = cmStrCat(outpath, '/', tgtNames.Output);
targetOutput = this->ConvertToNinjaPath(targetOutput);
- targetOutputReal = cmStrCat(outpath, '/', this->TargetNames.Real);
+ targetOutputReal = cmStrCat(outpath, '/', tgtNames.Real);
targetOutputReal = this->ConvertToNinjaPath(targetOutputReal);
} else if (gt->IsFrameworkOnApple()) {
// Create the library framework.
- this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output,
- gt->GetDirectory(cfgName));
+ this->OSXBundleGenerator->CreateFramework(
+ tgtNames.Output, gt->GetDirectory(config), config);
} else if (gt->IsCFBundleOnApple()) {
// Create the core foundation bundle.
- this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output,
- gt->GetDirectory(cfgName));
+ this->OSXBundleGenerator->CreateCFBundle(tgtNames.Output,
+ gt->GetDirectory(config), config);
}
// Write comments.
@@ -733,7 +739,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
<< "# Link build statements for " << cmState::GetTargetTypeName(targetType)
<< " target " << this->GetTargetName() << "\n\n";
- cmNinjaBuild linkBuild(this->LanguageLinkerRule());
+ cmNinjaBuild linkBuild(this->LanguageLinkerRule(config));
cmNinjaVars& vars = linkBuild.Variables;
// Compute the comment.
@@ -743,10 +749,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// Compute outputs.
linkBuild.Outputs.push_back(targetOutputReal);
- if (this->TargetLinkLanguage == "Swift") {
- vars["SWIFT_LIBRARY_NAME"] = [this]() -> std::string {
+ if (this->TargetLinkLanguage(config) == "Swift") {
+ vars["SWIFT_LIBRARY_NAME"] = [this, config]() -> std::string {
cmGeneratorTarget::Names targetNames =
- this->GetGeneratorTarget()->GetLibraryNames(this->GetConfigName());
+ this->GetGeneratorTarget()->GetLibraryNames(config);
return targetNames.Base;
}();
@@ -782,12 +788,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
"/output-file-map.json"),
cmOutputConverter::SHELL);
- vars["SWIFT_SOURCES"] = [this]() -> std::string {
+ vars["SWIFT_SOURCES"] = [this, config]() -> std::string {
std::vector<cmSourceFile const*> sources;
std::stringstream oss;
- this->GetGeneratorTarget()->GetObjectSources(sources,
- this->GetConfigName());
+ this->GetGeneratorTarget()->GetObjectSources(sources, config);
cmLocalGenerator const* LocalGen = this->GetLocalGenerator();
for (const auto& source : sources) {
oss << " "
@@ -801,15 +806,15 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// Since we do not perform object builds, compute the
// defines/flags/includes here so that they can be passed along
// appropriately.
- vars["DEFINES"] = this->GetDefines("Swift");
- vars["FLAGS"] = this->GetFlags("Swift");
- vars["INCLUDES"] = this->GetIncludes("Swift");
+ vars["DEFINES"] = this->GetDefines("Swift", config);
+ vars["FLAGS"] = this->GetFlags("Swift", config);
+ vars["INCLUDES"] = this->GetIncludes("Swift", config);
}
// Compute specific libraries to link with.
- if (this->TargetLinkLanguage == "Swift") {
+ if (this->TargetLinkLanguage(config) == "Swift") {
std::vector<cmSourceFile const*> sources;
- gt->GetObjectSources(sources, this->GetConfigName());
+ gt->GetObjectSources(sources, config);
for (const auto& source : sources) {
linkBuild.Outputs.push_back(
this->ConvertToNinjaPath(this->GetObjectFilePath(source)));
@@ -821,7 +826,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
} else {
linkBuild.ExplicitDeps = this->GetObjects();
}
- linkBuild.ImplicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage);
+ linkBuild.ImplicitDeps =
+ this->ComputeLinkDeps(this->TargetLinkLanguage(config), config);
if (!this->DeviceLinkObject.empty()) {
linkBuild.ExplicitDeps.push_back(this->DeviceLinkObject);
@@ -831,7 +837,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
std::string linkPath;
std::string createRule =
- gt->GetCreateRuleVariable(this->TargetLinkLanguage, this->GetConfigName());
+ gt->GetCreateRuleVariable(this->TargetLinkLanguage(config), config);
bool useWatcomQuote = mf->IsOn(createRule + "_USE_WATCOM_QUOTE");
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
@@ -844,26 +850,28 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetLocalGenerator()->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
- localGen.GetTargetFlags(linkLineComputer.get(), this->GetConfigName(),
+ localGen.GetTargetFlags(linkLineComputer.get(), config,
vars["LINK_LIBRARIES"], vars["FLAGS"],
vars["LINK_FLAGS"], frameworkPath, linkPath, gt);
// Add OS X version flags, if any.
if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
- this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage,
- "COMPATIBILITY", true);
- this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage,
- "CURRENT", false);
+ this->AppendOSXVerFlag(vars["LINK_FLAGS"],
+ this->TargetLinkLanguage(config), "COMPATIBILITY",
+ true);
+ this->AppendOSXVerFlag(vars["LINK_FLAGS"],
+ this->TargetLinkLanguage(config), "CURRENT", false);
}
this->addPoolNinjaVariable("JOB_POOL_LINK", gt, vars);
- this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"]);
+ this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"],
+ config);
vars["LINK_FLAGS"] =
cmGlobalNinjaGenerator::EncodeLiteral(vars["LINK_FLAGS"]);
- vars["MANIFESTS"] = this->GetManifests();
+ vars["MANIFESTS"] = this->GetManifests(config);
vars["LINK_PATH"] = frameworkPath + linkPath;
std::string lwyuFlags;
@@ -876,23 +884,26 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// code between the Makefile executable and library generators.
if (targetType == cmStateEnums::EXECUTABLE) {
std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, gt, TargetLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, gt, this->TargetLinkLanguage(config),
+ config);
t += lwyuFlags;
vars["FLAGS"] = t;
} else {
std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, gt, TargetLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, gt, this->TargetLinkLanguage(config),
+ config);
vars["ARCH_FLAGS"] = t;
t.clear();
t += lwyuFlags;
- localGen.AddLanguageFlagsForLinking(t, gt, TargetLinkLanguage, cfgName);
+ localGen.AddLanguageFlagsForLinking(
+ t, gt, this->TargetLinkLanguage(config), config);
vars["LANGUAGE_COMPILE_FLAGS"] = t;
}
- if (gt->HasSOName(cfgName)) {
- vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage);
- vars["SONAME"] = this->TargetNames.SharedObject;
+ if (gt->HasSOName(config)) {
+ vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage(config));
+ vars["SONAME"] = tgtNames.SharedObject;
if (targetType == cmStateEnums::SHARED_LIBRARY) {
- std::string install_dir = gt->GetInstallNameDirForBuildTree(cfgName);
+ std::string install_dir = gt->GetInstallNameDirForBuildTree(config);
if (!install_dir.empty()) {
vars["INSTALLNAME_DIR"] = localGen.ConvertToOutputFormat(
install_dir, cmOutputConverter::SHELL);
@@ -902,17 +913,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
cmNinjaDeps byproducts;
- if (!this->TargetNames.ImportLibrary.empty()) {
+ if (!tgtNames.ImportLibrary.empty()) {
const std::string impLibPath = localGen.ConvertToOutputFormat(
targetOutputImplib, cmOutputConverter::SHELL);
vars["TARGET_IMPLIB"] = impLibPath;
EnsureParentDirectoryExists(impLibPath);
- if (gt->HasImportLibrary(cfgName)) {
+ if (gt->HasImportLibrary(config)) {
byproducts.push_back(targetOutputImplib);
}
}
- if (!this->SetMsvcTargetPdbVariable(vars)) {
+ if (!this->SetMsvcTargetPdbVariable(vars, config)) {
// It is common to place debug symbols at a specific place,
// so we need a plain target name in the rule available.
std::string prefix;
@@ -953,7 +964,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
for (unsigned i = 0; i != 3; ++i) {
for (cmCustomCommand const& cc : *cmdLists[i]) {
- cmCustomCommandGenerator ccg(cc, cfgName, this->GetLocalGenerator());
+ cmCustomCommandGenerator ccg(cc, config, this->GetLocalGenerator());
localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
std::transform(ccByproducts.begin(), ccByproducts.end(),
@@ -963,7 +974,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// maybe create .def file from list of objects
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
- gt->GetModuleDefinitionInfo(this->GetConfigName());
+ gt->GetModuleDefinitionInfo(config);
if (mdi && mdi->DefFileGenerated) {
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
@@ -1024,7 +1035,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
symlinkVars["POST_BUILD"] = postBuildCmdLine;
}
- std::string cmakeVarLang = cmStrCat("CMAKE_", this->TargetLinkLanguage);
+ std::string cmakeVarLang =
+ cmStrCat("CMAKE_", this->TargetLinkLanguage(config));
// build response file name
std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
@@ -1032,8 +1044,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
const char* flag = GetMakefile()->GetDefinition(cmakeLinkVar);
bool const lang_supports_response =
- !(this->TargetLinkLanguage == "RC" ||
- (this->TargetLinkLanguage == "CUDA" && !flag));
+ !(this->TargetLinkLanguage(config) == "RC" ||
+ (this->TargetLinkLanguage(config) == "CUDA" && !flag));
int commandLineLengthLimit = -1;
if (!lang_supports_response || !this->ForceResponseFile()) {
commandLineLengthLimit =
@@ -1045,18 +1057,19 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
gt->GetName() + ".rsp");
// Gather order-only dependencies.
- this->GetLocalGenerator()->AppendTargetDepends(gt, linkBuild.OrderOnlyDeps);
+ this->GetLocalGenerator()->AppendTargetDepends(gt, linkBuild.OrderOnlyDeps,
+ config);
// Add order-only dependencies on versioning symlinks of shared libs we link.
if (!this->GeneratorTarget->IsDLLPlatform()) {
if (cmComputeLinkInformation* cli =
- this->GeneratorTarget->GetLinkInformation(this->GetConfigName())) {
+ this->GeneratorTarget->GetLinkInformation(config)) {
for (auto const& item : cli->GetItems()) {
if (item.Target &&
item.Target->GetType() == cmStateEnums::SHARED_LIBRARY &&
!item.Target->IsFrameworkOnApple()) {
- std::string const& lib = this->ConvertToNinjaPath(
- item.Target->GetFullPath(this->GetConfigName()));
+ std::string const& lib =
+ this->ConvertToNinjaPath(item.Target->GetFullPath(config));
if (std::find(linkBuild.ImplicitDeps.begin(),
linkBuild.ImplicitDeps.end(),
lib) == linkBuild.ImplicitDeps.end()) {
@@ -1079,7 +1092,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
bool usedResponseFile = false;
globalGen->WriteBuild(this->GetBuildFileStream(), linkBuild,
commandLineLengthLimit, &usedResponseFile);
- this->WriteLinkRule(usedResponseFile);
+ this->WriteLinkRule(usedResponseFile, config);
if (symlinkNeeded) {
if (targetType == cmStateEnums::EXECUTABLE) {
@@ -1094,7 +1107,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
build.Comment = "Create library symlink " + targetOutput;
std::string const soName = this->ConvertToNinjaPath(
- this->GetTargetFilePath(this->TargetNames.SharedObject));
+ this->GetTargetFilePath(tgtNames.SharedObject, config));
// If one link has to be created.
if (targetOutputReal == soName || targetOutput == soName) {
symlinkVars["SONAME"] =
@@ -1113,23 +1126,39 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
// Add aliases for the file name and the target name.
- globalGen->AddTargetAlias(this->TargetNames.Output, gt);
- globalGen->AddTargetAlias(this->GetTargetName(), gt);
+ globalGen->AddTargetAlias(tgtNames.Output, gt, config);
+ globalGen->AddTargetAlias(this->GetTargetName(), gt, config);
}
-void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
+void cmNinjaNormalTargetGenerator::WriteObjectLibStatement(
+ const std::string& config)
{
// Write a phony output that depends on all object files.
{
cmNinjaBuild build("phony");
build.Comment = "Object library " + this->GetTargetName();
this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
- build.Outputs);
+ build.Outputs, config);
build.ExplicitDeps = this->GetObjects();
this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
}
// Add aliases for the target name.
- this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
- this->GetGeneratorTarget());
+ this->GetGlobalGenerator()->AddTargetAlias(
+ this->GetTargetName(), this->GetGeneratorTarget(), config);
+}
+
+cmGeneratorTarget::Names cmNinjaNormalTargetGenerator::TargetNames(
+ const std::string& config) const
+{
+ if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
+ return this->GeneratorTarget->GetExecutableNames(config);
+ }
+ return this->GeneratorTarget->GetLibraryNames(config);
+}
+
+std::string cmNinjaNormalTargetGenerator::TargetLinkLanguage(
+ const std::string& config) const
+{
+ return this->GeneratorTarget->GetLinkerLanguage(config);
}