cmGlobalNinjaGenerator.cxx 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2011 Peter Collingbourne <[email protected]>
  4. Copyright 2011 Nicolas Despres <[email protected]>
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. #include "cmGeneratedFileStream.h"
  12. #include "cmGeneratorExpressionEvaluationFile.h"
  13. #include "cmGeneratorTarget.h"
  14. #include "cmGlobalNinjaGenerator.h"
  15. #include "cmLocalNinjaGenerator.h"
  16. #include "cmMakefile.h"
  17. #include "cmVersion.h"
  18. #include "cmAlgorithms.h"
  19. #include <algorithm>
  20. #include <assert.h>
  21. const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
  22. const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja";
  23. const char* cmGlobalNinjaGenerator::INDENT = " ";
  24. void cmGlobalNinjaGenerator::Indent(std::ostream& os, int count)
  25. {
  26. for(int i = 0; i < count; ++i)
  27. os << cmGlobalNinjaGenerator::INDENT;
  28. }
  29. void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os)
  30. {
  31. os
  32. << "# ======================================"
  33. << "=======================================\n";
  34. }
  35. void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
  36. const std::string& comment)
  37. {
  38. if (comment.empty())
  39. return;
  40. std::string replace = comment;
  41. std::string::size_type lpos = 0;
  42. std::string::size_type rpos;
  43. os << "\n#############################################\n";
  44. while((rpos = replace.find('\n', lpos)) != std::string::npos)
  45. {
  46. os << "# " << replace.substr(lpos, rpos - lpos) << "\n";
  47. lpos = rpos + 1;
  48. }
  49. os << "# " << replace.substr(lpos) << "\n\n";
  50. }
  51. static bool IsIdentChar(char c)
  52. {
  53. return
  54. ('a' <= c && c <= 'z') ||
  55. ('+' <= c && c <= '9') || // +,-./ and numbers
  56. ('A' <= c && c <= 'Z') ||
  57. (c == '_') || (c == '$') || (c == '\\') ||
  58. (c == ' ') || (c == ':');
  59. }
  60. std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident,
  61. std::ostream &vars) {
  62. if (std::find_if(ident.begin(), ident.end(),
  63. std::not1(std::ptr_fun(IsIdentChar))) != ident.end()) {
  64. static unsigned VarNum = 0;
  65. std::ostringstream names;
  66. names << "ident" << VarNum++;
  67. vars << names.str() << " = " << ident << "\n";
  68. return "$" + names.str();
  69. } else {
  70. std::string result = ident;
  71. cmSystemTools::ReplaceString(result, " ", "$ ");
  72. cmSystemTools::ReplaceString(result, ":", "$:");
  73. return result;
  74. }
  75. }
  76. std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit)
  77. {
  78. std::string result = lit;
  79. cmSystemTools::ReplaceString(result, "$", "$$");
  80. cmSystemTools::ReplaceString(result, "\n", "$\n");
  81. return result;
  82. }
  83. std::string cmGlobalNinjaGenerator::EncodePath(const std::string &path)
  84. {
  85. std::string result = path;
  86. #ifdef _WIN32
  87. if(UsingMinGW)
  88. cmSystemTools::ReplaceString(result, "\\", "/");
  89. else
  90. cmSystemTools::ReplaceString(result, "/", "\\");
  91. #endif
  92. return EncodeLiteral(result);
  93. }
  94. std::string cmGlobalNinjaGenerator::EncodeDepfileSpace(const std::string &path)
  95. {
  96. std::string result = path;
  97. cmSystemTools::ReplaceString(result, " ", "\\ ");
  98. return result;
  99. }
  100. void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
  101. const std::string& comment,
  102. const std::string& rule,
  103. const cmNinjaDeps& outputs,
  104. const cmNinjaDeps& explicitDeps,
  105. const cmNinjaDeps& implicitDeps,
  106. const cmNinjaDeps& orderOnlyDeps,
  107. const cmNinjaVars& variables,
  108. const std::string& rspfile,
  109. int cmdLineLimit)
  110. {
  111. // Make sure there is a rule.
  112. if(rule.empty())
  113. {
  114. cmSystemTools::Error("No rule for WriteBuildStatement! called "
  115. "with comment: ",
  116. comment.c_str());
  117. return;
  118. }
  119. // Make sure there is at least one output file.
  120. if(outputs.empty())
  121. {
  122. cmSystemTools::Error("No output files for WriteBuildStatement! called "
  123. "with comment: ",
  124. comment.c_str());
  125. return;
  126. }
  127. cmGlobalNinjaGenerator::WriteComment(os, comment);
  128. std::string arguments;
  129. // TODO: Better formatting for when there are multiple input/output files.
  130. // Write explicit dependencies.
  131. for(cmNinjaDeps::const_iterator i = explicitDeps.begin();
  132. i != explicitDeps.end();
  133. ++i)
  134. {
  135. arguments += " " + EncodeIdent(EncodePath(*i), os);
  136. }
  137. // Write implicit dependencies.
  138. if(!implicitDeps.empty())
  139. {
  140. arguments += " |";
  141. for(cmNinjaDeps::const_iterator i = implicitDeps.begin();
  142. i != implicitDeps.end();
  143. ++i)
  144. arguments += " " + EncodeIdent(EncodePath(*i), os);
  145. }
  146. // Write order-only dependencies.
  147. if(!orderOnlyDeps.empty())
  148. {
  149. arguments += " ||";
  150. for(cmNinjaDeps::const_iterator i = orderOnlyDeps.begin();
  151. i != orderOnlyDeps.end();
  152. ++i)
  153. arguments += " " + EncodeIdent(EncodePath(*i), os);
  154. }
  155. arguments += "\n";
  156. std::string build;
  157. // Write outputs files.
  158. build += "build";
  159. for(cmNinjaDeps::const_iterator i = outputs.begin();
  160. i != outputs.end(); ++i)
  161. {
  162. build += " " + EncodeIdent(EncodePath(*i), os);
  163. if (this->ComputingUnknownDependencies)
  164. {
  165. this->CombinedBuildOutputs.insert( EncodePath(*i) );
  166. }
  167. }
  168. build += ":";
  169. // Write the rule.
  170. build += " " + rule;
  171. // Write the variables bound to this build statement.
  172. std::ostringstream variable_assignments;
  173. for(cmNinjaVars::const_iterator i = variables.begin();
  174. i != variables.end(); ++i)
  175. cmGlobalNinjaGenerator::WriteVariable(variable_assignments,
  176. i->first, i->second, "", 1);
  177. // check if a response file rule should be used
  178. std::string buildstr = build;
  179. std::string assignments = variable_assignments.str();
  180. const std::string& args = arguments;
  181. if (cmdLineLimit > 0
  182. && args.size() + buildstr.size() + assignments.size()
  183. > (size_t) cmdLineLimit) {
  184. buildstr += "_RSP_FILE";
  185. variable_assignments.str(std::string());
  186. cmGlobalNinjaGenerator::WriteVariable(variable_assignments,
  187. "RSP_FILE", rspfile, "", 1);
  188. assignments += variable_assignments.str();
  189. }
  190. os << buildstr << args << assignments;
  191. }
  192. void cmGlobalNinjaGenerator::WritePhonyBuild(std::ostream& os,
  193. const std::string& comment,
  194. const cmNinjaDeps& outputs,
  195. const cmNinjaDeps& explicitDeps,
  196. const cmNinjaDeps& implicitDeps,
  197. const cmNinjaDeps& orderOnlyDeps,
  198. const cmNinjaVars& variables)
  199. {
  200. this->WriteBuild(os,
  201. comment,
  202. "phony",
  203. outputs,
  204. explicitDeps,
  205. implicitDeps,
  206. orderOnlyDeps,
  207. variables);
  208. }
  209. void cmGlobalNinjaGenerator::AddCustomCommandRule()
  210. {
  211. this->AddRule("CUSTOM_COMMAND",
  212. "$COMMAND",
  213. "$DESC",
  214. "Rule for running custom commands.",
  215. /*depfile*/ "",
  216. /*deptype*/ "",
  217. /*rspfile*/ "",
  218. /*rspcontent*/ "",
  219. /*restat*/ "1",
  220. /*generator*/ false);
  221. }
  222. void
  223. cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
  224. const std::string& description,
  225. const std::string& comment,
  226. bool uses_terminal,
  227. const cmNinjaDeps& outputs,
  228. const cmNinjaDeps& deps,
  229. const cmNinjaDeps& orderOnly)
  230. {
  231. std::string cmd = command;
  232. #ifdef _WIN32
  233. if (cmd.empty())
  234. // TODO Shouldn't an empty command be handled by ninja?
  235. cmd = "cmd.exe /c";
  236. #endif
  237. this->AddCustomCommandRule();
  238. cmNinjaVars vars;
  239. vars["COMMAND"] = cmd;
  240. vars["DESC"] = EncodeLiteral(description);
  241. if (uses_terminal && SupportsConsolePool())
  242. {
  243. vars["pool"] = "console";
  244. }
  245. this->WriteBuild(*this->BuildFileStream,
  246. comment,
  247. "CUSTOM_COMMAND",
  248. outputs,
  249. deps,
  250. cmNinjaDeps(),
  251. orderOnly,
  252. vars);
  253. if (this->ComputingUnknownDependencies)
  254. {
  255. //we need to track every dependency that comes in, since we are trying
  256. //to find dependencies that are side effects of build commands
  257. for(cmNinjaDeps::const_iterator i = deps.begin(); i != deps.end(); ++i)
  258. {
  259. this->CombinedCustomCommandExplicitDependencies.insert(EncodePath(*i));
  260. }
  261. }
  262. }
  263. void
  264. cmGlobalNinjaGenerator::AddMacOSXContentRule()
  265. {
  266. cmLocalGenerator *lg = this->LocalGenerators[0];
  267. cmMakefile* mfRoot = lg->GetMakefile();
  268. std::ostringstream cmd;
  269. cmd << lg->ConvertToOutputFormat(
  270. mfRoot->GetRequiredDefinition("CMAKE_COMMAND"),
  271. cmLocalGenerator::SHELL)
  272. << " -E copy $in $out";
  273. this->AddRule("COPY_OSX_CONTENT",
  274. cmd.str(),
  275. "Copying OS X Content $out",
  276. "Rule for copying OS X bundle content file.",
  277. /*depfile*/ "",
  278. /*deptype*/ "",
  279. /*rspfile*/ "",
  280. /*rspcontent*/ "",
  281. /*restat*/ "",
  282. /*generator*/ false);
  283. }
  284. void
  285. cmGlobalNinjaGenerator::WriteMacOSXContentBuild(const std::string& input,
  286. const std::string& output)
  287. {
  288. this->AddMacOSXContentRule();
  289. cmNinjaDeps outputs;
  290. outputs.push_back(output);
  291. cmNinjaDeps deps;
  292. deps.push_back(input);
  293. cmNinjaVars vars;
  294. this->WriteBuild(*this->BuildFileStream,
  295. "",
  296. "COPY_OSX_CONTENT",
  297. outputs,
  298. deps,
  299. cmNinjaDeps(),
  300. cmNinjaDeps(),
  301. cmNinjaVars());
  302. }
  303. void cmGlobalNinjaGenerator::WriteRule(std::ostream& os,
  304. const std::string& name,
  305. const std::string& command,
  306. const std::string& description,
  307. const std::string& comment,
  308. const std::string& depfile,
  309. const std::string& deptype,
  310. const std::string& rspfile,
  311. const std::string& rspcontent,
  312. const std::string& restat,
  313. bool generator)
  314. {
  315. // Make sure the rule has a name.
  316. if(name.empty())
  317. {
  318. cmSystemTools::Error("No name given for WriteRuleStatement! called "
  319. "with comment: ",
  320. comment.c_str());
  321. return;
  322. }
  323. // Make sure a command is given.
  324. if(command.empty())
  325. {
  326. cmSystemTools::Error("No command given for WriteRuleStatement! called "
  327. "with comment: ",
  328. comment.c_str());
  329. return;
  330. }
  331. cmGlobalNinjaGenerator::WriteComment(os, comment);
  332. // Write the rule.
  333. os << "rule " << name << "\n";
  334. // Write the depfile if any.
  335. if(!depfile.empty())
  336. {
  337. cmGlobalNinjaGenerator::Indent(os, 1);
  338. os << "depfile = " << depfile << "\n";
  339. }
  340. // Write the deptype if any.
  341. if (!deptype.empty())
  342. {
  343. cmGlobalNinjaGenerator::Indent(os, 1);
  344. os << "deps = " << deptype << "\n";
  345. }
  346. // Write the command.
  347. cmGlobalNinjaGenerator::Indent(os, 1);
  348. os << "command = " << command << "\n";
  349. // Write the description if any.
  350. if(!description.empty())
  351. {
  352. cmGlobalNinjaGenerator::Indent(os, 1);
  353. os << "description = " << description << "\n";
  354. }
  355. if(!rspfile.empty())
  356. {
  357. if (rspcontent.empty())
  358. {
  359. cmSystemTools::Error("No rspfile_content given!", comment.c_str());
  360. return;
  361. }
  362. cmGlobalNinjaGenerator::Indent(os, 1);
  363. os << "rspfile = " << rspfile << "\n";
  364. cmGlobalNinjaGenerator::Indent(os, 1);
  365. os << "rspfile_content = " << rspcontent << "\n";
  366. }
  367. if(!restat.empty())
  368. {
  369. cmGlobalNinjaGenerator::Indent(os, 1);
  370. os << "restat = " << restat << "\n";
  371. }
  372. if(generator)
  373. {
  374. cmGlobalNinjaGenerator::Indent(os, 1);
  375. os << "generator = 1\n";
  376. }
  377. os << "\n";
  378. }
  379. void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
  380. const std::string& name,
  381. const std::string& value,
  382. const std::string& comment,
  383. int indent)
  384. {
  385. // Make sure we have a name.
  386. if(name.empty())
  387. {
  388. cmSystemTools::Error("No name given for WriteVariable! called "
  389. "with comment: ",
  390. comment.c_str());
  391. return;
  392. }
  393. // Do not add a variable if the value is empty.
  394. std::string val = cmSystemTools::TrimWhitespace(value);
  395. if(val.empty())
  396. {
  397. return;
  398. }
  399. cmGlobalNinjaGenerator::WriteComment(os, comment);
  400. cmGlobalNinjaGenerator::Indent(os, indent);
  401. os << name << " = " << val << "\n";
  402. }
  403. void cmGlobalNinjaGenerator::WriteInclude(std::ostream& os,
  404. const std::string& filename,
  405. const std::string& comment)
  406. {
  407. cmGlobalNinjaGenerator::WriteComment(os, comment);
  408. os << "include " << filename << "\n";
  409. }
  410. void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os,
  411. const cmNinjaDeps& targets,
  412. const std::string& comment)
  413. {
  414. cmGlobalNinjaGenerator::WriteComment(os, comment);
  415. os << "default";
  416. for(cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end(); ++i)
  417. os << " " << *i;
  418. os << "\n";
  419. }
  420. cmGlobalNinjaGenerator::cmGlobalNinjaGenerator()
  421. : cmGlobalGenerator()
  422. , BuildFileStream(0)
  423. , RulesFileStream(0)
  424. , CompileCommandsStream(0)
  425. , Rules()
  426. , AllDependencies()
  427. , ComputingUnknownDependencies(false)
  428. , PolicyCMP0058(cmPolicies::WARN)
  429. {
  430. // // Ninja is not ported to non-Unix OS yet.
  431. // this->ForceUnixPaths = true;
  432. this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake";
  433. }
  434. //----------------------------------------------------------------------------
  435. // Virtual public methods.
  436. cmLocalGenerator* cmGlobalNinjaGenerator::CreateLocalGenerator()
  437. {
  438. cmLocalGenerator* lg = new cmLocalNinjaGenerator;
  439. lg->SetGlobalGenerator(this);
  440. return lg;
  441. }
  442. void cmGlobalNinjaGenerator
  443. ::GetDocumentation(cmDocumentationEntry& entry)
  444. {
  445. entry.Name = cmGlobalNinjaGenerator::GetActualName();
  446. entry.Brief = "Generates build.ninja files.";
  447. }
  448. // Implemented in all cmGlobaleGenerator sub-classes.
  449. // Used in:
  450. // Source/cmLocalGenerator.cxx
  451. // Source/cmake.cxx
  452. void cmGlobalNinjaGenerator::Generate()
  453. {
  454. this->OpenBuildFileStream();
  455. this->OpenRulesFileStream();
  456. this->PolicyCMP0058 =
  457. this->LocalGenerators[0]->GetMakefile()
  458. ->GetPolicyStatus(cmPolicies::CMP0058);
  459. this->ComputingUnknownDependencies =
  460. (this->PolicyCMP0058 == cmPolicies::OLD ||
  461. this->PolicyCMP0058 == cmPolicies::WARN);
  462. this->cmGlobalGenerator::Generate();
  463. this->WriteAssumedSourceDependencies();
  464. this->WriteTargetAliases(*this->BuildFileStream);
  465. this->WriteUnknownExplicitDependencies(*this->BuildFileStream);
  466. this->WriteBuiltinTargets(*this->BuildFileStream);
  467. if (cmSystemTools::GetErrorOccuredFlag()) {
  468. this->RulesFileStream->setstate(std::ios_base::failbit);
  469. this->BuildFileStream->setstate(std::ios_base::failbit);
  470. }
  471. this->CloseCompileCommandsStream();
  472. this->CloseRulesFileStream();
  473. this->CloseBuildFileStream();
  474. }
  475. // Implemented in all cmGlobaleGenerator sub-classes.
  476. // Used in:
  477. // Source/cmMakefile.cxx:
  478. void cmGlobalNinjaGenerator
  479. ::EnableLanguage(std::vector<std::string>const& langs,
  480. cmMakefile* makefile,
  481. bool optional)
  482. {
  483. if (makefile->IsOn("CMAKE_COMPILER_IS_MINGW"))
  484. {
  485. UsingMinGW = true;
  486. this->EnableMinGWLanguage(makefile);
  487. }
  488. if (std::find(langs.begin(), langs.end(), "Fortran") != langs.end())
  489. {
  490. cmSystemTools::Error("The Ninja generator does not support Fortran yet.");
  491. }
  492. this->cmGlobalGenerator::EnableLanguage(langs, makefile, optional);
  493. for(std::vector<std::string>::const_iterator l = langs.begin();
  494. l != langs.end(); ++l)
  495. {
  496. if(*l == "NONE")
  497. {
  498. continue;
  499. }
  500. this->ResolveLanguageCompiler(*l, makefile, optional);
  501. }
  502. }
  503. bool cmGlobalNinjaGenerator::UsingMinGW = false;
  504. // Implemented by:
  505. // cmGlobalUnixMakefileGenerator3
  506. // cmGlobalGhsMultiGenerator
  507. // cmGlobalVisualStudio10Generator
  508. // cmGlobalVisualStudio6Generator
  509. // cmGlobalVisualStudio7Generator
  510. // cmGlobalXCodeGenerator
  511. // Called by:
  512. // cmGlobalGenerator::Build()
  513. void cmGlobalNinjaGenerator
  514. ::GenerateBuildCommand(std::vector<std::string>& makeCommand,
  515. const std::string& makeProgram,
  516. const std::string& /*projectName*/,
  517. const std::string& /*projectDir*/,
  518. const std::string& targetName,
  519. const std::string& /*config*/,
  520. bool /*fast*/,
  521. bool verbose,
  522. std::vector<std::string> const& makeOptions)
  523. {
  524. makeCommand.push_back(
  525. this->SelectMakeProgram(makeProgram)
  526. );
  527. if(verbose)
  528. {
  529. makeCommand.push_back("-v");
  530. }
  531. makeCommand.insert(makeCommand.end(),
  532. makeOptions.begin(), makeOptions.end());
  533. if(!targetName.empty())
  534. {
  535. if(targetName == "clean")
  536. {
  537. makeCommand.push_back("-t");
  538. makeCommand.push_back("clean");
  539. }
  540. else
  541. {
  542. makeCommand.push_back(targetName);
  543. }
  544. }
  545. }
  546. //----------------------------------------------------------------------------
  547. // Non-virtual public methods.
  548. void cmGlobalNinjaGenerator::AddRule(const std::string& name,
  549. const std::string& command,
  550. const std::string& description,
  551. const std::string& comment,
  552. const std::string& depfile,
  553. const std::string& deptype,
  554. const std::string& rspfile,
  555. const std::string& rspcontent,
  556. const std::string& restat,
  557. bool generator)
  558. {
  559. // Do not add the same rule twice.
  560. if (this->HasRule(name))
  561. {
  562. return;
  563. }
  564. this->Rules.insert(name);
  565. cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream,
  566. name,
  567. command,
  568. description,
  569. comment,
  570. depfile,
  571. deptype,
  572. rspfile,
  573. rspcontent,
  574. restat,
  575. generator);
  576. this->RuleCmdLength[name] = (int) command.size();
  577. }
  578. bool cmGlobalNinjaGenerator::HasRule(const std::string &name)
  579. {
  580. RulesSetType::const_iterator rule = this->Rules.find(name);
  581. return (rule != this->Rules.end());
  582. }
  583. //----------------------------------------------------------------------------
  584. // Private virtual overrides
  585. std::string cmGlobalNinjaGenerator::GetEditCacheCommand() const
  586. {
  587. // Ninja by design does not run interactive tools in the terminal,
  588. // so our only choice is cmake-gui.
  589. return cmSystemTools::GetCMakeGUICommand();
  590. }
  591. //----------------------------------------------------------------------------
  592. void cmGlobalNinjaGenerator
  593. ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
  594. {
  595. cmTarget* target = gt->Target;
  596. // Compute full path to object file directory for this target.
  597. std::string dir;
  598. dir += gt->Makefile->GetCurrentOutputDirectory();
  599. dir += "/";
  600. dir += gt->LocalGenerator->GetTargetDirectory(*target);
  601. dir += "/";
  602. gt->ObjectDirectory = dir;
  603. }
  604. //----------------------------------------------------------------------------
  605. // Private methods
  606. void cmGlobalNinjaGenerator::OpenBuildFileStream()
  607. {
  608. // Compute Ninja's build file path.
  609. std::string buildFilePath =
  610. this->GetCMakeInstance()->GetHomeOutputDirectory();
  611. buildFilePath += "/";
  612. buildFilePath += cmGlobalNinjaGenerator::NINJA_BUILD_FILE;
  613. // Get a stream where to generate things.
  614. if (!this->BuildFileStream)
  615. {
  616. this->BuildFileStream = new cmGeneratedFileStream(buildFilePath.c_str());
  617. if (!this->BuildFileStream)
  618. {
  619. // An error message is generated by the constructor if it cannot
  620. // open the file.
  621. return;
  622. }
  623. }
  624. // Write the do not edit header.
  625. this->WriteDisclaimer(*this->BuildFileStream);
  626. // Write a comment about this file.
  627. *this->BuildFileStream
  628. << "# This file contains all the build statements describing the\n"
  629. << "# compilation DAG.\n\n"
  630. ;
  631. }
  632. void cmGlobalNinjaGenerator::CloseBuildFileStream()
  633. {
  634. if (this->BuildFileStream)
  635. {
  636. delete this->BuildFileStream;
  637. this->BuildFileStream = 0;
  638. }
  639. else
  640. {
  641. cmSystemTools::Error("Build file stream was not open.");
  642. }
  643. }
  644. void cmGlobalNinjaGenerator::OpenRulesFileStream()
  645. {
  646. // Compute Ninja's build file path.
  647. std::string rulesFilePath =
  648. this->GetCMakeInstance()->GetHomeOutputDirectory();
  649. rulesFilePath += "/";
  650. rulesFilePath += cmGlobalNinjaGenerator::NINJA_RULES_FILE;
  651. // Get a stream where to generate things.
  652. if (!this->RulesFileStream)
  653. {
  654. this->RulesFileStream = new cmGeneratedFileStream(rulesFilePath.c_str());
  655. if (!this->RulesFileStream)
  656. {
  657. // An error message is generated by the constructor if it cannot
  658. // open the file.
  659. return;
  660. }
  661. }
  662. // Write the do not edit header.
  663. this->WriteDisclaimer(*this->RulesFileStream);
  664. // Write comment about this file.
  665. *this->RulesFileStream
  666. << "# This file contains all the rules used to get the outputs files\n"
  667. << "# built from the input files.\n"
  668. << "# It is included in the main '" << NINJA_BUILD_FILE << "'.\n\n"
  669. ;
  670. }
  671. void cmGlobalNinjaGenerator::CloseRulesFileStream()
  672. {
  673. if (this->RulesFileStream)
  674. {
  675. delete this->RulesFileStream;
  676. this->RulesFileStream = 0;
  677. }
  678. else
  679. {
  680. cmSystemTools::Error("Rules file stream was not open.");
  681. }
  682. }
  683. void cmGlobalNinjaGenerator::AddCXXCompileCommand(
  684. const std::string &commandLine,
  685. const std::string &sourceFile)
  686. {
  687. // Compute Ninja's build file path.
  688. std::string buildFileDir =
  689. this->GetCMakeInstance()->GetHomeOutputDirectory();
  690. if (!this->CompileCommandsStream)
  691. {
  692. std::string buildFilePath = buildFileDir + "/compile_commands.json";
  693. // Get a stream where to generate things.
  694. this->CompileCommandsStream =
  695. new cmGeneratedFileStream(buildFilePath.c_str());
  696. *this->CompileCommandsStream << "[";
  697. } else {
  698. *this->CompileCommandsStream << "," << std::endl;
  699. }
  700. std::string sourceFileName = sourceFile;
  701. if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
  702. {
  703. sourceFileName = cmSystemTools::CollapseFullPath(
  704. sourceFileName,
  705. this->GetCMakeInstance()->GetHomeOutputDirectory());
  706. }
  707. *this->CompileCommandsStream << "\n{\n"
  708. << " \"directory\": \""
  709. << cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
  710. << " \"command\": \""
  711. << cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
  712. << " \"file\": \""
  713. << cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n"
  714. << "}";
  715. }
  716. void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
  717. {
  718. if (this->CompileCommandsStream)
  719. {
  720. *this->CompileCommandsStream << "\n]";
  721. delete this->CompileCommandsStream;
  722. this->CompileCommandsStream = 0;
  723. }
  724. }
  725. void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
  726. {
  727. os
  728. << "# CMAKE generated file: DO NOT EDIT!\n"
  729. << "# Generated by \"" << this->GetName() << "\""
  730. << " Generator, CMake Version "
  731. << cmVersion::GetMajorVersion() << "."
  732. << cmVersion::GetMinorVersion() << "\n\n";
  733. }
  734. void cmGlobalNinjaGenerator::AddDependencyToAll(cmTarget* target)
  735. {
  736. this->AppendTargetOutputs(target, this->AllDependencies);
  737. }
  738. void cmGlobalNinjaGenerator::AddDependencyToAll(const std::string& input)
  739. {
  740. this->AllDependencies.push_back(input);
  741. }
  742. void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
  743. {
  744. for (std::map<std::string, std::set<std::string> >::iterator
  745. i = this->AssumedSourceDependencies.begin();
  746. i != this->AssumedSourceDependencies.end(); ++i) {
  747. cmNinjaDeps deps;
  748. std::copy(i->second.begin(), i->second.end(), std::back_inserter(deps));
  749. WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
  750. "Assume dependencies for generated source file.",
  751. /*uses_terminal*/false,
  752. cmNinjaDeps(1, i->first), deps);
  753. }
  754. }
  755. void
  756. cmGlobalNinjaGenerator
  757. ::AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs)
  758. {
  759. std::string configName =
  760. target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
  761. cmLocalNinjaGenerator *ng =
  762. static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
  763. // for frameworks, we want the real name, not smple name
  764. // frameworks always appear versioned, and the build.ninja
  765. // will always attempt to manage symbolic links instead
  766. // of letting cmOSXBundleGenerator do it.
  767. bool realname = target->IsFrameworkOnApple();
  768. switch (target->GetType()) {
  769. case cmTarget::EXECUTABLE:
  770. case cmTarget::SHARED_LIBRARY:
  771. case cmTarget::STATIC_LIBRARY:
  772. case cmTarget::MODULE_LIBRARY:
  773. outputs.push_back(ng->ConvertToNinjaPath(
  774. target->GetFullPath(configName, false, realname)));
  775. break;
  776. case cmTarget::OBJECT_LIBRARY:
  777. case cmTarget::UTILITY: {
  778. std::string path = ng->ConvertToNinjaPath(
  779. target->GetMakefile()->GetStartOutputDirectory());
  780. if (path.empty() || path == ".")
  781. outputs.push_back(target->GetName());
  782. else {
  783. path += "/";
  784. path += target->GetName();
  785. outputs.push_back(path);
  786. }
  787. break;
  788. }
  789. case cmTarget::GLOBAL_TARGET:
  790. // Always use the target in HOME instead of an unused duplicate in a
  791. // subdirectory.
  792. outputs.push_back(target->GetName());
  793. break;
  794. default:
  795. return;
  796. }
  797. }
  798. void
  799. cmGlobalNinjaGenerator
  800. ::AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs)
  801. {
  802. if (target->GetType() == cmTarget::GLOBAL_TARGET) {
  803. // Global targets only depend on other utilities, which may not appear in
  804. // the TargetDepends set (e.g. "all").
  805. std::set<std::string> const& utils = target->GetUtilities();
  806. std::copy(utils.begin(), utils.end(), std::back_inserter(outputs));
  807. } else {
  808. cmTargetDependSet const& targetDeps =
  809. this->GetTargetDirectDepends(*target);
  810. for (cmTargetDependSet::const_iterator i = targetDeps.begin();
  811. i != targetDeps.end(); ++i)
  812. {
  813. if ((*i)->GetType() == cmTarget::INTERFACE_LIBRARY)
  814. {
  815. continue;
  816. }
  817. this->AppendTargetOutputs(*i, outputs);
  818. }
  819. }
  820. }
  821. void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
  822. cmTarget* target) {
  823. cmNinjaDeps outputs;
  824. this->AppendTargetOutputs(target, outputs);
  825. // Mark the target's outputs as ambiguous to ensure that no other target uses
  826. // the output as an alias.
  827. for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i)
  828. TargetAliases[*i] = 0;
  829. // Insert the alias into the map. If the alias was already present in the
  830. // map and referred to another target, mark it as ambiguous.
  831. std::pair<TargetAliasMap::iterator, bool> newAlias =
  832. TargetAliases.insert(std::make_pair(alias, target));
  833. if (newAlias.second && newAlias.first->second != target)
  834. newAlias.first->second = 0;
  835. }
  836. void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
  837. {
  838. cmGlobalNinjaGenerator::WriteDivider(os);
  839. os << "# Target aliases.\n\n";
  840. for (TargetAliasMap::const_iterator i = TargetAliases.begin();
  841. i != TargetAliases.end(); ++i) {
  842. // Don't write ambiguous aliases.
  843. if (!i->second)
  844. continue;
  845. cmNinjaDeps deps;
  846. this->AppendTargetOutputs(i->second, deps);
  847. this->WritePhonyBuild(os,
  848. "",
  849. cmNinjaDeps(1, i->first),
  850. deps);
  851. }
  852. }
  853. void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
  854. {
  855. if (!this->ComputingUnknownDependencies)
  856. {
  857. return;
  858. }
  859. // We need to collect the set of known build outputs.
  860. // Start with those generated by WriteBuild calls.
  861. // No other method needs this so we can take ownership
  862. // of the set locally and throw it out when we are done.
  863. std::set<std::string> knownDependencies;
  864. knownDependencies.swap(this->CombinedBuildOutputs);
  865. //now write out the unknown explicit dependencies.
  866. //union the configured files, evaluations files and the CombinedBuildOutputs,
  867. //and then difference with CombinedExplicitDependencies to find the explicit
  868. //dependencies that we have no rule for
  869. cmGlobalNinjaGenerator::WriteDivider(os);
  870. os << "# Unknown Build Time Dependencies.\n"
  871. << "# Tell Ninja that they may appear as side effects of build rules\n"
  872. << "# otherwise ordered by order-only dependencies.\n\n";
  873. //get the list of files that cmake itself has generated as a
  874. //product of configuration.
  875. cmLocalNinjaGenerator *ng =
  876. static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
  877. for (std::vector<cmLocalGenerator *>::const_iterator i =
  878. this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
  879. {
  880. //get the vector of files created by this makefile and convert them
  881. //to ninja paths, which are all relative in respect to the build directory
  882. const std::vector<std::string>& files =
  883. (*i)->GetMakefile()->GetOutputFiles();
  884. typedef std::vector<std::string>::const_iterator vect_it;
  885. for(vect_it j = files.begin(); j != files.end(); ++j)
  886. {
  887. knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
  888. }
  889. //get list files which are implicit dependencies as well and will be phony
  890. //for rebuild manifest
  891. std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
  892. typedef std::vector<std::string>::const_iterator vect_it;
  893. for(vect_it j = lf.begin(); j != lf.end(); ++j)
  894. {
  895. knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
  896. }
  897. }
  898. knownDependencies.insert( "CMakeCache.txt" );
  899. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  900. li = this->EvaluationFiles.begin();
  901. li != this->EvaluationFiles.end();
  902. ++li)
  903. {
  904. //get all the files created by generator expressions and convert them
  905. //to ninja paths
  906. std::vector<std::string> files = (*li)->GetFiles();
  907. typedef std::vector<std::string>::const_iterator vect_it;
  908. for(vect_it j = files.begin(); j != files.end(); ++j)
  909. {
  910. knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
  911. }
  912. }
  913. for(TargetAliasMap::const_iterator i= this->TargetAliases.begin();
  914. i != this->TargetAliases.end();
  915. ++i)
  916. {
  917. knownDependencies.insert( ng->ConvertToNinjaPath(i->first) );
  918. }
  919. //remove all source files we know will exist.
  920. typedef std::map<std::string, std::set<std::string> >::const_iterator map_it;
  921. for(map_it i = this->AssumedSourceDependencies.begin();
  922. i != this->AssumedSourceDependencies.end();
  923. ++i)
  924. {
  925. knownDependencies.insert( ng->ConvertToNinjaPath(i->first) );
  926. }
  927. //now we difference with CombinedCustomCommandExplicitDependencies to find
  928. //the list of items we know nothing about.
  929. //We have encoded all the paths in CombinedCustomCommandExplicitDependencies
  930. //and knownDependencies so no matter if unix or windows paths they
  931. //should all match now.
  932. std::vector<std::string> unknownExplicitDepends;
  933. this->CombinedCustomCommandExplicitDependencies.erase("all");
  934. std::set_difference(this->CombinedCustomCommandExplicitDependencies.begin(),
  935. this->CombinedCustomCommandExplicitDependencies.end(),
  936. knownDependencies.begin(),
  937. knownDependencies.end(),
  938. std::back_inserter(unknownExplicitDepends));
  939. std::string const rootBuildDirectory =
  940. this->GetCMakeInstance()->GetHomeOutputDirectory();
  941. bool const inSourceBuild =
  942. (rootBuildDirectory == this->GetCMakeInstance()->GetHomeDirectory());
  943. std::vector<std::string> warnExplicitDepends;
  944. for (std::vector<std::string>::const_iterator
  945. i = unknownExplicitDepends.begin();
  946. i != unknownExplicitDepends.end();
  947. ++i)
  948. {
  949. //verify the file is in the build directory
  950. std::string const absDepPath = cmSystemTools::CollapseFullPath(
  951. *i, rootBuildDirectory.c_str());
  952. bool const inBuildDir = cmSystemTools::IsSubDirectory(absDepPath,
  953. rootBuildDirectory);
  954. if(inBuildDir)
  955. {
  956. cmNinjaDeps deps(1,*i);
  957. this->WritePhonyBuild(os,
  958. "",
  959. deps,
  960. cmNinjaDeps());
  961. if (this->PolicyCMP0058 == cmPolicies::WARN &&
  962. !inSourceBuild && warnExplicitDepends.size() < 10)
  963. {
  964. warnExplicitDepends.push_back(*i);
  965. }
  966. }
  967. }
  968. if (!warnExplicitDepends.empty())
  969. {
  970. std::ostringstream w;
  971. w <<
  972. (this->GetCMakeInstance()->GetPolicies()->
  973. GetPolicyWarning(cmPolicies::CMP0058)) << "\n"
  974. "This project specifies custom command DEPENDS on files "
  975. "in the build tree that are not specified as the OUTPUT or "
  976. "BYPRODUCTS of any add_custom_command or add_custom_target:\n"
  977. " " << cmJoin(warnExplicitDepends, "\n ") <<
  978. "\n"
  979. "For compatibility with versions of CMake that did not have "
  980. "the BYPRODUCTS option, CMake is generating phony rules for "
  981. "such files to convince 'ninja' to build."
  982. "\n"
  983. "Project authors should add the missing BYPRODUCTS or OUTPUT "
  984. "options to the custom commands that produce these files."
  985. ;
  986. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  987. }
  988. }
  989. void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os)
  990. {
  991. // Write headers.
  992. cmGlobalNinjaGenerator::WriteDivider(os);
  993. os << "# Built-in targets\n\n";
  994. this->WriteTargetAll(os);
  995. this->WriteTargetRebuildManifest(os);
  996. this->WriteTargetClean(os);
  997. this->WriteTargetHelp(os);
  998. }
  999. void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
  1000. {
  1001. cmNinjaDeps outputs;
  1002. outputs.push_back("all");
  1003. this->WritePhonyBuild(os,
  1004. "The main all target.",
  1005. outputs,
  1006. this->AllDependencies);
  1007. cmGlobalNinjaGenerator::WriteDefault(os,
  1008. outputs,
  1009. "Make the all target the default.");
  1010. }
  1011. void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
  1012. {
  1013. cmLocalGenerator *lg = this->LocalGenerators[0];
  1014. cmMakefile* mfRoot = lg->GetMakefile();
  1015. std::ostringstream cmd;
  1016. cmd << lg->ConvertToOutputFormat(
  1017. mfRoot->GetRequiredDefinition("CMAKE_COMMAND"),
  1018. cmLocalGenerator::SHELL)
  1019. << " -H"
  1020. << lg->ConvertToOutputFormat(mfRoot->GetHomeDirectory(),
  1021. cmLocalGenerator::SHELL)
  1022. << " -B"
  1023. << lg->ConvertToOutputFormat(mfRoot->GetHomeOutputDirectory(),
  1024. cmLocalGenerator::SHELL);
  1025. WriteRule(*this->RulesFileStream,
  1026. "RERUN_CMAKE",
  1027. cmd.str(),
  1028. "Re-running CMake...",
  1029. "Rule for re-running cmake.",
  1030. /*depfile=*/ "",
  1031. /*deptype=*/ "",
  1032. /*rspfile=*/ "",
  1033. /*rspcontent*/ "",
  1034. /*restat=*/ "",
  1035. /*generator=*/ true);
  1036. cmLocalNinjaGenerator *ng = static_cast<cmLocalNinjaGenerator *>(lg);
  1037. cmNinjaDeps implicitDeps;
  1038. for(std::vector<cmLocalGenerator*>::const_iterator i =
  1039. this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
  1040. {
  1041. std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
  1042. for(std::vector<std::string>::const_iterator fi = lf.begin();
  1043. fi != lf.end(); ++fi)
  1044. {
  1045. implicitDeps.push_back(ng->ConvertToNinjaPath(*fi));
  1046. }
  1047. }
  1048. implicitDeps.push_back("CMakeCache.txt");
  1049. std::sort(implicitDeps.begin(), implicitDeps.end());
  1050. implicitDeps.erase(std::unique(implicitDeps.begin(), implicitDeps.end()),
  1051. implicitDeps.end());
  1052. cmNinjaVars variables;
  1053. // Use 'console' pool to get non buffered output of the CMake re-run call
  1054. // Available since Ninja 1.5
  1055. if(SupportsConsolePool())
  1056. {
  1057. variables["pool"] = "console";
  1058. }
  1059. this->WriteBuild(os,
  1060. "Re-run CMake if any of its inputs changed.",
  1061. "RERUN_CMAKE",
  1062. /*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE),
  1063. /*explicitDeps=*/ cmNinjaDeps(),
  1064. implicitDeps,
  1065. /*orderOnlyDeps=*/ cmNinjaDeps(),
  1066. variables);
  1067. this->WritePhonyBuild(os,
  1068. "A missing CMake input file is not an error.",
  1069. implicitDeps,
  1070. cmNinjaDeps());
  1071. }
  1072. std::string cmGlobalNinjaGenerator::ninjaCmd() const
  1073. {
  1074. cmLocalGenerator* lgen = this->LocalGenerators[0];
  1075. if (lgen) {
  1076. return lgen->ConvertToOutputFormat(
  1077. lgen->GetMakefile()->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"),
  1078. cmLocalGenerator::SHELL);
  1079. }
  1080. return "ninja";
  1081. }
  1082. std::string cmGlobalNinjaGenerator::ninjaVersion() const
  1083. {
  1084. std::string version;
  1085. std::string command = ninjaCmd() + " --version";
  1086. cmSystemTools::RunSingleCommand(command.c_str(),
  1087. &version, 0, 0, 0,
  1088. cmSystemTools::OUTPUT_NONE);
  1089. return version;
  1090. }
  1091. bool cmGlobalNinjaGenerator::SupportsConsolePool() const
  1092. {
  1093. return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
  1094. ninjaVersion().c_str(), "1.5") == false;
  1095. }
  1096. void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
  1097. {
  1098. WriteRule(*this->RulesFileStream,
  1099. "CLEAN",
  1100. ninjaCmd() + " -t clean",
  1101. "Cleaning all built files...",
  1102. "Rule for cleaning all built files.",
  1103. /*depfile=*/ "",
  1104. /*deptype=*/ "",
  1105. /*rspfile=*/ "",
  1106. /*rspcontent*/ "",
  1107. /*restat=*/ "",
  1108. /*generator=*/ false);
  1109. WriteBuild(os,
  1110. "Clean all the built files.",
  1111. "CLEAN",
  1112. /*outputs=*/ cmNinjaDeps(1, "clean"),
  1113. /*explicitDeps=*/ cmNinjaDeps(),
  1114. /*implicitDeps=*/ cmNinjaDeps(),
  1115. /*orderOnlyDeps=*/ cmNinjaDeps(),
  1116. /*variables=*/ cmNinjaVars());
  1117. }
  1118. void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os)
  1119. {
  1120. WriteRule(*this->RulesFileStream,
  1121. "HELP",
  1122. ninjaCmd() + " -t targets",
  1123. "All primary targets available:",
  1124. "Rule for printing all primary targets available.",
  1125. /*depfile=*/ "",
  1126. /*deptype=*/ "",
  1127. /*rspfile=*/ "",
  1128. /*rspcontent*/ "",
  1129. /*restat=*/ "",
  1130. /*generator=*/ false);
  1131. WriteBuild(os,
  1132. "Print all primary targets available.",
  1133. "HELP",
  1134. /*outputs=*/ cmNinjaDeps(1, "help"),
  1135. /*explicitDeps=*/ cmNinjaDeps(),
  1136. /*implicitDeps=*/ cmNinjaDeps(),
  1137. /*orderOnlyDeps=*/ cmNinjaDeps(),
  1138. /*variables=*/ cmNinjaVars());
  1139. }