summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalNinjaGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmLocalNinjaGenerator.cxx')
-rw-r--r--Source/cmLocalNinjaGenerator.cxx143
1 files changed, 104 insertions, 39 deletions
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index 134bbe1..6967097 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -29,6 +29,7 @@
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
+#include "cmTarget.h"
#include "cmake.h"
cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
@@ -61,7 +62,12 @@ void cmLocalNinjaGenerator::Generate()
this->HomeRelativeOutputPath.clear();
}
- this->WriteProcessedMakefile(this->GetBuildFileStream());
+ if (this->GetGlobalGenerator()->IsMultiConfig()) {
+ for (auto const& config : this->GetConfigNames()) {
+ this->WriteProcessedMakefile(this->GetConfigFileStream(config));
+ }
+ }
+ this->WriteProcessedMakefile(this->GetCommonFileStream());
#ifdef NINJA_GEN_VERBOSE_FILES
this->WriteProcessedMakefile(this->GetRulesFileStream());
#endif
@@ -82,18 +88,26 @@ void cmLocalNinjaGenerator::Generate()
}
}
- for (cmGeneratorTarget* target : this->GetGeneratorTargets()) {
+ for (const auto& target : this->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- auto tg = cmNinjaTargetGenerator::New(target);
+ auto tg = cmNinjaTargetGenerator::New(target.get());
if (tg) {
- tg->Generate();
+ if (target->Target->IsPerConfig()) {
+ for (auto const& config : this->GetConfigNames()) {
+ tg->Generate(config);
+ }
+ } else {
+ tg->Generate("");
+ }
}
}
- this->WriteCustomCommandBuildStatements();
- this->AdditionalCleanFiles();
+ for (auto const& config : this->GetConfigNames()) {
+ this->WriteCustomCommandBuildStatements(config);
+ this->AdditionalCleanFiles(config);
+ }
}
// TODO: Picked up from cmLocalUnixMakefileGenerator3. Refactor it.
@@ -140,9 +154,15 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference(
// Private methods.
-cmGeneratedFileStream& cmLocalNinjaGenerator::GetBuildFileStream() const
+cmGeneratedFileStream& cmLocalNinjaGenerator::GetConfigFileStream(
+ const std::string& config) const
{
- return *this->GetGlobalNinjaGenerator()->GetBuildFileStream();
+ return *this->GetGlobalNinjaGenerator()->GetConfigFileStream(config);
+}
+
+cmGeneratedFileStream& cmLocalNinjaGenerator::GetCommonFileStream() const
+{
+ return *this->GetGlobalNinjaGenerator()->GetCommonFileStream();
}
cmGeneratedFileStream& cmLocalNinjaGenerator::GetRulesFileStream() const
@@ -162,10 +182,22 @@ cmake* cmLocalNinjaGenerator::GetCMakeInstance()
void cmLocalNinjaGenerator::WriteBuildFileTop()
{
- // For the build file.
- this->WriteProjectHeader(this->GetBuildFileStream());
- this->WriteNinjaRequiredVersion(this->GetBuildFileStream());
- this->WriteNinjaFilesInclusion(this->GetBuildFileStream());
+ this->WriteProjectHeader(this->GetCommonFileStream());
+
+ if (this->GetGlobalGenerator()->IsMultiConfig()) {
+ for (auto const& config : this->GetConfigNames()) {
+ auto& stream = this->GetConfigFileStream(config);
+ this->WriteProjectHeader(stream);
+ this->WriteNinjaRequiredVersion(stream);
+ this->WriteNinjaConfigurationVariable(stream, config);
+ this->WriteNinjaFilesInclusionConfig(stream);
+ }
+ } else {
+ this->WriteNinjaRequiredVersion(this->GetCommonFileStream());
+ this->WriteNinjaConfigurationVariable(this->GetCommonFileStream(),
+ this->GetConfigNames().front());
+ }
+ this->WriteNinjaFilesInclusionCommon(this->GetCommonFileStream());
// For the rule file.
this->WriteProjectHeader(this->GetRulesFileStream());
@@ -175,7 +207,8 @@ void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);
os << "# Project: " << this->GetProjectName() << std::endl
- << "# Configuration: " << this->ConfigName << std::endl;
+ << "# Configurations: " << cmJoin(this->GetConfigNames(), ", ")
+ << std::endl;
cmGlobalNinjaGenerator::WriteDivider(os);
}
@@ -206,6 +239,14 @@ void cmLocalNinjaGenerator::WriteNinjaRequiredVersion(std::ostream& os)
<< std::endl;
}
+void cmLocalNinjaGenerator::WriteNinjaConfigurationVariable(
+ std::ostream& os, const std::string& config)
+{
+ cmGlobalNinjaGenerator::WriteVariable(
+ os, "CONFIGURATION", config,
+ "Set configuration variable for custom commands.");
+}
+
void cmLocalNinjaGenerator::WritePools(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);
@@ -235,7 +276,21 @@ void cmLocalNinjaGenerator::WritePools(std::ostream& os)
}
}
-void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os)
+void cmLocalNinjaGenerator::WriteNinjaFilesInclusionConfig(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os << "# Include auxiliary files.\n"
+ << "\n";
+ cmGlobalNinjaGenerator* ng = this->GetGlobalNinjaGenerator();
+ std::string const ninjaCommonFile =
+ ng->NinjaOutputPath(cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE);
+ std::string const commonFilePath = ng->EncodePath(ninjaCommonFile);
+ cmGlobalNinjaGenerator::WriteInclude(os, commonFilePath,
+ "Include common file.");
+ os << "\n";
+}
+
+void cmLocalNinjaGenerator::WriteNinjaFilesInclusionCommon(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);
os << "# Include auxiliary files.\n"
@@ -263,25 +318,30 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
}
void cmLocalNinjaGenerator::AppendTargetOutputs(cmGeneratorTarget* target,
- cmNinjaDeps& outputs)
+ cmNinjaDeps& outputs,
+ const std::string& config)
{
- this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs);
+ this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs,
+ config);
}
void cmLocalNinjaGenerator::AppendTargetDepends(cmGeneratorTarget* target,
cmNinjaDeps& outputs,
+ const std::string& config,
+ const std::string& fileConfig,
cmNinjaTargetDepends depends)
{
- this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs,
- depends);
+ this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs, config,
+ fileConfig, depends);
}
void cmLocalNinjaGenerator::AppendCustomCommandDeps(
- cmCustomCommandGenerator const& ccg, cmNinjaDeps& ninjaDeps)
+ cmCustomCommandGenerator const& ccg, cmNinjaDeps& ninjaDeps,
+ const std::string& config)
{
for (std::string const& i : ccg.GetDepends()) {
std::string dep;
- if (this->GetRealDependency(i, this->GetConfigName(), dep)) {
+ if (this->GetRealDependency(i, config, dep)) {
ninjaDeps.push_back(
this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(dep));
}
@@ -416,6 +476,8 @@ std::string cmLocalNinjaGenerator::BuildCommandLine(
void cmLocalNinjaGenerator::AppendCustomCommandLines(
cmCustomCommandGenerator const& ccg, std::vector<std::string>& cmdLines)
{
+ auto* gg = this->GetGlobalNinjaGenerator();
+
if (ccg.GetNumberOfCommands() > 0) {
std::string wd = ccg.GetWorkingDirectory();
if (wd.empty()) {
@@ -437,8 +499,10 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(
for (unsigned i = 0; i != ccg.GetNumberOfCommands(); ++i) {
cmdLines.push_back(launcher +
- this->ConvertToOutputFormat(ccg.GetCommand(i),
- cmOutputConverter::SHELL));
+ this->ConvertToOutputFormat(
+ ccg.GetCommand(i),
+ gg->IsMultiConfig() ? cmOutputConverter::NINJAMULTI
+ : cmOutputConverter::SHELL));
std::string& cmd = cmdLines.back();
ccg.AppendArguments(i, cmd);
@@ -446,14 +510,15 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(
}
void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
- cmCustomCommand const* cc, const cmNinjaDeps& orderOnlyDeps)
+ cmCustomCommand const* cc, const cmNinjaDeps& orderOnlyDeps,
+ const std::string& config)
{
cmGlobalNinjaGenerator* gg = this->GetGlobalNinjaGenerator();
- if (gg->SeenCustomCommand(cc)) {
+ if (gg->SeenCustomCommand(cc, config)) {
return;
}
- cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this);
+ cmCustomCommandGenerator ccg(*cc, config, this);
const std::vector<std::string>& outputs = ccg.GetOutputs();
const std::vector<std::string>& byproducts = ccg.GetByproducts();
@@ -484,7 +549,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
}
cmNinjaDeps ninjaDeps;
- this->AppendCustomCommandDeps(ccg, ninjaDeps);
+ this->AppendCustomCommandDeps(ccg, ninjaDeps, config);
std::vector<std::string> cmdLines;
this->AppendCustomCommandLines(ccg, cmdLines);
@@ -495,7 +560,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
build.Outputs = std::move(ninjaOutputs);
build.ExplicitDeps = std::move(ninjaDeps);
build.OrderOnlyDeps = orderOnlyDeps;
- gg->WriteBuild(this->GetBuildFileStream(), build);
+ gg->WriteBuild(this->GetConfigFileStream(config), build);
} else {
std::string customStep = cmSystemTools::GetFilenameName(ninjaOutputs[0]);
// Hash full path to make unique.
@@ -507,8 +572,8 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
this->BuildCommandLine(cmdLines, customStep),
this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0],
cc->GetDepfile(), cc->GetJobPool(), cc->GetUsesTerminal(),
- /*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, ninjaDeps,
- orderOnlyDeps);
+ /*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, config,
+ ninjaDeps, orderOnlyDeps);
}
}
@@ -524,7 +589,8 @@ void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
ins.first->second.insert(target);
}
-void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
+void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements(
+ const std::string& config)
{
for (cmCustomCommand const* customCommand : this->CustomCommands) {
auto i = this->CustomCommandTargets.find(customCommand);
@@ -542,15 +608,16 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
auto j = i->second.begin();
assert(j != i->second.end());
std::vector<std::string> ccTargetDeps;
- this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j,
- ccTargetDeps);
+ this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(
+ *j, ccTargetDeps, config);
std::sort(ccTargetDeps.begin(), ccTargetDeps.end());
++j;
for (; j != i->second.end(); ++j) {
std::vector<std::string> jDeps;
std::vector<std::string> depsIntersection;
- this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, jDeps);
+ this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, jDeps,
+ config);
std::sort(jDeps.begin(), jDeps.end());
std::set_intersection(ccTargetDeps.begin(), ccTargetDeps.end(),
jDeps.begin(), jDeps.end(),
@@ -558,7 +625,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
ccTargetDeps = depsIntersection;
}
- this->WriteCustomCommandBuildStatement(i->first, ccTargetDeps);
+ this->WriteCustomCommandBuildStatement(i->first, ccTargetDeps, config);
}
}
@@ -599,15 +666,13 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
return launcher;
}
-void cmLocalNinjaGenerator::AdditionalCleanFiles()
+void cmLocalNinjaGenerator::AdditionalCleanFiles(const std::string& config)
{
if (const char* prop_value =
this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
std::vector<std::string> cleanFiles;
{
- cmExpandList(cmGeneratorExpression::Evaluate(
- prop_value, this,
- this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")),
+ cmExpandList(cmGeneratorExpression::Evaluate(prop_value, this, config),
cleanFiles);
}
std::string const& binaryDir = this->GetCurrentBinaryDirectory();
@@ -615,7 +680,7 @@ void cmLocalNinjaGenerator::AdditionalCleanFiles()
for (std::string const& cleanFile : cleanFiles) {
// Support relative paths
gg->AddAdditionalCleanFile(
- cmSystemTools::CollapseFullPath(cleanFile, binaryDir));
+ cmSystemTools::CollapseFullPath(cleanFile, binaryDir), config);
}
}
}