cmComputeTargetDepends.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. const std::string& config,
  46. std::set<std::string>& emitted);
  47. void AddInterfaceDepends(int depender_index,
  48. cmGeneratorTarget const* dependee,
  49. const std::string& config,
  50. std::set<std::string>& emitted);
  51. cmGlobalGenerator* GlobalGenerator;
  52. bool DebugMode;
  53. bool NoCycles;
  54. // Collect all targets.
  55. std::vector<cmGeneratorTarget const*> Targets;
  56. std::map<cmGeneratorTarget const*, int> TargetIndex;
  57. // Represent the target dependency graph. The entry at each
  58. // top-level index corresponds to a depender whose dependencies are
  59. // listed.
  60. typedef cmGraphNodeList NodeList;
  61. typedef cmGraphEdgeList EdgeList;
  62. typedef cmGraphAdjacencyList Graph;
  63. Graph InitialGraph;
  64. Graph FinalGraph;
  65. void DisplayGraph(Graph const& graph, const std::string& name);
  66. // Deal with connected components.
  67. void DisplayComponents(cmComputeComponentGraph const& ccg);
  68. bool CheckComponents(cmComputeComponentGraph const& ccg);
  69. void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
  70. bool strong = false);
  71. std::vector<int> ComponentHead;
  72. std::vector<int> ComponentTail;
  73. bool IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
  74. std::set<int>& emitted, std::set<int>& visited);
  75. };
  76. #endif