cmGlobalNinjaGenerator.cxx 41 KB

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