cmComputeTargetDepends.h 3.2 KB

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