cmComputeTargetDepends.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmComputeTargetDepends_h
  4. #define cmComputeTargetDepends_h
  5. #include <cmConfigure.h> // IWYU pragma: keep
  6. #include "cmGraphAdjacencyList.h"
  7. #include <map>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. class cmComputeComponentGraph;
  12. class cmGeneratorTarget;
  13. class cmGlobalGenerator;
  14. class cmLinkItem;
  15. class cmTargetDependSet;
  16. /** \class cmComputeTargetDepends
  17. * \brief Compute global interdependencies among targets.
  18. *
  19. * Static libraries may form cycles in the target dependency graph.
  20. * This class evaluates target dependencies globally and adjusts them
  21. * to remove cycles while preserving a safe build order.
  22. */
  23. class cmComputeTargetDepends
  24. {
  25. public:
  26. cmComputeTargetDepends(cmGlobalGenerator* gg);
  27. ~cmComputeTargetDepends();
  28. bool Compute();
  29. std::vector<cmGeneratorTarget const*> const& GetTargets() const
  30. {
  31. return this->Targets;
  32. }
  33. void GetTargetDirectDepends(cmGeneratorTarget const* t,
  34. cmTargetDependSet& deps);
  35. private:
  36. void CollectTargets();
  37. void CollectDepends();
  38. void CollectTargetDepends(int depender_index);
  39. void AddTargetDepend(int depender_index, cmLinkItem const& dependee_name,
  40. bool linking);
  41. void AddTargetDepend(int depender_index, cmGeneratorTarget const* dependee,
  42. bool linking);
  43. bool ComputeFinalDepends(cmComputeComponentGraph const& ccg);
  44. void AddInterfaceDepends(int depender_index, cmLinkItem const& dependee_name,
  45. std::set<std::string>& emitted);
  46. void AddInterfaceDepends(int depender_index,
  47. cmGeneratorTarget const* dependee,
  48. const std::string& config,
  49. std::set<std::string>& emitted);
  50. cmGlobalGenerator* GlobalGenerator;
  51. bool DebugMode;
  52. bool NoCycles;
  53. // Collect all targets.
  54. std::vector<cmGeneratorTarget const*> Targets;
  55. std::map<cmGeneratorTarget const*, int> TargetIndex;
  56. // Represent the target dependency graph. The entry at each
  57. // top-level index corresponds to a depender whose dependencies are
  58. // listed.
  59. typedef cmGraphNodeList NodeList;
  60. typedef cmGraphEdgeList EdgeList;
  61. typedef cmGraphAdjacencyList Graph;
  62. Graph InitialGraph;
  63. Graph FinalGraph;
  64. void DisplayGraph(Graph const& graph, const std::string& name);
  65. // Deal with connected components.
  66. void DisplayComponents(cmComputeComponentGraph const& ccg);
  67. bool CheckComponents(cmComputeComponentGraph const& ccg);
  68. void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
  69. bool strong = false);
  70. std::vector<int> ComponentHead;
  71. std::vector<int> ComponentTail;
  72. bool IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
  73. std::set<int>& emitted, std::set<int>& visited);
  74. };
  75. #endif