diff options
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 95 |
1 files changed, 71 insertions, 24 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 143ad92..51175c7 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -30,8 +30,9 @@ const char* cmGlobalNinjaGenerator::INDENT = " "; void cmGlobalNinjaGenerator::Indent(std::ostream& os, int count) { - for (int i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) { os << cmGlobalNinjaGenerator::INDENT; + } } void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os) @@ -43,8 +44,9 @@ void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os) void cmGlobalNinjaGenerator::WriteComment(std::ostream& os, const std::string& comment) { - if (comment.empty()) + if (comment.empty()) { return; + } std::string::size_type lpos = 0; std::string::size_type rpos; @@ -165,16 +167,18 @@ void cmGlobalNinjaGenerator::WriteBuild( if (!implicitDeps.empty()) { arguments += " |"; for (cmNinjaDeps::const_iterator i = implicitDeps.begin(); - i != implicitDeps.end(); ++i) + i != implicitDeps.end(); ++i) { arguments += " " + EncodeIdent(EncodePath(*i), os); + } } // Write order-only dependencies. if (!orderOnlyDeps.empty()) { arguments += " ||"; for (cmNinjaDeps::const_iterator i = orderOnlyDeps.begin(); - i != orderOnlyDeps.end(); ++i) + i != orderOnlyDeps.end(); ++i) { arguments += " " + EncodeIdent(EncodePath(*i), os); + } } arguments += "\n"; @@ -198,9 +202,10 @@ void cmGlobalNinjaGenerator::WriteBuild( // Write the variables bound to this build statement. std::ostringstream variable_assignments; for (cmNinjaVars::const_iterator i = variables.begin(); i != variables.end(); - ++i) + ++i) { cmGlobalNinjaGenerator::WriteVariable(variable_assignments, i->first, i->second, "", 1); + } // check if a response file rule should be used std::string buildstr = build; @@ -430,16 +435,17 @@ void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os, cmGlobalNinjaGenerator::WriteComment(os, comment); os << "default"; for (cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end(); - ++i) + ++i) { os << " " << *i; + } os << "\n"; } cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm) : cmGlobalCommonGenerator(cm) - , BuildFileStream(0) - , RulesFileStream(0) - , CompileCommandsStream(0) + , BuildFileStream(CM_NULLPTR) + , RulesFileStream(CM_NULLPTR) + , CompileCommandsStream(CM_NULLPTR) , Rules() , AllDependencies() , UsingGCCOnWindows(false) @@ -487,6 +493,8 @@ void cmGlobalNinjaGenerator::Generate() this->OpenBuildFileStream(); this->OpenRulesFileStream(); + this->TargetDependsClosures.clear(); + this->InitOutputPathPrefix(); this->TargetAll = this->NinjaOutputPath("all"); this->CMakeCacheFile = this->NinjaOutputPath("CMakeCache.txt"); @@ -507,8 +515,8 @@ void cmGlobalNinjaGenerator::Generate() this->WriteBuiltinTargets(*this->BuildFileStream); if (cmSystemTools::GetErrorOccuredFlag()) { - this->RulesFileStream->setstate(std::ios_base::failbit); - this->BuildFileStream->setstate(std::ios_base::failbit); + this->RulesFileStream->setstate(std::ios::failbit); + this->BuildFileStream->setstate(std::ios::failbit); } this->CloseCompileCommandsStream(); @@ -525,8 +533,8 @@ void cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf) command.push_back(this->NinjaCommand); command.push_back("--version"); std::string version; - cmSystemTools::RunSingleCommand(command, &version, 0, 0, 0, - cmSystemTools::OUTPUT_NONE); + cmSystemTools::RunSingleCommand(command, &version, CM_NULLPTR, CM_NULLPTR, + CM_NULLPTR, cmSystemTools::OUTPUT_NONE); this->NinjaVersion = cmSystemTools::TrimWhitespace(version); } } @@ -670,7 +678,7 @@ void cmGlobalNinjaGenerator::CloseBuildFileStream() { if (this->BuildFileStream) { delete this->BuildFileStream; - this->BuildFileStream = 0; + this->BuildFileStream = CM_NULLPTR; } else { cmSystemTools::Error("Build file stream was not open."); } @@ -711,7 +719,7 @@ void cmGlobalNinjaGenerator::CloseRulesFileStream() { if (this->RulesFileStream) { delete this->RulesFileStream; - this->RulesFileStream = 0; + this->RulesFileStream = CM_NULLPTR; } else { cmSystemTools::Error("Rules file stream was not open."); } @@ -799,7 +807,7 @@ void cmGlobalNinjaGenerator::CloseCompileCommandsStream() if (this->CompileCommandsStream) { *this->CompileCommandsStream << "\n]"; delete this->CompileCommandsStream; - this->CompileCommandsStream = 0; + this->CompileCommandsStream = CM_NULLPTR; } } @@ -899,6 +907,42 @@ void cmGlobalNinjaGenerator::AppendTargetDepends( } } +void cmGlobalNinjaGenerator::AppendTargetDependsClosure( + cmGeneratorTarget const* target, cmNinjaDeps& outputs) +{ + TargetDependsClosureMap::iterator i = + this->TargetDependsClosures.find(target); + if (i == this->TargetDependsClosures.end()) { + TargetDependsClosureMap::value_type e( + target, std::set<cmGeneratorTarget const*>()); + i = this->TargetDependsClosures.insert(e).first; + this->ComputeTargetDependsClosure(target, i->second); + } + std::set<cmGeneratorTarget const*> const& targets = i->second; + cmNinjaDeps outs; + for (std::set<cmGeneratorTarget const*>::const_iterator ti = targets.begin(); + ti != targets.end(); ++ti) { + this->AppendTargetOutputs(*ti, outs); + } + std::sort(outs.begin(), outs.end()); + outputs.insert(outputs.end(), outs.begin(), outs.end()); +} + +void cmGlobalNinjaGenerator::ComputeTargetDependsClosure( + cmGeneratorTarget const* target, std::set<cmGeneratorTarget const*>& depends) +{ + cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target); + for (cmTargetDependSet::const_iterator i = targetDeps.begin(); + i != targetDeps.end(); ++i) { + if ((*i)->GetType() == cmState::INTERFACE_LIBRARY) { + continue; + } + if (depends.insert(*i).second) { + this->ComputeTargetDependsClosure(*i, depends); + } + } +} + void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, cmGeneratorTarget* target) { @@ -907,15 +951,17 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, this->AppendTargetOutputs(target, outputs); // Mark the target's outputs as ambiguous to ensure that no other target uses // the output as an alias. - for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i) - TargetAliases[*i] = 0; + for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i) { + TargetAliases[*i] = CM_NULLPTR; + } // Insert the alias into the map. If the alias was already present in the // map and referred to another target, mark it as ambiguous. std::pair<TargetAliasMap::iterator, bool> newAlias = TargetAliases.insert(std::make_pair(buildAlias, target)); - if (newAlias.second && newAlias.first->second != target) - newAlias.first->second = 0; + if (newAlias.second && newAlias.first->second != target) { + newAlias.first->second = CM_NULLPTR; + } } void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) @@ -926,8 +972,9 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) for (TargetAliasMap::const_iterator i = TargetAliases.begin(); i != TargetAliases.end(); ++i) { // Don't write ambiguous aliases. - if (!i->second) + if (!i->second) { continue; + } cmNinjaDeps deps; this->AppendTargetOutputs(i->second, deps); @@ -1227,9 +1274,9 @@ std::string cmGlobalNinjaGenerator::ninjaCmd() const bool cmGlobalNinjaGenerator::SupportsConsolePool() const { - return cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForConsolePool().c_str()) == false; + return !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForConsolePool().c_str()); } void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) |