cmLocalVisualStudio10Generator: Simplify target ordering by dependencies

Replace our own depth-first traversal with use of the global generator's
computed target order that respects dependencies.
This commit is contained in:
Brad King 2020-09-03 15:09:19 -04:00
parent 48bf7192e7
commit 1527242745
2 changed files with 12 additions and 26 deletions

View File

@ -66,29 +66,17 @@ cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
{
}
void cmLocalVisualStudio10Generator::GenerateTargetsDepthFirst(
cmGeneratorTarget* target, std::vector<cmGeneratorTarget*>& remaining)
void cmLocalVisualStudio10Generator::GenerateTarget(cmGeneratorTarget* target)
{
if (!target->IsInBuildSystem()) {
return;
}
// Find this target in the list of remaining targets.
auto it = std::find(remaining.begin(), remaining.end(), target);
if (it == remaining.end()) {
// This target was already handled.
return;
}
// Remove this target from the list of remaining targets because
// we are handling it now.
*it = nullptr;
auto& targetVisited = this->GetSourcesVisited(target);
auto& deps = this->GlobalGenerator->GetTargetDirectDepends(target);
for (auto& d : deps) {
// FIXME: Revise CreateSingleVCProj so we do not have to drop `const` here.
auto dependee = const_cast<cmGeneratorTarget*>(&*d);
GenerateTargetsDepthFirst(dependee, remaining);
// Take the union of visited source files of custom commands
auto visited = GetSourcesVisited(dependee);
GetSourcesVisited(target).insert(visited.begin(), visited.end());
auto depVisited = this->GetSourcesVisited(d);
targetVisited.insert(depVisited.begin(), depVisited.end());
}
if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
->TargetIsFortranOnly(target)) {
@ -104,12 +92,9 @@ void cmLocalVisualStudio10Generator::GenerateTargetsDepthFirst(
void cmLocalVisualStudio10Generator::Generate()
{
std::vector<cmGeneratorTarget*> remaining;
cm::append(remaining, this->GetGeneratorTargets());
for (auto& t : remaining) {
if (t) {
this->GenerateTargetsDepthFirst(t, remaining);
}
for (cmGeneratorTarget* gt :
this->GlobalGenerator->GetLocalGeneratorTargetsInOrder(this)) {
this->GenerateTarget(gt);
}
this->WriteStampFiles();
}

View File

@ -32,7 +32,8 @@ public:
void ReadAndStoreExternalGUID(const std::string& name,
const char* path) override;
std::set<cmSourceFile const*>& GetSourcesVisited(cmGeneratorTarget* target)
std::set<cmSourceFile const*>& GetSourcesVisited(
cmGeneratorTarget const* target)
{
return SourcesVisited[target];
};
@ -42,8 +43,8 @@ protected:
bool CustomCommandUseLocal() const override { return true; }
private:
void GenerateTargetsDepthFirst(cmGeneratorTarget* target,
std::vector<cmGeneratorTarget*>& remaining);
void GenerateTarget(cmGeneratorTarget* target);
std::map<cmGeneratorTarget*, std::set<cmSourceFile const*>> SourcesVisited;
std::map<cmGeneratorTarget const*, std::set<cmSourceFile const*>>
SourcesVisited;
};