cmGlobalCommonGenerator.cxx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGlobalCommonGenerator.h"
  4. #include <memory>
  5. #include <utility>
  6. #include "cmGeneratorTarget.h"
  7. #include "cmLocalGenerator.h"
  8. #include "cmStateDirectory.h"
  9. #include "cmStateSnapshot.h"
  10. #include "cmStateTypes.h"
  11. #include "cmStringAlgorithms.h"
  12. class cmake;
  13. cmGlobalCommonGenerator::cmGlobalCommonGenerator(cmake* cm)
  14. : cmGlobalGenerator(cm)
  15. {
  16. }
  17. cmGlobalCommonGenerator::~cmGlobalCommonGenerator() = default;
  18. std::map<std::string, cmGlobalCommonGenerator::DirectoryTarget>
  19. cmGlobalCommonGenerator::ComputeDirectoryTargets() const
  20. {
  21. std::map<std::string, DirectoryTarget> dirTargets;
  22. for (const auto& lg : this->LocalGenerators) {
  23. std::string const& currentBinaryDir(
  24. lg->GetStateSnapshot().GetDirectory().GetCurrentBinary());
  25. DirectoryTarget& dirTarget = dirTargets[currentBinaryDir];
  26. dirTarget.LG = lg.get();
  27. // The directory-level rule should depend on the target-level rules
  28. // for all targets in the directory.
  29. for (const auto& gt : lg->GetGeneratorTargets()) {
  30. cmStateEnums::TargetType const type = gt->GetType();
  31. if (type != cmStateEnums::EXECUTABLE &&
  32. type != cmStateEnums::STATIC_LIBRARY &&
  33. type != cmStateEnums::SHARED_LIBRARY &&
  34. type != cmStateEnums::MODULE_LIBRARY &&
  35. type != cmStateEnums::OBJECT_LIBRARY &&
  36. type != cmStateEnums::UTILITY) {
  37. continue;
  38. }
  39. DirectoryTarget::Target t;
  40. t.GT = gt.get();
  41. if (const char* exclude = gt->GetProperty("EXCLUDE_FROM_ALL")) {
  42. if (cmIsOn(exclude)) {
  43. // This target has been explicitly excluded.
  44. t.ExcludeFromAll = true;
  45. } else {
  46. // This target has been explicitly un-excluded. The directory-level
  47. // rule for every directory between this and the root should depend
  48. // on the target-level rule for this target.
  49. for (cmStateSnapshot dir =
  50. lg->GetStateSnapshot().GetBuildsystemDirectoryParent();
  51. dir.IsValid(); dir = dir.GetBuildsystemDirectoryParent()) {
  52. std::string const& d = dir.GetDirectory().GetCurrentBinary();
  53. dirTargets[d].Targets.emplace_back(t);
  54. }
  55. }
  56. }
  57. dirTarget.Targets.emplace_back(t);
  58. }
  59. // The directory-level rule should depend on the directory-level
  60. // rules of the subdirectories.
  61. for (cmStateSnapshot const& state : lg->GetStateSnapshot().GetChildren()) {
  62. DirectoryTarget::Dir d;
  63. d.Path = state.GetDirectory().GetCurrentBinary();
  64. d.ExcludeFromAll =
  65. state.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL");
  66. dirTarget.Children.emplace_back(std::move(d));
  67. }
  68. }
  69. return dirTargets;
  70. }