cmGlobalNinjaGenerator.cxx 41 KB

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