MCPcopy Create free account
hub / github.com/Kitware/CMake / WriteDependencies

Method WriteDependencies

Source/cmDependsC.cxx:76–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76bool cmDependsC::WriteDependencies(std::set<std::string> const& sources,
77 std::string const& obj,
78 std::ostream& makeDepends,
79 std::ostream& internalDepends)
80{
81 // Make sure this is a scanning instance.
82 if (sources.empty() || sources.begin()->empty()) {
83 cmSystemTools::Error("Cannot scan dependencies without a source file.");
84 return false;
85 }
86 if (obj.empty()) {
87 cmSystemTools::Error("Cannot scan dependencies without an object file.");
88 return false;
89 }
90
91 std::set<std::string> dependencies;
92 bool haveDeps = false;
93
94 // Compute a path to the object file to write to the internal depend file.
95 // Any existing content of the internal depend file has already been
96 // loaded in ValidDeps with this path as a key.
97 std::string obj_i = this->LocalGenerator->MaybeRelativeToTopBinDir(obj);
98
99 if (this->ValidDeps) {
100 auto const tmpIt = this->ValidDeps->find(obj_i);
101 if (tmpIt != this->ValidDeps->end()) {
102 dependencies.insert(tmpIt->second.begin(), tmpIt->second.end());
103 haveDeps = true;
104 }
105 }
106
107 if (!haveDeps) {
108 // Walk the dependency graph starting with the source file.
109 int srcFiles = static_cast<int>(sources.size());
110 this->Encountered.clear();
111
112 for (std::string const& src : sources) {
113 UnscannedEntry root;
114 root.FileName = src;
115 this->Unscanned.push(root);
116 this->Encountered.insert(src);
117 }
118
119 std::set<std::string> scanned;
120 while (!this->Unscanned.empty()) {
121 // Get the next file to scan.
122 UnscannedEntry current = this->Unscanned.front();
123 this->Unscanned.pop();
124
125 // If not a full path, find the file in the include path.
126 std::string fullName;
127 if ((srcFiles > 0) || cmSystemTools::FileIsFullPath(current.FileName)) {
128 if (cmSystemTools::FileExists(current.FileName, true)) {
129 fullName = current.FileName;
130 }
131 } else if (!current.QuotedLocation.empty() &&
132 cmSystemTools::FileExists(current.QuotedLocation, true)) {
133 // The include statement producing this entry was a double-quote

Callers

nothing calls this directly

Calls 15

ScanMethod · 0.95
moveFunction · 0.85
ReadBOMFunction · 0.85
c_strMethod · 0.80
ErrorClass · 0.70
cmStrCatFunction · 0.70
FileExistsFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected