/src/CMake/Source/cmGlobalUnixMakefileGenerator3.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmGlobalUnixMakefileGenerator3.h" |
4 | | |
5 | | #include <algorithm> |
6 | | #include <functional> |
7 | | #include <sstream> |
8 | | #include <utility> |
9 | | |
10 | | #include <cm/memory> |
11 | | #include <cmext/algorithm> |
12 | | #include <cmext/memory> |
13 | | |
14 | | #include "cmsys/RegularExpression.hxx" |
15 | | |
16 | | #include "cmCustomCommand.h" |
17 | | #include "cmDuration.h" |
18 | | #include "cmGeneratedFileStream.h" |
19 | | #include "cmGeneratorTarget.h" |
20 | | #include "cmGlobalGenerator.h" |
21 | | #include "cmLocalGenerator.h" |
22 | | #include "cmLocalUnixMakefileGenerator3.h" |
23 | | #include "cmMakefile.h" |
24 | | #include "cmMakefileTargetGenerator.h" |
25 | | #include "cmMessageType.h" |
26 | | #include "cmOutputConverter.h" |
27 | | #include "cmSourceFile.h" |
28 | | #include "cmState.h" |
29 | | #include "cmStringAlgorithms.h" |
30 | | #include "cmSystemTools.h" |
31 | | #include "cmTarget.h" |
32 | | #include "cmTargetDepend.h" |
33 | | #include "cmTargetTypes.h" |
34 | | #include "cmTest.h" |
35 | | #include "cmTestGenerator.h" |
36 | | #include "cmValue.h" |
37 | | #include "cmake.h" |
38 | | |
39 | | cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3(cmake* cm) |
40 | 0 | : cmGlobalCommonGenerator(cm) |
41 | 0 | { |
42 | | // This type of makefile always requires unix style paths |
43 | 0 | this->ForceUnixPaths = true; |
44 | 0 | this->FindMakeProgramFile = "CMakeUnixFindMake.cmake"; |
45 | 0 | this->ToolSupportsColor = true; |
46 | |
|
47 | | #if defined(_WIN32) || defined(__VMS) |
48 | | this->UseLinkScript = false; |
49 | | #else |
50 | 0 | this->UseLinkScript = true; |
51 | 0 | #endif |
52 | |
|
53 | 0 | this->IncludeDirective = "include"; |
54 | 0 | this->LineContinueDirective = "\\\n"; |
55 | 0 | this->DefineWindowsNULL = false; |
56 | 0 | this->PassMakeflags = false; |
57 | 0 | this->UnixCD = true; |
58 | 0 | } |
59 | | |
60 | 0 | cmGlobalUnixMakefileGenerator3::~cmGlobalUnixMakefileGenerator3() = default; |
61 | | |
62 | | void cmGlobalUnixMakefileGenerator3::EnableLanguage( |
63 | | std::vector<std::string> const& languages, cmMakefile* mf, bool optional) |
64 | 0 | { |
65 | 0 | this->cmGlobalGenerator::EnableLanguage(languages, mf, optional); |
66 | 0 | for (std::string const& language : languages) { |
67 | 0 | if (language == "NONE") { |
68 | 0 | continue; |
69 | 0 | } |
70 | 0 | this->ResolveLanguageCompiler(language, mf, optional); |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | | //! Create a local generator appropriate to this Global Generator |
75 | | std::unique_ptr<cmLocalGenerator> |
76 | | cmGlobalUnixMakefileGenerator3::CreateLocalGenerator(cmMakefile* mf) |
77 | 0 | { |
78 | 0 | return std::unique_ptr<cmLocalGenerator>( |
79 | 0 | cm::make_unique<cmLocalUnixMakefileGenerator3>(this, mf)); |
80 | 0 | } |
81 | | |
82 | | cmDocumentationEntry cmGlobalUnixMakefileGenerator3::GetDocumentation() |
83 | 0 | { |
84 | 0 | return { cmGlobalUnixMakefileGenerator3::GetActualName(), |
85 | 0 | "Generates standard UNIX makefiles." }; |
86 | 0 | } |
87 | | |
88 | | bool cmGlobalUnixMakefileGenerator3::SupportsShortObjectNames() const |
89 | 0 | { |
90 | 0 | return true; |
91 | 0 | } |
92 | | |
93 | | void cmGlobalUnixMakefileGenerator3::ComputeTargetObjectDirectory( |
94 | | cmGeneratorTarget* gt) const |
95 | 0 | { |
96 | | // Compute full path to object file directory for this target. |
97 | 0 | std::string dir = cmStrCat(gt->GetSupportDirectory(), '/'); |
98 | 0 | gt->ObjectDirectory = dir; |
99 | 0 | } |
100 | | |
101 | | bool cmGlobalUnixMakefileGenerator3::IsInstallPrepComponentRepresentable( |
102 | | std::string const& component) const |
103 | 0 | { |
104 | | // A Makefile rule name cannot contain ':'. |
105 | 0 | return component.find(':') == std::string::npos && |
106 | 0 | this->cmGlobalGenerator::IsInstallPrepComponentRepresentable(component); |
107 | 0 | } |
108 | | |
109 | | bool cmGlobalUnixMakefileGenerator3::CanEscapeOctothorpe() const |
110 | 0 | { |
111 | | // Make tools that use UNIX-style '/' paths also support '\' escaping. |
112 | 0 | return this->ForceUnixPaths; |
113 | 0 | } |
114 | | |
115 | | void cmGlobalUnixMakefileGenerator3::Configure() |
116 | 0 | { |
117 | | // Initialize CMAKE_EDIT_COMMAND cache entry. |
118 | 0 | this->GetEditCacheCommand(); |
119 | |
|
120 | 0 | this->cmGlobalGenerator::Configure(); |
121 | 0 | } |
122 | | |
123 | | void cmGlobalUnixMakefileGenerator3::Generate() |
124 | 0 | { |
125 | 0 | this->ClangTidyExportFixesDirs.clear(); |
126 | 0 | this->ClangTidyExportFixesFiles.clear(); |
127 | |
|
128 | 0 | this->TestPrepTargets.clear(); |
129 | 0 | this->TestPrepEnabled = false; |
130 | | |
131 | | // Compute the "test_prep/" and "install_prep/" targets before generating the |
132 | | // local makefiles so they can be emitted in a single pass. |
133 | 0 | this->ComputeTestPrepTargets(); |
134 | 0 | this->ComputeInstallPrepTargets(); |
135 | | |
136 | | // first do superclass method |
137 | 0 | this->cmGlobalGenerator::Generate(); |
138 | | |
139 | | // initialize progress |
140 | 0 | unsigned long total = 0; |
141 | 0 | for (auto const& pmi : this->ProgressMap) { |
142 | 0 | total += pmi.second.NumberOfActions; |
143 | 0 | } |
144 | | |
145 | | // write each target's progress.make this loop is done twice. Basically the |
146 | | // Generate pass counts all the actions, the first loop below determines |
147 | | // how many actions have progress updates for each target and writes to |
148 | | // correct variable values for everything except the all targets. The |
149 | | // second loop actually writes out correct values for the all targets as |
150 | | // well. This is because the all targets require more information that is |
151 | | // computed in the first loop. |
152 | 0 | unsigned long current = 0; |
153 | 0 | for (auto& pmi : this->ProgressMap) { |
154 | 0 | pmi.second.WriteProgressVariables(total, current); |
155 | 0 | } |
156 | 0 | for (auto const& lg : this->LocalGenerators) { |
157 | 0 | std::string markFileName = |
158 | 0 | cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles/progress.marks"); |
159 | 0 | cmGeneratedFileStream markFile(markFileName); |
160 | 0 | markFile << this->CountProgressMarksInAll(*lg) << "\n"; |
161 | 0 | } |
162 | | |
163 | | // write the main makefile |
164 | 0 | this->WriteMainMakefile2(); |
165 | 0 | this->WriteMainCMakefile(); |
166 | |
|
167 | 0 | if (this->CommandDatabase) { |
168 | 0 | *this->CommandDatabase << "\n]"; |
169 | 0 | this->CommandDatabase.reset(); |
170 | 0 | } |
171 | |
|
172 | 0 | this->RemoveUnknownClangTidyExportFixesFiles(); |
173 | 0 | } |
174 | | |
175 | | void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand( |
176 | | std::string const& sourceFile, std::string const& workingDirectory, |
177 | | std::string const& compileCommand, std::string const& objPath) |
178 | 0 | { |
179 | 0 | if (!this->CommandDatabase) { |
180 | 0 | std::string commandDatabaseName = |
181 | 0 | this->GetCMakeInstance()->GetHomeOutputDirectory() + |
182 | 0 | "/compile_commands.json"; |
183 | 0 | this->CommandDatabase = |
184 | 0 | cm::make_unique<cmGeneratedFileStream>(commandDatabaseName); |
185 | 0 | *this->CommandDatabase << "[\n"; |
186 | 0 | } else { |
187 | 0 | *this->CommandDatabase << ",\n"; |
188 | 0 | } |
189 | 0 | *this->CommandDatabase << "{\n" |
190 | 0 | << R"( "directory": ")" |
191 | 0 | << cmGlobalGenerator::EscapeJSON(workingDirectory) |
192 | 0 | << "\",\n" |
193 | 0 | << R"( "command": ")" |
194 | 0 | << cmGlobalGenerator::EscapeJSON(compileCommand) |
195 | 0 | << "\",\n" |
196 | 0 | << R"( "file": ")" |
197 | 0 | << cmGlobalGenerator::EscapeJSON(sourceFile) |
198 | 0 | << "\",\n" |
199 | 0 | << R"( "output": ")" |
200 | 0 | << cmGlobalGenerator::EscapeJSON(objPath) << "\"\n}"; |
201 | 0 | } |
202 | | |
203 | | void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2() |
204 | 0 | { |
205 | | // Open the output file. This should not be copy-if-different |
206 | | // because the check-build-system step compares the makefile time to |
207 | | // see if the build system must be regenerated. |
208 | 0 | std::string makefileName = |
209 | 0 | cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), |
210 | 0 | "/CMakeFiles/Makefile2"); |
211 | 0 | cmGeneratedFileStream makefileStream(makefileName, false, |
212 | 0 | this->GetMakefileEncoding()); |
213 | 0 | if (!makefileStream) { |
214 | 0 | return; |
215 | 0 | } |
216 | | |
217 | | // The global dependency graph is expressed via the root local generator. |
218 | 0 | auto& rootLG = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>( |
219 | 0 | this->LocalGenerators[0]); |
220 | | |
221 | | // Write the do not edit header. |
222 | 0 | rootLG.WriteDisclaimer(makefileStream); |
223 | | |
224 | | // Write the main entry point target. This must be the VERY first |
225 | | // target so that make with no arguments will run it. |
226 | | // Just depend on the all target to drive the build. |
227 | 0 | std::vector<std::string> depends; |
228 | 0 | std::vector<std::string> no_commands; |
229 | 0 | depends.emplace_back("all"); |
230 | | |
231 | | // Write the rule. |
232 | 0 | rootLG.WriteMakeRule(makefileStream, |
233 | 0 | "Default target executed when no arguments are " |
234 | 0 | "given to make.", |
235 | 0 | "default_target", depends, no_commands, true); |
236 | |
|
237 | 0 | depends.clear(); |
238 | | |
239 | | // The all and preinstall rules might never have any dependencies |
240 | | // added to them. |
241 | 0 | if (!this->EmptyRuleHackDepends.empty()) { |
242 | 0 | depends.push_back(this->EmptyRuleHackDepends); |
243 | 0 | } |
244 | | |
245 | | // Write out the "special" stuff |
246 | 0 | rootLG.WriteSpecialTargetsTop(makefileStream); |
247 | | |
248 | | // Write the directory level rules. |
249 | 0 | for (auto const& it : this->ComputeDirectoryTargets()) { |
250 | 0 | this->WriteDirectoryRules2(makefileStream, rootLG, it.second); |
251 | 0 | } |
252 | | |
253 | | // Write the target convenience rules |
254 | 0 | for (auto const& localGen : this->LocalGenerators) { |
255 | 0 | this->WriteConvenienceRules2( |
256 | 0 | makefileStream, rootLG, |
257 | 0 | cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(localGen)); |
258 | 0 | } |
259 | | |
260 | | // Write the internal test_prep/ and install_prep/ rules. |
261 | 0 | this->WriteTestPrepRules(makefileStream, rootLG); |
262 | 0 | this->WriteInstallPrepRules(makefileStream, rootLG); |
263 | | |
264 | | // Write special bottom targets |
265 | 0 | rootLG.WriteSpecialTargetsBottom(makefileStream); |
266 | 0 | } |
267 | | |
268 | | void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() |
269 | 0 | { |
270 | 0 | if (this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) { |
271 | 0 | return; |
272 | 0 | } |
273 | | |
274 | | // Open the output file. This should not be copy-if-different |
275 | | // because the check-build-system step compares the makefile time to |
276 | | // see if the build system must be regenerated. |
277 | 0 | std::string cmakefileName = |
278 | 0 | cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), |
279 | 0 | "/CMakeFiles/Makefile.cmake"); |
280 | 0 | cmGeneratedFileStream cmakefileStream(cmakefileName); |
281 | 0 | if (!cmakefileStream) { |
282 | 0 | return; |
283 | 0 | } |
284 | | |
285 | 0 | std::string makefileName = |
286 | 0 | cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), "/Makefile"); |
287 | |
|
288 | 0 | { |
289 | | // get a local generator for some useful methods |
290 | 0 | auto& lg = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>( |
291 | 0 | this->LocalGenerators[0]); |
292 | | |
293 | | // Write the do not edit header. |
294 | 0 | lg.WriteDisclaimer(cmakefileStream); |
295 | 0 | } |
296 | | |
297 | | // Save the generator name |
298 | 0 | cmakefileStream << "# The generator used is:\n" |
299 | 0 | << "set(CMAKE_DEPENDS_GENERATOR \"" << this->GetName() |
300 | 0 | << "\")\n\n"; |
301 | | |
302 | | // for each cmMakefile get its list of dependencies |
303 | 0 | std::vector<std::string> lfiles; |
304 | 0 | for (auto const& localGen : this->LocalGenerators) { |
305 | | // Get the list of files contributing to this generation step. |
306 | 0 | cm::append(lfiles, localGen->GetMakefile()->GetListFiles()); |
307 | 0 | } |
308 | |
|
309 | 0 | cmake* cm = this->GetCMakeInstance(); |
310 | 0 | if (cm->DoWriteGlobVerifyTarget()) { |
311 | 0 | lfiles.push_back(cm->GetGlobVerifyScript()); |
312 | 0 | lfiles.push_back(cm->GetGlobVerifyStamp()); |
313 | 0 | } |
314 | | |
315 | | // Sort the list and remove duplicates. |
316 | 0 | std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>()); |
317 | 0 | #if !defined(__VMS) // The Compaq STL on VMS crashes, so accept duplicates. |
318 | 0 | auto new_end = std::unique(lfiles.begin(), lfiles.end()); |
319 | 0 | lfiles.erase(new_end, lfiles.end()); |
320 | 0 | #endif |
321 | |
|
322 | 0 | { |
323 | | // reset lg to the first makefile |
324 | 0 | auto const& lg = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>( |
325 | 0 | this->LocalGenerators[0]); |
326 | | |
327 | | // Save the list to the cmake file. |
328 | 0 | cmakefileStream |
329 | 0 | << "# The top level Makefile was generated from the following files:\n" |
330 | 0 | << "set(CMAKE_MAKEFILE_DEPENDS\n" |
331 | 0 | << " \"CMakeCache.txt\"\n"; |
332 | 0 | for (std::string const& f : lfiles) { |
333 | 0 | cmakefileStream << " \"" << lg.MaybeRelativeToCurBinDir(f) << "\"\n"; |
334 | 0 | } |
335 | 0 | cmakefileStream << " )\n\n"; |
336 | | |
337 | | // Build the path to the cache check file. |
338 | 0 | std::string check = |
339 | 0 | cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(), |
340 | 0 | "/CMakeFiles/cmake.check_cache"); |
341 | | |
342 | | // Set the corresponding makefile in the cmake file. |
343 | 0 | cmakefileStream << "# The corresponding makefile is:\n" |
344 | 0 | << "set(CMAKE_MAKEFILE_OUTPUTS\n" |
345 | 0 | << " \"" << lg.MaybeRelativeToCurBinDir(makefileName) |
346 | 0 | << "\"\n" |
347 | 0 | << " \"" << lg.MaybeRelativeToCurBinDir(check) << "\"\n"; |
348 | 0 | cmakefileStream << " )\n\n"; |
349 | | |
350 | | // CMake must rerun if a byproduct is missing. |
351 | 0 | cmakefileStream << "# Byproducts of CMake generate step:\n" |
352 | 0 | << "set(CMAKE_MAKEFILE_PRODUCTS\n"; |
353 | | |
354 | | // add in any byproducts and all the directory information files |
355 | 0 | std::string tmpStr; |
356 | 0 | for (auto const& localGen : this->LocalGenerators) { |
357 | 0 | for (std::string const& outfile : |
358 | 0 | localGen->GetMakefile()->GetOutputFiles()) { |
359 | 0 | cmakefileStream << " \"" << lg.MaybeRelativeToTopBinDir(outfile) |
360 | 0 | << "\"\n"; |
361 | 0 | } |
362 | 0 | tmpStr = cmStrCat(localGen->GetCurrentBinaryDirectory(), |
363 | 0 | "/CMakeFiles/CMakeDirectoryInformation.cmake"); |
364 | 0 | cmakefileStream << " \"" << localGen->MaybeRelativeToTopBinDir(tmpStr) |
365 | 0 | << "\"\n"; |
366 | 0 | } |
367 | 0 | cmakefileStream << " )\n\n"; |
368 | 0 | } |
369 | |
|
370 | 0 | this->WriteMainCMakefileLanguageRules(cmakefileStream, |
371 | 0 | this->LocalGenerators); |
372 | 0 | } |
373 | | |
374 | | void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules( |
375 | | cmGeneratedFileStream& cmakefileStream, |
376 | | std::vector<std::unique_ptr<cmLocalGenerator>>& lGenerators) |
377 | 0 | { |
378 | | // now list all the target info files |
379 | 0 | cmakefileStream << "# Dependency information for all targets:\n"; |
380 | 0 | cmakefileStream << "set(CMAKE_DEPEND_INFO_FILES\n"; |
381 | 0 | for (auto const& lGenerator : lGenerators) { |
382 | 0 | auto const& lg = |
383 | 0 | cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(lGenerator); |
384 | | // for all of out targets |
385 | 0 | for (auto const& tgt : lg.GetGeneratorTargets()) { |
386 | 0 | if (tgt->IsInBuildSystem() && |
387 | 0 | tgt->GetType() != cm::TargetType::GLOBAL_TARGET) { |
388 | 0 | std::string tname = cmStrCat(lg.GetRelativeTargetDirectory(tgt.get()), |
389 | 0 | "/DependInfo.cmake"); |
390 | 0 | cmSystemTools::ConvertToUnixSlashes(tname); |
391 | 0 | cmakefileStream << " \"" << tname << "\"\n"; |
392 | 0 | } |
393 | 0 | } |
394 | 0 | } |
395 | 0 | cmakefileStream << " )\n"; |
396 | 0 | } |
397 | | |
398 | | void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( |
399 | | std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3& rootLG, |
400 | | DirectoryTarget const& dt, char const* pass, bool check_all, |
401 | | bool check_relink, std::vector<std::string> const& commands) |
402 | 0 | { |
403 | 0 | auto* lg = static_cast<cmLocalUnixMakefileGenerator3*>(dt.LG); |
404 | 0 | std::string makeTarget = |
405 | 0 | cmStrCat(lg->GetCurrentBinaryDirectory(), '/', pass); |
406 | | |
407 | | // The directory-level rule should depend on the target-level rules |
408 | | // for all targets in the directory. |
409 | 0 | std::vector<std::string> depends; |
410 | 0 | for (DirectoryTarget::Target const& t : dt.Targets) { |
411 | | // Add this to the list of depends rules in this directory. |
412 | 0 | if ((!check_all || t.ExcludedFromAllInConfigs.empty()) && |
413 | 0 | (!check_relink || |
414 | 0 | t.GT->NeedRelinkBeforeInstall(lg->GetConfigName()))) { |
415 | | // The target may be from a different directory; use its local gen. |
416 | 0 | auto const* tlg = static_cast<cmLocalUnixMakefileGenerator3 const*>( |
417 | 0 | t.GT->GetLocalGenerator()); |
418 | 0 | std::string tname = |
419 | 0 | cmStrCat(tlg->GetRelativeTargetDirectory(t.GT), '/', pass); |
420 | 0 | depends.push_back(std::move(tname)); |
421 | 0 | } |
422 | 0 | } |
423 | | |
424 | | // The directory-level rule should depend on the directory-level |
425 | | // rules of the subdirectories. |
426 | 0 | for (DirectoryTarget::Dir const& d : dt.Children) { |
427 | 0 | if (check_all && d.ExcludeFromAll) { |
428 | 0 | continue; |
429 | 0 | } |
430 | 0 | std::string subdir = cmStrCat(d.Path, '/', pass); |
431 | 0 | depends.push_back(std::move(subdir)); |
432 | 0 | } |
433 | | |
434 | | // Work-around for makes that drop rules that have no dependencies |
435 | | // or commands. |
436 | 0 | if (depends.empty() && !this->EmptyRuleHackDepends.empty()) { |
437 | 0 | depends.push_back(this->EmptyRuleHackDepends); |
438 | 0 | } |
439 | | |
440 | | // Write the rule. |
441 | 0 | std::string doc; |
442 | 0 | if (lg->IsRootMakefile()) { |
443 | 0 | doc = cmStrCat("The main recursive \"", pass, "\" target."); |
444 | 0 | } else { |
445 | 0 | doc = cmStrCat("Recursive \"", pass, "\" directory target."); |
446 | 0 | } |
447 | |
|
448 | 0 | rootLG.WriteMakeRule(ruleFileStream, doc.c_str(), makeTarget, depends, |
449 | 0 | commands, true); |
450 | 0 | } |
451 | | |
452 | | void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( |
453 | | std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3& rootLG, |
454 | | DirectoryTarget const& dt) |
455 | 0 | { |
456 | 0 | auto* lg = static_cast<cmLocalUnixMakefileGenerator3*>(dt.LG); |
457 | | // Begin the directory-level rules section. |
458 | 0 | { |
459 | 0 | std::string dir = cmSystemTools::ConvertToOutputPath( |
460 | 0 | rootLG.MaybeRelativeToTopBinDir(lg->GetCurrentBinaryDirectory())); |
461 | 0 | rootLG.WriteDivider(ruleFileStream); |
462 | 0 | if (lg->IsRootMakefile()) { |
463 | 0 | ruleFileStream << "# Directory level rules for the build root directory"; |
464 | 0 | } else { |
465 | 0 | ruleFileStream << "# Directory level rules for directory " << dir; |
466 | 0 | } |
467 | 0 | ruleFileStream << "\n\n"; |
468 | 0 | } |
469 | | |
470 | | // Write directory-level rules for "all". |
471 | 0 | this->WriteDirectoryRule2(ruleFileStream, rootLG, dt, "all", true, false); |
472 | | |
473 | | // Write directory-level rules for "codegen". |
474 | 0 | this->WriteDirectoryRule2(ruleFileStream, rootLG, dt, "codegen", true, |
475 | 0 | false); |
476 | | |
477 | | // Write directory-level rules for "preinstall". |
478 | 0 | this->WriteDirectoryRule2(ruleFileStream, rootLG, dt, "preinstall", true, |
479 | 0 | true); |
480 | | |
481 | | // Write directory-level rules for "clean". |
482 | 0 | { |
483 | 0 | std::vector<std::string> cmds; |
484 | 0 | lg->AppendDirectoryCleanCommand(cmds); |
485 | 0 | this->WriteDirectoryRule2(ruleFileStream, rootLG, dt, "clean", false, |
486 | 0 | false, cmds); |
487 | 0 | } |
488 | 0 | } |
489 | | |
490 | | namespace { |
491 | | std::string ConvertToMakefilePathForUnix(std::string const& path, |
492 | | bool isForceQuote) |
493 | 0 | { |
494 | 0 | bool const quote = isForceQuote; |
495 | 0 | std::string result; |
496 | 0 | result.reserve(path.size() + (quote ? 2 : 0)); |
497 | 0 | if (quote) { |
498 | 0 | result.push_back('"'); |
499 | 0 | } |
500 | 0 | for (char c : path) { |
501 | 0 | switch (c) { |
502 | 0 | case '=': |
503 | | // We provide 'EQUALS = =' to encode '=' in a non-assignment case. |
504 | 0 | result.append("$(EQUALS)"); |
505 | 0 | break; |
506 | 0 | case '$': |
507 | 0 | result.append("$$"); |
508 | 0 | break; |
509 | 0 | case '\\': |
510 | 0 | case ' ': |
511 | 0 | case '#': |
512 | 0 | result.push_back('\\'); |
513 | 0 | CM_FALLTHROUGH; |
514 | 0 | default: |
515 | 0 | result.push_back(c); |
516 | 0 | break; |
517 | 0 | } |
518 | 0 | } |
519 | 0 | if (quote) { |
520 | 0 | result.push_back('"'); |
521 | 0 | } |
522 | 0 | return result; |
523 | 0 | } |
524 | | |
525 | | #if defined(_WIN32) && !defined(__CYGWIN__) |
526 | | std::string ConvertToMakefilePathForWindows(std::string const& path, |
527 | | bool isForceQuote) |
528 | | { |
529 | | bool const quote = |
530 | | isForceQuote || path.find_first_of(" #") != std::string::npos; |
531 | | std::string result; |
532 | | result.reserve(path.size() + (quote ? 2 : 0)); |
533 | | if (quote) { |
534 | | result.push_back('"'); |
535 | | } |
536 | | for (char c : path) { |
537 | | switch (c) { |
538 | | case '=': |
539 | | // We provide 'EQUALS = =' to encode '=' in a non-assignment case. |
540 | | result.append("$(EQUALS)"); |
541 | | break; |
542 | | case '$': |
543 | | result.append("$$"); |
544 | | break; |
545 | | case '/': |
546 | | result.push_back('\\'); |
547 | | break; |
548 | | default: |
549 | | result.push_back(c); |
550 | | break; |
551 | | } |
552 | | } |
553 | | if (quote) { |
554 | | result.push_back('"'); |
555 | | } |
556 | | return result; |
557 | | } |
558 | | #endif |
559 | | } |
560 | | |
561 | | std::string cmGlobalUnixMakefileGenerator3::ConvertToMakefilePath( |
562 | | std::string const& path) const |
563 | 0 | { |
564 | | // Watcom WMake treats '+' as special. Quote the whole path so names |
565 | | // containing '+' (e.g. test+1.c, stdc++.cmake) are accepted. |
566 | 0 | bool const isWatcomWMake = |
567 | 0 | this->GetCMakeInstance()->GetState()->UseWatcomWMake(); |
568 | 0 | bool const isForceQuote = |
569 | 0 | isWatcomWMake && path.find('+') != std::string::npos; |
570 | |
|
571 | | #if defined(_WIN32) && !defined(__CYGWIN__) |
572 | | if (!this->ForceUnixPaths) { |
573 | | return ConvertToMakefilePathForWindows(path, isForceQuote); |
574 | | } |
575 | | #endif |
576 | 0 | return ConvertToMakefilePathForUnix(path, isForceQuote); |
577 | 0 | } |
578 | | |
579 | | std::vector<cmGlobalGenerator::GeneratedMakeCommand> |
580 | | cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( |
581 | | std::string const& makeProgram, std::string const& /*projectName*/, |
582 | | std::string const& /*projectDir*/, |
583 | | std::vector<std::string> const& targetNames, std::string const& /*config*/, |
584 | | int jobs, bool verbose, cmBuildOptions buildOptions, |
585 | | std::vector<std::string> const& makeOptions, |
586 | | BuildTryCompile /*isInTryCompile*/) |
587 | 0 | { |
588 | 0 | GeneratedMakeCommand makeCommand; |
589 | | |
590 | | // Make it possible to set verbosity also from command line |
591 | 0 | if (verbose) { |
592 | 0 | makeCommand.Add(cmSystemTools::GetCMakeCommand()); |
593 | 0 | makeCommand.Add("-E"); |
594 | 0 | makeCommand.Add("env"); |
595 | 0 | makeCommand.Add("VERBOSE=1"); |
596 | 0 | } |
597 | 0 | makeCommand.Add(this->SelectMakeProgram(makeProgram)); |
598 | | |
599 | | // Explicitly tell the make tool to use the Makefile written by |
600 | | // cmLocalUnixMakefileGenerator3::WriteLocalMakefile |
601 | 0 | makeCommand.Add("-f"); |
602 | 0 | makeCommand.Add("Makefile"); |
603 | |
|
604 | 0 | if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) { |
605 | 0 | if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) { |
606 | 0 | makeCommand.Add("-j"); |
607 | 0 | } else { |
608 | 0 | makeCommand.Add(cmStrCat("-j", jobs)); |
609 | 0 | } |
610 | | |
611 | | // Group each recipe's output so parallel jobs do not interleave. Only |
612 | | // done when CMake is the one passing the parallel flag to make; a native |
613 | | // `-- -j` leaves jobs unset and thus opts out. Grouping requires GNU |
614 | | // Make 4.0+ (its --output-sync); IsGNUMakeJobServerAware() excludes |
615 | | // non-GNU makes such as JOM before the version probe runs. Emitted |
616 | | // before the user's make options so a native `-- -O<mode>` overrides it. |
617 | 0 | if (this->IsGNUMakeJobServerAware() && |
618 | 0 | this->MakeSupportsOutputSync(makeProgram)) { |
619 | 0 | makeCommand.Add("-Otarget"); |
620 | | // Set the (empty by default) USES_TERMINAL recipe prefix to "+" so |
621 | | // GNU Make leaves those recipes unbuffered, keeping interactive |
622 | | // commands able to reach the terminal under -Otarget. |
623 | 0 | makeCommand.Add("CMAKE_USES_TERMINAL_PREFIX=+"); |
624 | 0 | } |
625 | 0 | } |
626 | |
|
627 | 0 | makeCommand.Add(makeOptions.begin(), makeOptions.end()); |
628 | 0 | for (auto tname : targetNames) { |
629 | 0 | if (!tname.empty()) { |
630 | 0 | if (buildOptions.Fast) { |
631 | 0 | tname += "/fast"; |
632 | 0 | } |
633 | 0 | cmSystemTools::ConvertToOutputSlashes(tname); |
634 | 0 | makeCommand.Add(std::move(tname)); |
635 | 0 | } |
636 | 0 | } |
637 | 0 | return { std::move(makeCommand) }; |
638 | 0 | } |
639 | | |
640 | | bool cmGlobalUnixMakefileGenerator3::MakeSupportsOutputSync( |
641 | | std::string const& makeProgram) |
642 | 0 | { |
643 | 0 | if (this->OutputSyncSupportState == OutputSyncSupport::Unknown) { |
644 | | // Any probe failure (spawn error, timeout, non-GNU or old make) leaves |
645 | | // grouping off; it is a convenience and must never fail the build. |
646 | 0 | this->OutputSyncSupportState = OutputSyncSupport::No; |
647 | |
|
648 | 0 | std::string version; |
649 | 0 | std::string error; |
650 | 0 | int retVal = 1; |
651 | 0 | std::vector<std::string> command{ this->SelectMakeProgram(makeProgram), |
652 | 0 | "--version" }; |
653 | 0 | if (cmSystemTools::RunSingleCommand(command, &version, &error, &retVal, |
654 | 0 | nullptr, cmSystemTools::OUTPUT_NONE, |
655 | 0 | cmDuration(30)) && |
656 | 0 | retVal == 0) { |
657 | | // GNU Make's version line is not localized, so no LC_ALL=C is needed. |
658 | 0 | cmsys::RegularExpression versionRegex("GNU Make ([0-9]+(\\.[0-9]+)*)"); |
659 | 0 | if (versionRegex.find(version) && |
660 | 0 | !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, |
661 | 0 | versionRegex.match(1), "4.0")) { |
662 | 0 | this->OutputSyncSupportState = OutputSyncSupport::Yes; |
663 | 0 | } |
664 | 0 | } |
665 | 0 | } |
666 | 0 | return this->OutputSyncSupportState == OutputSyncSupport::Yes; |
667 | 0 | } |
668 | | |
669 | | void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules( |
670 | | std::ostream& ruleFileStream, std::set<std::string>& emitted) |
671 | 0 | { |
672 | 0 | std::vector<std::string> depends; |
673 | 0 | std::vector<std::string> commands; |
674 | |
|
675 | 0 | bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION"); |
676 | 0 | if (regenerate) { |
677 | 0 | depends.emplace_back("cmake_check_build_system"); |
678 | 0 | } |
679 | | |
680 | | // write the target convenience rules |
681 | 0 | for (auto const& localGen : this->LocalGenerators) { |
682 | 0 | auto& lg = |
683 | 0 | cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(localGen); |
684 | | // for each target Generate the rule files for each target. |
685 | 0 | for (auto const& gtarget : lg.GetGeneratorTargets()) { |
686 | | // Don't emit the same rule twice (e.g. two targets with the same |
687 | | // simple name) |
688 | 0 | std::string name = gtarget->GetName(); |
689 | 0 | if (!name.empty() && emitted.insert(name).second && |
690 | | // Handle user targets here. Global targets are handled in |
691 | | // the local generator on a per-directory basis. |
692 | 0 | (gtarget->IsInBuildSystem() && |
693 | 0 | gtarget->GetType() != cm::TargetType::GLOBAL_TARGET)) { |
694 | | // Add a rule to build the target by name. |
695 | 0 | lg.WriteDivider(ruleFileStream); |
696 | 0 | ruleFileStream << "# Target rules for targets named " << name |
697 | 0 | << "\n\n"; |
698 | | |
699 | | // Write the rule. |
700 | 0 | commands.clear(); |
701 | 0 | std::string tmp = "CMakeFiles/Makefile2"; |
702 | 0 | commands.push_back(lg.GetRecursiveMakeCall(tmp, name)); |
703 | 0 | depends.clear(); |
704 | 0 | if (regenerate) { |
705 | 0 | depends.emplace_back("cmake_check_build_system"); |
706 | 0 | } |
707 | 0 | lg.WriteMakeRule(ruleFileStream, "Build rule for target.", name, |
708 | 0 | depends, commands, true); |
709 | | |
710 | | // Add a fast rule to build the target |
711 | 0 | std::string localName = lg.GetRelativeTargetDirectory(gtarget.get()); |
712 | 0 | std::string makefileName; |
713 | 0 | makefileName = cmStrCat(localName, "/build.make"); |
714 | 0 | depends.clear(); |
715 | 0 | commands.clear(); |
716 | 0 | std::string makeTargetName = cmStrCat(localName, "/build"); |
717 | 0 | localName = cmStrCat(name, "/fast"); |
718 | 0 | commands.push_back( |
719 | 0 | lg.GetRecursiveMakeCall(makefileName, makeTargetName)); |
720 | 0 | lg.WriteMakeRule(ruleFileStream, "fast build rule for target.", |
721 | 0 | localName, depends, commands, true); |
722 | | |
723 | | // Add a local name for the rule to relink the target before |
724 | | // installation. |
725 | 0 | if (gtarget->NeedRelinkBeforeInstall(lg.GetConfigName())) { |
726 | 0 | makeTargetName = cmStrCat( |
727 | 0 | lg.GetRelativeTargetDirectory(gtarget.get()), "/preinstall"); |
728 | 0 | localName = cmStrCat(name, "/preinstall"); |
729 | 0 | depends.clear(); |
730 | 0 | commands.clear(); |
731 | 0 | commands.push_back( |
732 | 0 | lg.GetRecursiveMakeCall(makefileName, makeTargetName)); |
733 | 0 | lg.WriteMakeRule(ruleFileStream, |
734 | 0 | "Manual pre-install relink rule for target.", |
735 | 0 | localName, depends, commands, true); |
736 | 0 | } |
737 | 0 | } |
738 | 0 | } |
739 | 0 | } |
740 | | |
741 | | // Forward the test_prep/ and install_prep/ convenience targets to |
742 | | // CMakeFiles/Makefile2. |
743 | 0 | this->WriteTestPrepConvenienceRules(ruleFileStream); |
744 | 0 | this->WriteInstallPrepConvenienceRules(ruleFileStream); |
745 | 0 | } |
746 | | |
747 | | void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( |
748 | | std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3& rootLG, |
749 | | cmLocalUnixMakefileGenerator3& lg) |
750 | 0 | { |
751 | 0 | std::vector<std::string> depends; |
752 | 0 | std::vector<std::string> commands; |
753 | 0 | std::string localName; |
754 | 0 | std::string makeTargetName; |
755 | |
|
756 | 0 | bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION"); |
757 | 0 | if (regenerate) { |
758 | 0 | depends.emplace_back("cmake_check_build_system"); |
759 | 0 | } |
760 | | |
761 | | // for each target Generate the rule files for each target. |
762 | 0 | for (auto const& gtarget : lg.GetGeneratorTargets()) { |
763 | 0 | std::string name = gtarget->GetName(); |
764 | 0 | if (!name.empty() && |
765 | 0 | (gtarget->IsInBuildSystem() && |
766 | 0 | gtarget->GetType() != cm::TargetType::GLOBAL_TARGET)) { |
767 | 0 | std::string makefileName; |
768 | | // Add a rule to build the target by name. |
769 | 0 | localName = lg.GetRelativeTargetDirectory(gtarget.get()); |
770 | 0 | makefileName = cmStrCat(localName, "/build.make"); |
771 | |
|
772 | 0 | lg.WriteDivider(ruleFileStream); |
773 | 0 | ruleFileStream << "# Target rules for target " << localName << "\n\n"; |
774 | |
|
775 | 0 | commands.clear(); |
776 | 0 | makeTargetName = cmStrCat(localName, "/depend"); |
777 | 0 | commands.push_back( |
778 | 0 | lg.GetRecursiveMakeCall(makefileName, makeTargetName)); |
779 | |
|
780 | 0 | makeTargetName = cmStrCat(localName, "/build"); |
781 | 0 | commands.push_back( |
782 | 0 | lg.GetRecursiveMakeCall(makefileName, makeTargetName)); |
783 | | |
784 | | // Write the rule. |
785 | 0 | localName += "/all"; |
786 | 0 | depends.clear(); |
787 | |
|
788 | 0 | cmLocalUnixMakefileGenerator3::EchoProgress progress; |
789 | 0 | progress.Dir = cmStrCat(lg.GetBinaryDirectory(), "/CMakeFiles"); |
790 | 0 | { |
791 | 0 | progress.Arg = cmJoin(this->ProgressMap[gtarget.get()].Marks, ","); |
792 | 0 | } |
793 | |
|
794 | 0 | bool targetMessages = true; |
795 | 0 | if (cmValue tgtMsg = |
796 | 0 | this->GetCMakeInstance()->GetState()->GetGlobalProperty( |
797 | 0 | "TARGET_MESSAGES")) { |
798 | 0 | targetMessages = tgtMsg.IsOn(); |
799 | 0 | } |
800 | |
|
801 | 0 | if (targetMessages) { |
802 | 0 | lg.AppendEcho(commands, "Built target " + name, |
803 | 0 | cmLocalUnixMakefileGenerator3::EchoNormal, &progress); |
804 | 0 | } |
805 | |
|
806 | 0 | this->AppendGlobalTargetDepends(depends, gtarget.get()); |
807 | 0 | rootLG.WriteMakeRule(ruleFileStream, "All Build rule for target.", |
808 | 0 | localName, depends, commands, true); |
809 | | |
810 | | // Write the rule. |
811 | 0 | commands.clear(); |
812 | |
|
813 | 0 | { |
814 | | // TODO: Convert the total progress count to a make variable. |
815 | 0 | std::set<cmGeneratorTarget const*> emitted; |
816 | 0 | commands.push_back(cmStrCat( |
817 | 0 | "$(CMAKE_COMMAND) -E cmake_progress_start ", |
818 | 0 | lg.ConvertToOutputFormat(progress.Dir, cmOutputConverter::SHELL), |
819 | 0 | ' ', this->CountProgressMarksInTarget(gtarget.get(), emitted))); |
820 | 0 | } |
821 | 0 | std::string tmp = "CMakeFiles/Makefile2"; |
822 | 0 | commands.push_back(lg.GetRecursiveMakeCall(tmp, localName)); |
823 | 0 | { |
824 | 0 | commands.push_back(cmStrCat( |
825 | 0 | "$(CMAKE_COMMAND) -E cmake_progress_start ", |
826 | 0 | lg.ConvertToOutputFormat(progress.Dir, cmOutputConverter::SHELL), |
827 | 0 | " 0")); |
828 | 0 | } |
829 | 0 | depends.clear(); |
830 | 0 | if (regenerate) { |
831 | 0 | depends.emplace_back("cmake_check_build_system"); |
832 | 0 | } |
833 | 0 | localName = |
834 | 0 | cmStrCat(lg.GetRelativeTargetDirectory(gtarget.get()), "/rule"); |
835 | 0 | rootLG.WriteMakeRule(ruleFileStream, |
836 | 0 | "Build rule for subdir invocation for target.", |
837 | 0 | localName, depends, commands, true); |
838 | | |
839 | | // Add a target with the canonical name (no prefix, suffix or path). |
840 | 0 | commands.clear(); |
841 | 0 | depends.clear(); |
842 | 0 | depends.push_back(localName); |
843 | 0 | rootLG.WriteMakeRule(ruleFileStream, "Convenience name for target.", |
844 | 0 | name, depends, commands, true); |
845 | | |
846 | | // Add rules to prepare the target for installation. |
847 | 0 | if (gtarget->NeedRelinkBeforeInstall(lg.GetConfigName())) { |
848 | 0 | localName = cmStrCat(lg.GetRelativeTargetDirectory(gtarget.get()), |
849 | 0 | "/preinstall"); |
850 | 0 | depends.clear(); |
851 | 0 | commands.clear(); |
852 | 0 | commands.push_back(lg.GetRecursiveMakeCall(makefileName, localName)); |
853 | 0 | rootLG.WriteMakeRule(ruleFileStream, |
854 | 0 | "Pre-install relink rule for target.", localName, |
855 | 0 | depends, commands, true); |
856 | 0 | } |
857 | | |
858 | | // add the codegen rule |
859 | 0 | localName = lg.GetRelativeTargetDirectory(gtarget.get()); |
860 | 0 | depends.clear(); |
861 | 0 | commands.clear(); |
862 | 0 | makeTargetName = cmStrCat(localName, "/codegen"); |
863 | 0 | commands.push_back( |
864 | 0 | lg.GetRecursiveMakeCall(makefileName, makeTargetName)); |
865 | 0 | if (targetMessages) { |
866 | 0 | lg.AppendEcho(commands, "Finished codegen for target " + name, |
867 | 0 | cmLocalUnixMakefileGenerator3::EchoNormal, &progress); |
868 | 0 | } |
869 | 0 | this->AppendCodegenTargetDepends(depends, gtarget.get()); |
870 | 0 | rootLG.WriteMakeRule(ruleFileStream, "codegen rule for target.", |
871 | 0 | makeTargetName, depends, commands, true); |
872 | | |
873 | | // add the clean rule |
874 | 0 | localName = lg.GetRelativeTargetDirectory(gtarget.get()); |
875 | 0 | makeTargetName = cmStrCat(localName, "/clean"); |
876 | 0 | depends.clear(); |
877 | 0 | commands.clear(); |
878 | 0 | commands.push_back( |
879 | 0 | lg.GetRecursiveMakeCall(makefileName, makeTargetName)); |
880 | 0 | rootLG.WriteMakeRule(ruleFileStream, "clean rule for target.", |
881 | 0 | makeTargetName, depends, commands, true); |
882 | 0 | commands.clear(); |
883 | 0 | } |
884 | 0 | } |
885 | 0 | } |
886 | | |
887 | | // Build a map that contains the set of targets used by each local |
888 | | // generator directory level. |
889 | | void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks() |
890 | 0 | { |
891 | 0 | this->DirectoryTargetsMap.clear(); |
892 | | // Loop over all targets in all local generators. |
893 | 0 | for (auto const& lg : this->LocalGenerators) { |
894 | 0 | for (auto const& gt : lg->GetGeneratorTargets()) { |
895 | 0 | if (!gt->IsInBuildSystem() || this->IsExcluded(lg.get(), gt.get())) { |
896 | 0 | continue; |
897 | 0 | } |
898 | | |
899 | 0 | cmStateSnapshot csnp = lg->GetStateSnapshot(); |
900 | | |
901 | | // Consider the directory containing the target and all its parents. |
902 | | // An excluded directory may contains non-excluded targets. |
903 | 0 | for (; csnp.IsValid(); csnp = csnp.GetBuildsystemDirectoryParent()) { |
904 | | // This local generator includes the target. |
905 | 0 | std::set<cmGeneratorTarget const*>& targetSet = |
906 | 0 | this->DirectoryTargetsMap[csnp]; |
907 | 0 | targetSet.insert(gt.get()); |
908 | | |
909 | | // Add dependencies of the included target. An excluded |
910 | | // target may still be included if it is a dependency of a |
911 | | // non-excluded target. |
912 | 0 | for (cmTargetDepend const& tgtdep : |
913 | 0 | this->GetTargetDirectDepends(gt.get())) { |
914 | 0 | targetSet.insert(tgtdep); |
915 | 0 | } |
916 | 0 | } |
917 | 0 | } |
918 | 0 | } |
919 | 0 | } |
920 | | |
921 | | size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInTarget( |
922 | | cmGeneratorTarget const* target, std::set<cmGeneratorTarget const*>& emitted) |
923 | 0 | { |
924 | 0 | size_t count = 0; |
925 | 0 | if (emitted.insert(target).second) { |
926 | 0 | count = this->ProgressMap[target].Marks.size(); |
927 | 0 | for (cmTargetDepend const& depend : this->GetTargetDirectDepends(target)) { |
928 | 0 | if (!depend->IsInBuildSystem()) { |
929 | 0 | continue; |
930 | 0 | } |
931 | 0 | count += this->CountProgressMarksInTarget(depend, emitted); |
932 | 0 | } |
933 | 0 | } |
934 | 0 | return count; |
935 | 0 | } |
936 | | |
937 | | size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInAll( |
938 | | cmLocalGenerator const& lg) |
939 | 0 | { |
940 | 0 | size_t count = 0; |
941 | 0 | std::set<cmGeneratorTarget const*> emitted; |
942 | 0 | for (cmGeneratorTarget const* target : |
943 | 0 | this->DirectoryTargetsMap[lg.GetStateSnapshot()]) { |
944 | 0 | if (!this->IsExcluded(&lg, target)) { |
945 | 0 | count += this->CountProgressMarksInTarget(target, emitted); |
946 | 0 | } |
947 | 0 | } |
948 | 0 | return count; |
949 | 0 | } |
950 | | |
951 | | void cmGlobalUnixMakefileGenerator3::RecordTargetProgress( |
952 | | cmMakefileTargetGenerator* tg) |
953 | 0 | { |
954 | 0 | TargetProgress& tp = this->ProgressMap[tg->GetGeneratorTarget()]; |
955 | 0 | tp.NumberOfActions = tg->GetNumberOfProgressActions(); |
956 | 0 | tp.VariableFile = tg->GetProgressFileNameFull(); |
957 | 0 | } |
958 | | |
959 | | void cmGlobalUnixMakefileGenerator3::TargetProgress::WriteProgressVariables( |
960 | | unsigned long total, unsigned long& current) |
961 | 0 | { |
962 | 0 | cmGeneratedFileStream fout(this->VariableFile); |
963 | 0 | for (unsigned long i = 1; i <= this->NumberOfActions; ++i) { |
964 | 0 | fout << "CMAKE_PROGRESS_" << i << " = "; |
965 | 0 | if (total <= 100) { |
966 | 0 | unsigned long num = i + current; |
967 | 0 | fout << num; |
968 | 0 | this->Marks.push_back(num); |
969 | 0 | } else if (((i + current) * 100) / total > |
970 | 0 | ((i - 1 + current) * 100) / total) { |
971 | 0 | unsigned long num = ((i + current) * 100) / total; |
972 | 0 | fout << num; |
973 | 0 | this->Marks.push_back(num); |
974 | 0 | } |
975 | 0 | fout << "\n"; |
976 | 0 | } |
977 | 0 | fout << "\n"; |
978 | 0 | current += this->NumberOfActions; |
979 | 0 | } |
980 | | |
981 | | void cmGlobalUnixMakefileGenerator3::AppendGlobalTargetDepends( |
982 | | std::vector<std::string>& depends, cmGeneratorTarget* target) |
983 | 0 | { |
984 | 0 | for (cmTargetDepend const& i : this->GetTargetDirectDepends(target)) { |
985 | | // Create the target-level dependency. |
986 | 0 | cmGeneratorTarget const* dep = i; |
987 | 0 | if (!dep->IsInBuildSystem()) { |
988 | 0 | continue; |
989 | 0 | } |
990 | 0 | cmLocalUnixMakefileGenerator3* lg3 = |
991 | 0 | static_cast<cmLocalUnixMakefileGenerator3*>(dep->GetLocalGenerator()); |
992 | 0 | std::string tgtName = cmStrCat( |
993 | 0 | lg3->GetRelativeTargetDirectory(const_cast<cmGeneratorTarget*>(dep)), |
994 | 0 | "/all"); |
995 | 0 | depends.push_back(tgtName); |
996 | 0 | } |
997 | 0 | } |
998 | | |
999 | | void cmGlobalUnixMakefileGenerator3::AppendCodegenTargetDepends( |
1000 | | std::vector<std::string>& depends, cmGeneratorTarget* target) |
1001 | 0 | { |
1002 | 0 | std::set<std::string> const& codegen_depends = |
1003 | 0 | target->Target->GetCodegenDeps(); |
1004 | |
|
1005 | 0 | bool hasCodegenCommands = false; |
1006 | 0 | { |
1007 | 0 | std::vector<cmSourceFile const*> customCommands; |
1008 | 0 | cmLocalUnixMakefileGenerator3* lg3 = |
1009 | 0 | static_cast<cmLocalUnixMakefileGenerator3*>(target->GetLocalGenerator()); |
1010 | 0 | target->GetCustomCommands(customCommands, lg3->GetConfigName()); |
1011 | 0 | hasCodegenCommands = |
1012 | 0 | std::any_of(customCommands.begin(), customCommands.end(), |
1013 | 0 | [](cmSourceFile const* sf) { |
1014 | 0 | return sf->GetCustomCommand()->GetCodegen(); |
1015 | 0 | }); |
1016 | 0 | } |
1017 | |
|
1018 | 0 | for (cmTargetDepend const& i : this->GetTargetDirectDepends(target)) { |
1019 | | // Create the target-level dependency. |
1020 | 0 | cmGeneratorTarget const* dep = i; |
1021 | 0 | if (!dep->IsInBuildSystem()) { |
1022 | 0 | continue; |
1023 | 0 | } |
1024 | 0 | if (codegen_depends.find(dep->GetName()) != codegen_depends.end()) { |
1025 | 0 | cmLocalUnixMakefileGenerator3* lg3 = |
1026 | 0 | static_cast<cmLocalUnixMakefileGenerator3*>(dep->GetLocalGenerator()); |
1027 | 0 | std::string const tgtDir = |
1028 | 0 | lg3->GetRelativeTargetDirectory(const_cast<cmGeneratorTarget*>(dep)); |
1029 | 0 | depends.push_back(cmStrCat(tgtDir, "/codegen")); |
1030 | 0 | if (hasCodegenCommands) { |
1031 | 0 | depends.push_back(cmStrCat(tgtDir, "/all")); |
1032 | 0 | } |
1033 | 0 | } |
1034 | 0 | } |
1035 | 0 | } |
1036 | | |
1037 | | void cmGlobalUnixMakefileGenerator3::ComputeTestPrepTargets() |
1038 | 0 | { |
1039 | 0 | this->TestPrepTargets.clear(); |
1040 | 0 | this->TestPrepEnabled = false; |
1041 | 0 | if (this->Makefiles.empty() || |
1042 | 0 | this->Makefiles.front()->IsOn("CMAKE_SKIP_TEST_PREP_TARGETS")) { |
1043 | 0 | return; |
1044 | 0 | } |
1045 | 0 | this->TestPrepEnabled = true; |
1046 | | |
1047 | | // Map a generator target to its "<target>.dir/all" recursive rule. |
1048 | 0 | auto targetAllRule = [](cmGeneratorTarget* gt) -> std::string { |
1049 | 0 | auto* lg3 = |
1050 | 0 | static_cast<cmLocalUnixMakefileGenerator3*>(gt->GetLocalGenerator()); |
1051 | 0 | return cmStrCat(lg3->GetRelativeTargetDirectory(gt), "/all"); |
1052 | 0 | }; |
1053 | | |
1054 | | // Collect the dependencies of each test, merging tests that share a name |
1055 | | // across directories (as the Ninja generator does). |
1056 | 0 | for (auto const& lg : this->LocalGenerators) { |
1057 | 0 | for (auto const& tester : lg->GetMakefile()->GetTestGenerators()) { |
1058 | 0 | cmTestGenerator::BuildDependencies deps; |
1059 | 0 | if (!tester->GetBuildDependencies(lg.get(), std::string(), deps)) { |
1060 | 0 | continue; |
1061 | 0 | } |
1062 | 0 | cmTest* test = tester->GetTest(); |
1063 | 0 | std::string const& testName = test->GetName(); |
1064 | | |
1065 | | // A Makefile target name cannot contain ':'. Such a name is valid for |
1066 | | // add_test() (e.g. a namespaced name) and works with the Ninja |
1067 | | // generator, but cannot be expressed as a Makefile rule. |
1068 | 0 | if (testName.find(':') != std::string::npos) { |
1069 | 0 | test->GetMakefile()->IssueMessage( |
1070 | 0 | MessageType::WARNING, |
1071 | 0 | cmStrCat("Test \"", testName, |
1072 | 0 | "\" has a name containing ':', which cannot be used as a " |
1073 | 0 | "Makefile build target. No \"test_prep/\" target will be " |
1074 | 0 | "generated for it. Use the Ninja generator or rename the " |
1075 | 0 | "test to build its dependencies with a \"test_prep/\" " |
1076 | 0 | "target."), |
1077 | 0 | test->GetBacktrace()); |
1078 | 0 | continue; |
1079 | 0 | } |
1080 | | |
1081 | 0 | std::vector<std::string>& rules = |
1082 | 0 | this->GetTestPrepTarget(cmStrCat("test_prep/", testName)).Rules; |
1083 | | |
1084 | | // Target dependencies are filtered to build-system targets by |
1085 | | // GetBuildDependencies. |
1086 | 0 | for (cmGeneratorTarget* dep : deps.Targets) { |
1087 | 0 | rules.push_back(targetAllRule(dep)); |
1088 | 0 | } |
1089 | |
|
1090 | 0 | for (cmTestGenerator::BuildDependencies::FileDependency const& file : |
1091 | 0 | deps.Files) { |
1092 | 0 | if (cmGeneratorTarget* owner = file.Owner |
1093 | 0 | ? file.Owner |
1094 | 0 | : this->FindOutputOwningTarget(file.Path)) { |
1095 | | // The file is the primary output of one build-system target; build |
1096 | | // that target to produce the file. |
1097 | 0 | rules.push_back(targetAllRule(owner)); |
1098 | 0 | } else if (file.Generated) { |
1099 | | // The file is generated but cannot be attributed to a single owning |
1100 | | // target (e.g. a byproduct or an ambiguous/shared output), so the |
1101 | | // recursive Makefile graph cannot build it from a top-level rule. |
1102 | 0 | test->GetMakefile()->IssueMessage( |
1103 | 0 | MessageType::WARNING, |
1104 | 0 | cmStrCat("Test \"", testName, "\" BUILD_DEPENDS file\n ", |
1105 | 0 | file.Path, |
1106 | 0 | "\nis generated but is not the unique output of a build " |
1107 | 0 | "target, so the \"test_prep/", |
1108 | 0 | testName, |
1109 | 0 | "\" target cannot build it with this generator. Depend " |
1110 | 0 | "on the target that produces it (for example one created " |
1111 | 0 | "with add_custom_target) instead."), |
1112 | 0 | test->GetBacktrace()); |
1113 | 0 | } |
1114 | | // Otherwise the file is not generated by the build (e.g. a source |
1115 | | // file that already exists) and needs no build rule. |
1116 | 0 | } |
1117 | 0 | } |
1118 | |
|
1119 | 0 | this->AddDirectoryTestPrepTargets(lg.get()); |
1120 | 0 | } |
1121 | | |
1122 | | // Sort and de-duplicate each rule list (as the Ninja generator does). |
1123 | 0 | for (auto& entry : this->TestPrepTargets) { |
1124 | 0 | std::vector<std::string>& rules = entry.second.Rules; |
1125 | 0 | std::sort(rules.begin(), rules.end()); |
1126 | 0 | rules.erase(std::unique(rules.begin(), rules.end()), rules.end()); |
1127 | 0 | } |
1128 | 0 | } |
1129 | | |
1130 | | cmGlobalUnixMakefileGenerator3::TestPrepTarget& |
1131 | | cmGlobalUnixMakefileGenerator3::GetTestPrepTarget(std::string const& name) |
1132 | 0 | { |
1133 | | // Merge targets whose names differ only in case where the make tool does |
1134 | | // not distinguish them. Keep the first spelling for the user-facing name. |
1135 | 0 | TestPrepTarget& testPrepTarget = |
1136 | 0 | this->TestPrepTargets[this->TargetNamesAreCaseInsensitive() |
1137 | 0 | ? cmSystemTools::LowerCase(name) |
1138 | 0 | : name]; |
1139 | 0 | if (testPrepTarget.Name.empty()) { |
1140 | 0 | testPrepTarget.Name = name; |
1141 | 0 | } |
1142 | 0 | return testPrepTarget; |
1143 | 0 | } |
1144 | | |
1145 | | void cmGlobalUnixMakefileGenerator3::AddDirectoryTestPrepTargets( |
1146 | | cmLocalGenerator* lg) |
1147 | 0 | { |
1148 | 0 | cmLocalGenerator::DirectoryTestPrepTarget directoryTarget; |
1149 | 0 | if (!lg->GetDirectoryTestPrepTarget( |
1150 | 0 | directoryTarget, |
1151 | 0 | lg->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"))) { |
1152 | 0 | return; |
1153 | 0 | } |
1154 | | |
1155 | 0 | std::vector<std::string>& rules = |
1156 | 0 | this->GetTestPrepTarget(directoryTarget.Name).Rules; |
1157 | |
|
1158 | 0 | for (cmLocalGenerator::DirectoryTestPrepDependency const& dep : |
1159 | 0 | directoryTarget.Dependencies) { |
1160 | 0 | cmGeneratorTarget* target = dep.Target ? dep.Target : dep.Owner; |
1161 | 0 | if (!target) { |
1162 | 0 | target = this->FindOutputOwningTarget(dep.Raw); |
1163 | 0 | } |
1164 | 0 | if (target) { |
1165 | 0 | auto* lg3 = static_cast<cmLocalUnixMakefileGenerator3*>( |
1166 | 0 | target->GetLocalGenerator()); |
1167 | 0 | rules.push_back( |
1168 | 0 | cmStrCat(lg3->GetRelativeTargetDirectory(target), "/all")); |
1169 | 0 | } else if (dep.Generated) { |
1170 | 0 | lg->GetMakefile()->IssueMessage( |
1171 | 0 | MessageType::WARNING, |
1172 | 0 | cmStrCat("Directory test prep dependency\n ", dep.Raw, |
1173 | 0 | "\nis generated but is not the unique output of a build " |
1174 | 0 | "target, so the \"", |
1175 | 0 | directoryTarget.Name, |
1176 | 0 | "\" target cannot build it with this generator. Depend " |
1177 | 0 | "on the target that produces it (for example one created " |
1178 | 0 | "with add_custom_target) instead."), |
1179 | 0 | lg->GetMakefile()->GetBacktrace()); |
1180 | 0 | } |
1181 | 0 | } |
1182 | 0 | } |
1183 | | |
1184 | | void cmGlobalUnixMakefileGenerator3::WriteTestPrepRules( |
1185 | | std::ostream& makefileStream, cmLocalUnixMakefileGenerator3& rootLG) |
1186 | 0 | { |
1187 | 0 | if (!this->TestPrepEnabled) { |
1188 | 0 | return; |
1189 | 0 | } |
1190 | | |
1191 | 0 | rootLG.WriteDivider(makefileStream); |
1192 | 0 | makefileStream << "# Targets to build the dependencies of tests.\n\n"; |
1193 | |
|
1194 | 0 | std::vector<std::string> no_commands; |
1195 | 0 | std::vector<std::string> allDeps; |
1196 | 0 | for (auto const& entry : this->TestPrepTargets) { |
1197 | | // A test whose target name matches "test_prep/all" is prepared by the |
1198 | | // rule for all tests. |
1199 | 0 | if (entry.first == "test_prep/all") { |
1200 | 0 | cm::append(allDeps, entry.second.Rules); |
1201 | 0 | continue; |
1202 | 0 | } |
1203 | 0 | std::vector<std::string> depends = entry.second.Rules; |
1204 | 0 | if (depends.empty() && !this->EmptyRuleHackDepends.empty()) { |
1205 | 0 | depends.push_back(this->EmptyRuleHackDepends); |
1206 | 0 | } |
1207 | 0 | rootLG.WriteMakeRule(makefileStream, "Build the dependencies of a test.", |
1208 | 0 | entry.second.Name, depends, no_commands, true); |
1209 | 0 | allDeps.push_back(entry.second.Name); |
1210 | 0 | } |
1211 | |
|
1212 | 0 | if (allDeps.empty() && !this->EmptyRuleHackDepends.empty()) { |
1213 | 0 | allDeps.push_back(this->EmptyRuleHackDepends); |
1214 | 0 | } |
1215 | 0 | rootLG.WriteMakeRule(makefileStream, "Build the dependencies of all tests.", |
1216 | 0 | "test_prep/all", allDeps, no_commands, true); |
1217 | 0 | } |
1218 | | |
1219 | | void cmGlobalUnixMakefileGenerator3::WriteTestPrepConvenienceRules( |
1220 | | std::ostream& ruleFileStream) |
1221 | 0 | { |
1222 | 0 | if (!this->TestPrepEnabled) { |
1223 | 0 | return; |
1224 | 0 | } |
1225 | | |
1226 | 0 | auto& lg = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>( |
1227 | 0 | this->LocalGenerators[0]); |
1228 | |
|
1229 | 0 | bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION"); |
1230 | 0 | std::string const makefile2 = "CMakeFiles/Makefile2"; |
1231 | |
|
1232 | 0 | std::vector<std::string> depends; |
1233 | 0 | std::vector<std::string> commands; |
1234 | |
|
1235 | 0 | lg.WriteDivider(ruleFileStream); |
1236 | 0 | ruleFileStream << "# Convenience rules to build test dependencies.\n\n"; |
1237 | |
|
1238 | 0 | for (auto const& entry : this->TestPrepTargets) { |
1239 | | // The "test_prep/all" rule is written below. |
1240 | 0 | if (entry.first == "test_prep/all") { |
1241 | 0 | continue; |
1242 | 0 | } |
1243 | 0 | depends.clear(); |
1244 | 0 | if (regenerate) { |
1245 | 0 | depends.emplace_back("cmake_check_build_system"); |
1246 | 0 | } |
1247 | 0 | commands.clear(); |
1248 | 0 | commands.push_back(lg.GetRecursiveMakeCall(makefile2, entry.second.Name)); |
1249 | 0 | lg.WriteMakeRule(ruleFileStream, "Build the dependencies of a test.", |
1250 | 0 | entry.second.Name, depends, commands, true); |
1251 | 0 | } |
1252 | |
|
1253 | 0 | depends.clear(); |
1254 | 0 | if (regenerate) { |
1255 | 0 | depends.emplace_back("cmake_check_build_system"); |
1256 | 0 | } |
1257 | 0 | commands.clear(); |
1258 | 0 | commands.push_back(lg.GetRecursiveMakeCall(makefile2, "test_prep/all")); |
1259 | 0 | lg.WriteMakeRule(ruleFileStream, "Build the dependencies of a test.", |
1260 | 0 | "test_prep/all", depends, commands, true); |
1261 | 0 | } |
1262 | | |
1263 | | void cmGlobalUnixMakefileGenerator3::ComputeInstallPrepTargets() |
1264 | 0 | { |
1265 | 0 | this->InstallPrepComponentTargets.clear(); |
1266 | 0 | this->InstallPrepAllTargets.clear(); |
1267 | 0 | this->InstallPrepOrderedTargets.clear(); |
1268 | 0 | this->InstallPrepEnabled = false; |
1269 | 0 | if (!this->AreInstallPrepTargetsEnabled()) { |
1270 | 0 | return; |
1271 | 0 | } |
1272 | 0 | this->InstallPrepEnabled = true; |
1273 | 0 | this->CheckInstallPrepTargets(); |
1274 | |
|
1275 | 0 | auto const& rootLG = |
1276 | 0 | cm::static_reference_cast<cmLocalUnixMakefileGenerator3>( |
1277 | 0 | this->LocalGenerators.front()); |
1278 | 0 | std::string const config = rootLG.GetConfigName(); |
1279 | 0 | InstallPrepTargets const prep = this->GetInstallPrepTargets(config); |
1280 | |
|
1281 | 0 | std::set<std::string> unownedGeneratedFiles; |
1282 | 0 | auto appendTargetRules = |
1283 | 0 | [this, &config, &unownedGeneratedFiles]( |
1284 | 0 | std::vector<std::string>& rules, cmGeneratorTarget const* gt, |
1285 | 0 | InstallPrepTargets::TargetRequirements requirements) { |
1286 | 0 | auto* lg3 = |
1287 | 0 | static_cast<cmLocalUnixMakefileGenerator3*>(gt->GetLocalGenerator()); |
1288 | 0 | std::string const targetDirectory = lg3->GetRelativeTargetDirectory(gt); |
1289 | 0 | bool const needsRelink = gt->NeedRelinkBeforeInstall(config); |
1290 | 0 | if (requirements.InstallArtifact && needsRelink) { |
1291 | 0 | std::string const orderedRule = |
1292 | 0 | cmStrCat(targetDirectory, "/install_prep"); |
1293 | 0 | this->InstallPrepOrderedTargets[orderedRule] = { |
1294 | 0 | cmStrCat(targetDirectory, "/all"), |
1295 | 0 | cmStrCat(targetDirectory, "/preinstall") |
1296 | 0 | }; |
1297 | 0 | rules.push_back(orderedRule); |
1298 | 0 | return; |
1299 | 0 | } |
1300 | | // A top-level rule cannot build an individual custom command output, so |
1301 | | // build the whole target that owns it. A generated file that is not |
1302 | | // the unique output of a target is attributed to its installing target. |
1303 | 0 | for (std::string const& file : requirements.GeneratedFiles) { |
1304 | 0 | this->CheckInstallPrepGeneratedFile(gt, file, unownedGeneratedFiles); |
1305 | 0 | } |
1306 | 0 | if (requirements.Normal || |
1307 | 0 | (!requirements.GeneratedFiles.empty() && gt->IsInBuildSystem())) { |
1308 | 0 | rules.push_back(cmStrCat(targetDirectory, "/all")); |
1309 | 0 | } |
1310 | 0 | if (requirements.InstallArtifact) { |
1311 | 0 | rules.push_back( |
1312 | 0 | cmStrCat(targetDirectory, needsRelink ? "/preinstall" : "/all")); |
1313 | 0 | } |
1314 | 0 | }; |
1315 | |
|
1316 | 0 | for (auto const& target : prep.All) { |
1317 | 0 | appendTargetRules(this->InstallPrepAllTargets, target.first, |
1318 | 0 | target.second); |
1319 | 0 | } |
1320 | |
|
1321 | 0 | for (auto const& entry : prep.Components) { |
1322 | 0 | std::string const name = cmStrCat("install_prep/", entry.first); |
1323 | | // Merge targets whose names differ only in case where the make tool does |
1324 | | // not distinguish them, as for "test_prep/" targets. Each of them then |
1325 | | // prepares a superset of what its installation needs. Components are |
1326 | | // visited in order, so the first spelling names the target. |
1327 | 0 | std::string const key = this->TargetNamesAreCaseInsensitive() |
1328 | 0 | ? cmSystemTools::LowerCase(name) |
1329 | 0 | : name; |
1330 | 0 | std::vector<std::string>* rules = &this->InstallPrepAllTargets; |
1331 | 0 | if (key != "install_prep/all") { |
1332 | 0 | InstallPrepTarget& prepTarget = this->InstallPrepComponentTargets[key]; |
1333 | 0 | if (prepTarget.Name.empty()) { |
1334 | 0 | prepTarget.Name = name; |
1335 | 0 | } |
1336 | 0 | rules = &prepTarget.Rules; |
1337 | 0 | } |
1338 | 0 | for (auto const& target : entry.second) { |
1339 | 0 | appendTargetRules(*rules, target.first, target.second); |
1340 | 0 | } |
1341 | 0 | } |
1342 | |
|
1343 | 0 | auto sortAndRemoveDuplicates = [](std::vector<std::string>& rules) { |
1344 | 0 | std::sort(rules.begin(), rules.end()); |
1345 | 0 | rules.erase(std::unique(rules.begin(), rules.end()), rules.end()); |
1346 | 0 | }; |
1347 | 0 | sortAndRemoveDuplicates(this->InstallPrepAllTargets); |
1348 | 0 | for (auto& entry : this->InstallPrepComponentTargets) { |
1349 | 0 | sortAndRemoveDuplicates(entry.second.Rules); |
1350 | 0 | } |
1351 | 0 | } |
1352 | | |
1353 | | void cmGlobalUnixMakefileGenerator3::WriteInstallPrepRules( |
1354 | | std::ostream& makefileStream, cmLocalUnixMakefileGenerator3& rootLG) |
1355 | 0 | { |
1356 | 0 | if (!this->InstallPrepEnabled) { |
1357 | 0 | return; |
1358 | 0 | } |
1359 | | |
1360 | 0 | std::vector<std::string> noCommands; |
1361 | 0 | std::string const makefile2 = "CMakeFiles/Makefile2"; |
1362 | 0 | for (auto const& ordered : this->InstallPrepOrderedTargets) { |
1363 | 0 | std::vector<std::string> depends{ ordered.second.NormalRule }; |
1364 | 0 | std::vector<std::string> commands{ rootLG.GetRecursiveMakeCall( |
1365 | 0 | makefile2, ordered.second.PreinstallRule) }; |
1366 | 0 | rootLG.WriteMakeRule(makefileStream, nullptr, ordered.first, depends, |
1367 | 0 | commands, true); |
1368 | 0 | } |
1369 | |
|
1370 | 0 | for (auto const& entry : this->InstallPrepComponentTargets) { |
1371 | 0 | std::vector<std::string> depends = entry.second.Rules; |
1372 | 0 | if (depends.empty() && !this->EmptyRuleHackDepends.empty()) { |
1373 | 0 | depends.push_back(this->EmptyRuleHackDepends); |
1374 | 0 | } |
1375 | 0 | rootLG.WriteMakeRule(makefileStream, nullptr, entry.second.Name, depends, |
1376 | 0 | noCommands, true); |
1377 | 0 | } |
1378 | |
|
1379 | 0 | std::vector<std::string> allDepends = this->InstallPrepAllTargets; |
1380 | 0 | if (allDepends.empty() && !this->EmptyRuleHackDepends.empty()) { |
1381 | 0 | allDepends.push_back(this->EmptyRuleHackDepends); |
1382 | 0 | } |
1383 | 0 | rootLG.WriteMakeRule(makefileStream, nullptr, "install_prep/all", allDepends, |
1384 | 0 | noCommands, true); |
1385 | 0 | } |
1386 | | |
1387 | | void cmGlobalUnixMakefileGenerator3::WriteInstallPrepConvenienceRules( |
1388 | | std::ostream& ruleFileStream) |
1389 | 0 | { |
1390 | 0 | if (!this->InstallPrepEnabled) { |
1391 | 0 | return; |
1392 | 0 | } |
1393 | | |
1394 | 0 | auto& lg = cm::static_reference_cast<cmLocalUnixMakefileGenerator3>( |
1395 | 0 | this->LocalGenerators[0]); |
1396 | |
|
1397 | 0 | bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION"); |
1398 | 0 | std::string const makefile2 = "CMakeFiles/Makefile2"; |
1399 | |
|
1400 | 0 | std::vector<std::string> depends; |
1401 | 0 | std::vector<std::string> commands; |
1402 | 0 | auto writeForward = [&](std::string const& prepName) { |
1403 | 0 | depends.clear(); |
1404 | 0 | if (regenerate) { |
1405 | 0 | depends.emplace_back("cmake_check_build_system"); |
1406 | 0 | } |
1407 | 0 | commands.clear(); |
1408 | 0 | commands.push_back(lg.GetRecursiveMakeCall(makefile2, prepName)); |
1409 | 0 | lg.WriteMakeRule(ruleFileStream, nullptr, prepName, depends, commands, |
1410 | 0 | true); |
1411 | 0 | }; |
1412 | |
|
1413 | 0 | for (auto const& entry : this->InstallPrepComponentTargets) { |
1414 | 0 | writeForward(entry.second.Name); |
1415 | 0 | } |
1416 | 0 | writeForward("install_prep/all"); |
1417 | 0 | } |
1418 | | |
1419 | | void cmGlobalUnixMakefileGenerator3::WriteHelpRule( |
1420 | | std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg) |
1421 | 0 | { |
1422 | | // add the help target |
1423 | 0 | std::string path; |
1424 | 0 | std::vector<std::string> no_depends; |
1425 | 0 | std::vector<std::string> commands; |
1426 | 0 | lg->AppendEcho(commands, |
1427 | 0 | "The following are some of the valid targets " |
1428 | 0 | "for this Makefile:"); |
1429 | 0 | lg->AppendEcho(commands, "... all (the default if no target is provided)"); |
1430 | 0 | lg->AppendEcho(commands, "... clean"); |
1431 | 0 | if (!this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) { |
1432 | 0 | lg->AppendEcho(commands, "... depend"); |
1433 | 0 | } |
1434 | 0 | if (this->CheckCMP0171()) { |
1435 | 0 | lg->AppendEcho(commands, "... codegen"); |
1436 | 0 | } |
1437 | | |
1438 | | // Keep track of targets already listed. |
1439 | 0 | std::set<std::string> emittedTargets; |
1440 | 0 | std::set<std::string> utility_targets; |
1441 | 0 | std::set<std::string> globals_targets; |
1442 | 0 | std::set<std::string> project_targets; |
1443 | | |
1444 | | // for each local generator |
1445 | 0 | for (auto const& localGen : this->LocalGenerators) { |
1446 | 0 | auto const& lg2 = |
1447 | 0 | cm::static_reference_cast<cmLocalUnixMakefileGenerator3>(localGen); |
1448 | | // for the passed in makefile or if this is the top Makefile wripte out |
1449 | | // the targets |
1450 | 0 | if (&lg2 == lg || lg->IsRootMakefile()) { |
1451 | | // for each target Generate the rule files for each target. |
1452 | 0 | for (auto const& target : lg2.GetGeneratorTargets()) { |
1453 | 0 | cm::TargetType type = target->GetType(); |
1454 | 0 | if ((type == cm::TargetType::EXECUTABLE) || |
1455 | 0 | (type == cm::TargetType::STATIC_LIBRARY) || |
1456 | 0 | (type == cm::TargetType::SHARED_LIBRARY) || |
1457 | 0 | (type == cm::TargetType::MODULE_LIBRARY) || |
1458 | 0 | (type == cm::TargetType::OBJECT_LIBRARY) || |
1459 | 0 | (type == cm::TargetType::INTERFACE_LIBRARY && |
1460 | 0 | target->IsInBuildSystem())) { |
1461 | 0 | project_targets.insert(target->GetName()); |
1462 | 0 | } else if (type == cm::TargetType::GLOBAL_TARGET) { |
1463 | 0 | globals_targets.insert(target->GetName()); |
1464 | 0 | } else if (type == cm::TargetType::UTILITY) { |
1465 | 0 | utility_targets.insert(target->GetName()); |
1466 | 0 | } |
1467 | 0 | } |
1468 | 0 | } |
1469 | 0 | } |
1470 | |
|
1471 | 0 | for (std::string const& name : globals_targets) { |
1472 | 0 | path = cmStrCat("... ", name); |
1473 | 0 | lg->AppendEcho(commands, path); |
1474 | 0 | } |
1475 | 0 | for (std::string const& name : utility_targets) { |
1476 | 0 | path = cmStrCat("... ", name); |
1477 | 0 | lg->AppendEcho(commands, path); |
1478 | 0 | } |
1479 | 0 | for (std::string const& name : project_targets) { |
1480 | 0 | path = cmStrCat("... ", name); |
1481 | 0 | lg->AppendEcho(commands, path); |
1482 | 0 | } |
1483 | |
|
1484 | 0 | for (std::string const& o : lg->GetLocalHelp()) { |
1485 | 0 | path = cmStrCat("... ", o); |
1486 | 0 | lg->AppendEcho(commands, path); |
1487 | 0 | } |
1488 | 0 | lg->WriteMakeRule(ruleFileStream, "Help Target", "help", no_depends, |
1489 | 0 | commands, true); |
1490 | 0 | ruleFileStream << "\n\n"; |
1491 | 0 | } |