diff options
author | Brad King <brad.king@kitware.com> | 2019-09-27 13:23:35 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-09-30 14:33:20 (GMT) |
commit | d713bcb6427381ab8743084726196a4eed96c135 (patch) | |
tree | db9efe36c12ef50225a7e6d5361971f94063899c /Source/cmGlobalCommonGenerator.cxx | |
parent | a75586c775eb8f663ca1372ff20f9a51e1ad420d (diff) | |
download | CMake-d713bcb6427381ab8743084726196a4eed96c135.zip CMake-d713bcb6427381ab8743084726196a4eed96c135.tar.gz CMake-d713bcb6427381ab8743084726196a4eed96c135.tar.bz2 |
Ninja: Factor out per-dir "all" target computation into common generator
This will make it re-usable for the Makefile generator.
Diffstat (limited to 'Source/cmGlobalCommonGenerator.cxx')
-rw-r--r-- | Source/cmGlobalCommonGenerator.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Source/cmGlobalCommonGenerator.cxx b/Source/cmGlobalCommonGenerator.cxx index bf992b4..93ff00b 100644 --- a/Source/cmGlobalCommonGenerator.cxx +++ b/Source/cmGlobalCommonGenerator.cxx @@ -2,6 +2,15 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGlobalCommonGenerator.h" +#include "cmGeneratorTarget.h" +#include "cmLocalGenerator.h" +#include "cmStateDirectory.h" +#include "cmStateSnapshot.h" +#include "cmStateTypes.h" +#include "cmStringAlgorithms.h" + +#include <utility> + class cmake; cmGlobalCommonGenerator::cmGlobalCommonGenerator(cmake* cm) @@ -10,3 +19,60 @@ cmGlobalCommonGenerator::cmGlobalCommonGenerator(cmake* cm) } cmGlobalCommonGenerator::~cmGlobalCommonGenerator() = default; + +std::map<std::string, cmGlobalCommonGenerator::DirectoryTarget> +cmGlobalCommonGenerator::ComputeDirectoryTargets() const +{ + std::map<std::string, DirectoryTarget> dirTargets; + for (cmLocalGenerator* lg : this->LocalGenerators) { + std::string const& currentBinaryDir( + lg->GetStateSnapshot().GetDirectory().GetCurrentBinary()); + DirectoryTarget& dirTarget = dirTargets[currentBinaryDir]; + dirTarget.LG = lg; + + // The directory-level rule should depend on the target-level rules + // for all targets in the directory. + for (auto gt : lg->GetGeneratorTargets()) { + cmStateEnums::TargetType const type = gt->GetType(); + if (type != cmStateEnums::EXECUTABLE && + type != cmStateEnums::STATIC_LIBRARY && + type != cmStateEnums::SHARED_LIBRARY && + type != cmStateEnums::MODULE_LIBRARY && + type != cmStateEnums::OBJECT_LIBRARY && + type != cmStateEnums::UTILITY) { + continue; + } + DirectoryTarget::Target t; + t.GT = gt; + if (const char* exclude = gt->GetProperty("EXCLUDE_FROM_ALL")) { + if (cmIsOn(exclude)) { + // This target has been explicitly excluded. + t.ExcludeFromAll = true; + } else { + // This target has been explicitly un-excluded. The directory-level + // rule for every directory between this and the root should depend + // on the target-level rule for this target. + for (cmStateSnapshot dir = + lg->GetStateSnapshot().GetBuildsystemDirectoryParent(); + dir.IsValid(); dir = dir.GetBuildsystemDirectoryParent()) { + std::string const& d = dir.GetDirectory().GetCurrentBinary(); + dirTargets[d].Targets.emplace_back(t); + } + } + } + dirTarget.Targets.emplace_back(t); + } + + // The directory-level rule should depend on the directory-level + // rules of the subdirectories. + for (cmStateSnapshot const& state : lg->GetStateSnapshot().GetChildren()) { + DirectoryTarget::Dir d; + d.Path = state.GetDirectory().GetCurrentBinary(); + d.ExcludeFromAll = + state.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL"); + dirTarget.Children.emplace_back(std::move(d)); + } + } + + return dirTargets; +} |