summaryrefslogtreecommitdiffstats
path: root/Source/cmComputeLinkDepends.h
blob: 881d50fc264baed593c04db0102a771bd3a30bc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef cmComputeLinkDepends_h
#define cmComputeLinkDepends_h

#include "cmStandardIncludes.h"
#include "cmTarget.h"

#include <queue>

class cmGlobalGenerator;
class cmLocalGenerator;
class cmMakefile;
class cmTarget;

/** \class cmComputeLinkDepends
 * \brief Compute link dependencies for targets.
 */
class cmComputeLinkDepends
{
public:
  cmComputeLinkDepends(cmTarget* target, const char* config);
  ~cmComputeLinkDepends();

  // Basic information about each link item.
  struct LinkEntry
  {
    std::string Item;
    cmTarget* Target;
    LinkEntry(): Item(), Target(0) {}
    LinkEntry(LinkEntry const& r): Item(r.Item), Target(r.Target) {}
  };

  typedef std::vector<LinkEntry> EntryVector;
  EntryVector const& Compute();

private:

  // Context information.
  cmTarget* Target;
  cmMakefile* Makefile;
  cmLocalGenerator* LocalGenerator;
  cmGlobalGenerator* GlobalGenerator;
  bool DebugMode;

  // Configuration information.
  const char* Config;

  // Output information.
  EntryVector FinalLinkEntries;

  typedef cmTarget::LinkLibraryVectorType LinkLibraryVectorType;

  int AddLinkEntry(std::string const& item);
  void AddImportedLinkEntries(int depender_index, cmTarget* target);
  void AddVarLinkEntries(int depender_index, const char* value);
  void AddTargetLinkEntries(int depender_index,
                            LinkLibraryVectorType const& libs);
  void AddLinkEntries(int depender_index,
                      std::vector<std::string> const& libs);

  // One entry for each unique item.
  std::vector<LinkEntry> EntryList;
  std::map<cmStdString, int> LinkEntryIndex;

  // BFS of initial dependencies.
  struct BFSEntry
  {
    int Index;
    const char* LibDepends;
  };
  std::queue<BFSEntry> BFSQueue;
  void FollowLinkEntry(BFSEntry const&);

  // Dependency inferral for each link item.
  struct DependSet: public std::set<int> {};
  struct DependSetList: public std::vector<DependSet> {};
  std::vector<DependSetList*> InferredDependSets;
  void InferDependencies();

  // Ordering constraint graph adjacency list.
  struct EntryConstraintSet: public std::set<int> {};
  std::vector<EntryConstraintSet> EntryConstraintGraph;
  void DisplayConstraintGraph();

  // Ordering algorithm.
  std::vector<int> EntryVisited;
  std::set<int> EntryEmitted;
  int WalkId;
  void OrderLinkEntires();
  void VisitLinkEntry(unsigned int i);
  void DisplayFinalEntries();
};

#endif