cmComputeTargetDepends.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmComputeTargetDepends_h
  11. #define cmComputeTargetDepends_h
  12. #include "cmStandardIncludes.h"
  13. #include "cmGraphAdjacencyList.h"
  14. #include <stack>
  15. class cmComputeComponentGraph;
  16. class cmGlobalGenerator;
  17. class cmTarget;
  18. class cmTargetDependSet;
  19. /** \class cmComputeTargetDepends
  20. * \brief Compute global interdependencies among targets.
  21. *
  22. * Static libraries may form cycles in the target dependency graph.
  23. * This class evaluates target dependencies globally and adjusts them
  24. * to remove cycles while preserving a safe build order.
  25. */
  26. class cmComputeTargetDepends
  27. {
  28. public:
  29. cmComputeTargetDepends(cmGlobalGenerator* gg);
  30. ~cmComputeTargetDepends();
  31. bool Compute();
  32. std::vector<cmTarget*> const& GetTargets() const { return this->Targets; }
  33. void GetTargetDirectDepends(cmTarget* t, cmTargetDependSet& deps);
  34. private:
  35. void CollectTargets();
  36. void CollectDepends();
  37. void CollectTargetDepends(int depender_index);
  38. void AddTargetDepend(int depender_index, const char* dependee_name,
  39. bool linking);
  40. void AddTargetDepend(int depender_index, cmTarget* dependee, bool linking);
  41. bool ComputeFinalDepends(cmComputeComponentGraph const& ccg);
  42. cmGlobalGenerator* GlobalGenerator;
  43. bool DebugMode;
  44. bool NoCycles;
  45. // Collect all targets.
  46. std::vector<cmTarget*> Targets;
  47. std::map<cmTarget*, int> TargetIndex;
  48. // Represent the target dependency graph. The entry at each
  49. // top-level index corresponds to a depender whose dependencies are
  50. // listed.
  51. typedef cmGraphNodeList NodeList;
  52. typedef cmGraphEdgeList EdgeList;
  53. typedef cmGraphAdjacencyList Graph;
  54. Graph InitialGraph;
  55. Graph FinalGraph;
  56. void DisplayGraph(Graph const& graph, const char* name);
  57. // Deal with connected components.
  58. void DisplayComponents(cmComputeComponentGraph const& ccg);
  59. bool CheckComponents(cmComputeComponentGraph const& ccg);
  60. void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
  61. bool strong = false);
  62. std::vector<int> ComponentHead;
  63. std::vector<int> ComponentTail;
  64. bool IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
  65. std::set<int>& emitted, std::set<int>& visited);
  66. };
  67. #endif