cmNinjaTargetGenerator.cxx 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmNinjaTargetGenerator.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmComputeLinkInformation.h"
  6. #include "cmCustomCommandGenerator.h"
  7. #include "cmGeneratedFileStream.h"
  8. #include "cmGeneratorTarget.h"
  9. #include "cmGlobalNinjaGenerator.h"
  10. #include "cmLocalGenerator.h"
  11. #include "cmLocalNinjaGenerator.h"
  12. #include "cmMakefile.h"
  13. #include "cmNinjaNormalTargetGenerator.h"
  14. #include "cmNinjaUtilityTargetGenerator.h"
  15. #include "cmOutputConverter.h"
  16. #include "cmSourceFile.h"
  17. #include "cmState.h"
  18. #include "cmSystemTools.h"
  19. #include "cmake.h"
  20. #include "cm_jsoncpp_writer.h"
  21. #include <algorithm>
  22. #include <iterator>
  23. #include <map>
  24. #include <sstream>
  25. #include <string.h>
  26. cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target)
  27. {
  28. switch (target->GetType()) {
  29. case cmState::EXECUTABLE:
  30. case cmState::SHARED_LIBRARY:
  31. case cmState::STATIC_LIBRARY:
  32. case cmState::MODULE_LIBRARY:
  33. case cmState::OBJECT_LIBRARY:
  34. return new cmNinjaNormalTargetGenerator(target);
  35. case cmState::UTILITY:
  36. case cmState::GLOBAL_TARGET:
  37. return new cmNinjaUtilityTargetGenerator(target);
  38. default:
  39. return CM_NULLPTR;
  40. }
  41. }
  42. cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
  43. : cmCommonTargetGenerator(target)
  44. , MacOSXContentGenerator(CM_NULLPTR)
  45. , OSXBundleGenerator(CM_NULLPTR)
  46. , MacContentFolders()
  47. , LocalGenerator(
  48. static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator()))
  49. , Objects()
  50. {
  51. MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
  52. }
  53. cmNinjaTargetGenerator::~cmNinjaTargetGenerator()
  54. {
  55. delete this->MacOSXContentGenerator;
  56. }
  57. cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const
  58. {
  59. return *this->GetGlobalGenerator()->GetBuildFileStream();
  60. }
  61. cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const
  62. {
  63. return *this->GetGlobalGenerator()->GetRulesFileStream();
  64. }
  65. cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
  66. {
  67. return this->LocalGenerator->GetGlobalNinjaGenerator();
  68. }
  69. std::string cmNinjaTargetGenerator::LanguageCompilerRule(
  70. const std::string& lang) const
  71. {
  72. return lang + "_COMPILER__" +
  73. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName());
  74. }
  75. std::string cmNinjaTargetGenerator::LanguagePreprocessRule(
  76. std::string const& lang) const
  77. {
  78. return lang + "_PREPROCESS__" +
  79. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName());
  80. }
  81. bool cmNinjaTargetGenerator::NeedExplicitPreprocessing(
  82. std::string const& lang) const
  83. {
  84. return lang == "Fortran";
  85. }
  86. std::string cmNinjaTargetGenerator::LanguageDyndepRule(
  87. const std::string& lang) const
  88. {
  89. return lang + "_DYNDEP__" +
  90. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName());
  91. }
  92. bool cmNinjaTargetGenerator::NeedDyndep(std::string const& lang) const
  93. {
  94. return lang == "Fortran";
  95. }
  96. std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget()
  97. {
  98. return "cmake_order_depends_target_" + this->GetTargetName();
  99. }
  100. // TODO: Most of the code is picked up from
  101. // void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink),
  102. // void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
  103. // Refactor it.
  104. std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
  105. cmSourceFile const* source, const std::string& language)
  106. {
  107. std::string flags = this->GetFlags(language);
  108. // Add Fortran format flags.
  109. if (language == "Fortran") {
  110. this->AppendFortranFormatFlags(flags, *source);
  111. }
  112. // Add source file specific flags.
  113. this->LocalGenerator->AppendFlags(flags,
  114. source->GetProperty("COMPILE_FLAGS"));
  115. return flags;
  116. }
  117. void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
  118. std::string const& language)
  119. {
  120. std::vector<std::string> includes;
  121. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  122. language, this->GetConfigName());
  123. // Add include directory flags.
  124. std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
  125. includes, this->GeneratorTarget, language,
  126. language == "RC", // full include paths for RC needed by cmcldeps
  127. false, this->GetConfigName());
  128. if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
  129. std::replace(includeFlags.begin(), includeFlags.end(), '\\', '/');
  130. }
  131. this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
  132. }
  133. bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const
  134. {
  135. return strcmp(this->GetMakefile()->GetSafeDefinition("CMAKE_NINJA_DEPTYPE_" +
  136. lang),
  137. "msvc") == 0;
  138. }
  139. // TODO: Refactor with
  140. // void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
  141. std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
  142. const std::string& language)
  143. {
  144. std::set<std::string> defines;
  145. this->LocalGenerator->AppendDefines(
  146. defines, source->GetProperty("COMPILE_DEFINITIONS"));
  147. {
  148. std::string defPropName = "COMPILE_DEFINITIONS_";
  149. defPropName += cmSystemTools::UpperCase(this->GetConfigName());
  150. this->LocalGenerator->AppendDefines(defines,
  151. source->GetProperty(defPropName));
  152. }
  153. std::string definesString = this->GetDefines(language);
  154. this->LocalGenerator->JoinDefines(defines, definesString, language);
  155. return definesString;
  156. }
  157. cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
  158. {
  159. // Static libraries never depend on other targets for linking.
  160. if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
  161. this->GeneratorTarget->GetType() == cmState::OBJECT_LIBRARY) {
  162. return cmNinjaDeps();
  163. }
  164. cmComputeLinkInformation* cli =
  165. this->GeneratorTarget->GetLinkInformation(this->GetConfigName());
  166. if (!cli) {
  167. return cmNinjaDeps();
  168. }
  169. const std::vector<std::string>& deps = cli->GetDepends();
  170. cmNinjaDeps result(deps.size());
  171. std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
  172. // Add a dependency on the link definitions file, if any.
  173. if (this->ModuleDefinitionFile) {
  174. result.push_back(
  175. this->ConvertToNinjaPath(this->ModuleDefinitionFile->GetFullPath()));
  176. }
  177. // Add a dependency on user-specified manifest files, if any.
  178. std::vector<cmSourceFile const*> manifest_srcs;
  179. this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
  180. for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
  181. mi != manifest_srcs.end(); ++mi) {
  182. result.push_back(this->ConvertToNinjaPath((*mi)->GetFullPath()));
  183. }
  184. // Add user-specified dependencies.
  185. if (const char* linkDepends =
  186. this->GeneratorTarget->GetProperty("LINK_DEPENDS")) {
  187. std::vector<std::string> linkDeps;
  188. cmSystemTools::ExpandListArgument(linkDepends, linkDeps);
  189. std::transform(linkDeps.begin(), linkDeps.end(),
  190. std::back_inserter(result), MapToNinjaPath());
  191. }
  192. return result;
  193. }
  194. std::string cmNinjaTargetGenerator::GetSourceFilePath(
  195. cmSourceFile const* source) const
  196. {
  197. return ConvertToNinjaPath(source->GetFullPath());
  198. }
  199. std::string cmNinjaTargetGenerator::GetObjectFilePath(
  200. cmSourceFile const* source) const
  201. {
  202. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  203. if (!path.empty()) {
  204. path += "/";
  205. }
  206. std::string const& objectName = this->GeneratorTarget->GetObjectName(source);
  207. path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  208. path += "/";
  209. path += objectName;
  210. return path;
  211. }
  212. std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
  213. cmSourceFile const* source) const
  214. {
  215. // Choose an extension to compile already-preprocessed source.
  216. std::string ppExt = source->GetExtension();
  217. if (cmHasLiteralPrefix(ppExt, "F")) {
  218. // Some Fortran compilers automatically enable preprocessing for
  219. // upper-case extensions. Since the source is already preprocessed,
  220. // use a lower-case extension.
  221. ppExt = cmSystemTools::LowerCase(ppExt);
  222. }
  223. if (ppExt == "fpp") {
  224. // Some Fortran compilers automatically enable preprocessing for
  225. // the ".fpp" extension. Since the source is already preprocessed,
  226. // use the ".f" extension.
  227. ppExt = "f";
  228. }
  229. // Take the object file name and replace the extension.
  230. std::string const& objName = this->GeneratorTarget->GetObjectName(source);
  231. std::string const& objExt =
  232. this->GetGlobalGenerator()->GetLanguageOutputExtension(*source);
  233. assert(objName.size() >= objExt.size());
  234. std::string const ppName =
  235. objName.substr(0, objName.size() - objExt.size()) + "-pp." + ppExt;
  236. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  237. if (!path.empty())
  238. path += "/";
  239. path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  240. path += "/";
  241. path += ppName;
  242. return path;
  243. }
  244. std::string cmNinjaTargetGenerator::GetDyndepFilePath(
  245. std::string const& lang) const
  246. {
  247. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  248. if (!path.empty())
  249. path += "/";
  250. path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  251. path += "/";
  252. path += lang;
  253. path += ".dd";
  254. return path;
  255. }
  256. std::string cmNinjaTargetGenerator::GetTargetDependInfoPath(
  257. std::string const& lang) const
  258. {
  259. std::string path = this->Makefile->GetCurrentBinaryDirectory();
  260. path += "/";
  261. path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  262. path += "/" + lang + "DependInfo.json";
  263. return path;
  264. }
  265. std::string cmNinjaTargetGenerator::GetTargetOutputDir() const
  266. {
  267. std::string dir = this->GeneratorTarget->GetDirectory(this->GetConfigName());
  268. return ConvertToNinjaPath(dir);
  269. }
  270. std::string cmNinjaTargetGenerator::GetTargetFilePath(
  271. const std::string& name) const
  272. {
  273. std::string path = this->GetTargetOutputDir();
  274. if (path.empty() || path == ".") {
  275. return name;
  276. }
  277. path += "/";
  278. path += name;
  279. return path;
  280. }
  281. std::string cmNinjaTargetGenerator::GetTargetName() const
  282. {
  283. return this->GeneratorTarget->GetName();
  284. }
  285. bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const
  286. {
  287. cmMakefile* mf = this->GetMakefile();
  288. if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
  289. mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) {
  290. std::string pdbPath;
  291. std::string compilePdbPath;
  292. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
  293. this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
  294. this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  295. this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
  296. pdbPath = this->GeneratorTarget->GetPDBDirectory(this->GetConfigName());
  297. pdbPath += "/";
  298. pdbPath += this->GeneratorTarget->GetPDBName(this->GetConfigName());
  299. }
  300. if (this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY) {
  301. compilePdbPath =
  302. this->GeneratorTarget->GetCompilePDBPath(this->GetConfigName());
  303. if (compilePdbPath.empty()) {
  304. compilePdbPath = this->GeneratorTarget->GetSupportDirectory() + "/";
  305. }
  306. }
  307. vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  308. ConvertToNinjaPath(pdbPath), cmOutputConverter::SHELL);
  309. vars["TARGET_COMPILE_PDB"] =
  310. this->GetLocalGenerator()->ConvertToOutputFormat(
  311. ConvertToNinjaPath(compilePdbPath), cmOutputConverter::SHELL);
  312. EnsureParentDirectoryExists(pdbPath);
  313. EnsureParentDirectoryExists(compilePdbPath);
  314. return true;
  315. }
  316. return false;
  317. }
  318. void cmNinjaTargetGenerator::WriteLanguageRules(const std::string& language)
  319. {
  320. #ifdef NINJA_GEN_VERBOSE_FILES
  321. this->GetRulesFileStream() << "# Rules for language " << language << "\n\n";
  322. #endif
  323. this->WriteCompileRule(language);
  324. }
  325. void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
  326. {
  327. cmLocalGenerator::RuleVariables vars;
  328. vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
  329. vars.CMTarget = this->GetGeneratorTarget();
  330. vars.Language = lang.c_str();
  331. vars.Source = "$IN_ABS";
  332. vars.Object = "$out";
  333. vars.Defines = "$DEFINES";
  334. vars.Includes = "$INCLUDES";
  335. vars.TargetPDB = "$TARGET_PDB";
  336. vars.TargetCompilePDB = "$TARGET_COMPILE_PDB";
  337. vars.ObjectDir = "$OBJECT_DIR";
  338. vars.ObjectFileDir = "$OBJECT_FILE_DIR";
  339. // For some cases we do an explicit preprocessor invocation.
  340. bool const explicitPP = this->NeedExplicitPreprocessing(lang);
  341. bool const needDyndep = this->NeedDyndep(lang);
  342. cmMakefile* mf = this->GetMakefile();
  343. std::string flags = "$FLAGS";
  344. std::string rspfile;
  345. std::string rspcontent;
  346. std::string responseFlag;
  347. if (lang != "RC" && this->ForceResponseFile()) {
  348. rspfile = "$RSP_FILE";
  349. responseFlag = "@" + rspfile;
  350. rspcontent = " $DEFINES $INCLUDES $FLAGS";
  351. flags = responseFlag;
  352. vars.Defines = "";
  353. vars.Includes = "";
  354. }
  355. // Tell ninja dependency format so all deps can be loaded into a database
  356. std::string deptype;
  357. std::string depfile;
  358. std::string cldeps;
  359. if (explicitPP) {
  360. // The explicit preprocessing step will handle dependency scanning.
  361. } else if (this->NeedDepTypeMSVC(lang)) {
  362. deptype = "msvc";
  363. depfile = "";
  364. flags += " /showIncludes";
  365. } else if (mf->IsOn("CMAKE_NINJA_CMCLDEPS_" + lang)) {
  366. // For the MS resource compiler we need cmcldeps, but skip dependencies
  367. // for source-file try_compile cases because they are always fresh.
  368. if (!mf->GetIsSourceFileTryCompile()) {
  369. deptype = "gcc";
  370. depfile = "$DEP_FILE";
  371. const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER")
  372. ? mf->GetSafeDefinition("CMAKE_C_COMPILER")
  373. : mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
  374. cldeps = "\"";
  375. cldeps += cmSystemTools::GetCMClDepsCommand();
  376. cldeps += "\" " + lang + " $in \"$DEP_FILE\" $out \"";
  377. cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
  378. cldeps += "\" \"" + cl + "\" ";
  379. }
  380. } else {
  381. deptype = "gcc";
  382. const char* langdeptype = mf->GetDefinition("CMAKE_NINJA_DEPTYPE_" + lang);
  383. if (langdeptype) {
  384. deptype = langdeptype;
  385. }
  386. depfile = "$DEP_FILE";
  387. const std::string flagsName = "CMAKE_DEPFILE_FLAGS_" + lang;
  388. std::string depfileFlags = mf->GetSafeDefinition(flagsName);
  389. if (!depfileFlags.empty()) {
  390. cmSystemTools::ReplaceString(depfileFlags, "<DEPFILE>", "$DEP_FILE");
  391. cmSystemTools::ReplaceString(depfileFlags, "<OBJECT>", "$out");
  392. cmSystemTools::ReplaceString(depfileFlags, "<CMAKE_C_COMPILER>",
  393. mf->GetDefinition("CMAKE_C_COMPILER"));
  394. flags += " " + depfileFlags;
  395. }
  396. }
  397. vars.Flags = flags.c_str();
  398. vars.DependencyFile = depfile.c_str();
  399. std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat(
  400. ConvertToNinjaPath(this->GetTargetDependInfoPath(lang)),
  401. cmLocalGenerator::SHELL);
  402. if (explicitPP) {
  403. // Lookup the explicit preprocessing rule.
  404. std::string const ppVar = "CMAKE_" + lang + "_PREPROCESS_SOURCE";
  405. std::string const ppCmd =
  406. this->GetMakefile()->GetRequiredDefinition(ppVar);
  407. // Explicit preprocessing always uses a depfile.
  408. std::string const ppDeptype = ""; // no deps= for multiple outputs
  409. std::string const ppDepfile = "$DEP_FILE";
  410. cmLocalGenerator::RuleVariables ppVars;
  411. ppVars.RuleLauncher = vars.RuleLauncher;
  412. ppVars.CMTarget = vars.CMTarget;
  413. ppVars.Language = vars.Language;
  414. ppVars.Object = "$out"; // for RULE_LAUNCH_COMPILE
  415. ppVars.PreprocessedSource = "$out";
  416. ppVars.DependencyFile = ppDepfile.c_str();
  417. // Preprocessing uses the original source,
  418. // compilation uses preprocessed output.
  419. ppVars.Source = vars.Source;
  420. vars.Source = "$in";
  421. // Preprocessing and compilation use the same flags.
  422. ppVars.Flags = vars.Flags;
  423. // Move preprocessor definitions to the preprocessor rule.
  424. ppVars.Defines = vars.Defines;
  425. vars.Defines = "";
  426. // Copy include directories to the preprocessor rule. The Fortran
  427. // compilation rule still needs them for the INCLUDE directive.
  428. ppVars.Includes = vars.Includes;
  429. // Rule for preprocessing source file.
  430. std::vector<std::string> ppCmds;
  431. cmSystemTools::ExpandListArgument(ppCmd, ppCmds);
  432. for (std::vector<std::string>::iterator i = ppCmds.begin();
  433. i != ppCmds.end(); ++i) {
  434. this->GetLocalGenerator()->ExpandRuleVariables(*i, ppVars);
  435. }
  436. // Run CMake dependency scanner on preprocessed output.
  437. std::string const cmake = this->GetLocalGenerator()->ConvertToOutputFormat(
  438. cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
  439. ppCmds.push_back(
  440. cmake + " -E cmake_ninja_depends"
  441. " --tdi=" +
  442. tdi + " --pp=$out"
  443. " --dep=$DEP_FILE" +
  444. (needDyndep ? " --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE" : ""));
  445. std::string const ppCmdLine =
  446. this->GetLocalGenerator()->BuildCommandLine(ppCmds);
  447. // Write the rule for preprocessing file of the given language.
  448. std::ostringstream ppComment;
  449. ppComment << "Rule for preprocessing " << lang << " files.";
  450. std::ostringstream ppDesc;
  451. ppDesc << "Building " << lang << " preprocessed $out";
  452. this->GetGlobalGenerator()->AddRule(this->LanguagePreprocessRule(lang),
  453. ppCmdLine, ppDesc.str(),
  454. ppComment.str(), ppDepfile, ppDeptype,
  455. /*rspfile*/ "",
  456. /*rspcontent*/ "",
  457. /*restat*/ "",
  458. /*generator*/ false);
  459. }
  460. if (needDyndep) {
  461. // Write the rule for ninja dyndep file generation.
  462. std::vector<std::string> ddCmds;
  463. // Run CMake dependency scanner on preprocessed output.
  464. std::string const cmake = this->GetLocalGenerator()->ConvertToOutputFormat(
  465. cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
  466. ddCmds.push_back(cmake + " -E cmake_ninja_dyndep"
  467. " --tdi=" +
  468. tdi + " --dd=$out"
  469. " $in");
  470. std::string const ddCmdLine =
  471. this->GetLocalGenerator()->BuildCommandLine(ddCmds);
  472. std::ostringstream ddComment;
  473. ddComment << "Rule to generate ninja dyndep files for " << lang << ".";
  474. std::ostringstream ddDesc;
  475. ddDesc << "Generating " << lang << " dyndep file $out";
  476. this->GetGlobalGenerator()->AddRule(
  477. this->LanguageDyndepRule(lang), ddCmdLine, ddDesc.str(), ddComment.str(),
  478. /*depfile*/ "",
  479. /*deps*/ "",
  480. /*rspfile*/ "",
  481. /*rspcontent*/ "",
  482. /*restat*/ "",
  483. /*generator*/ false);
  484. }
  485. // Rule for compiling object file.
  486. const std::string cmdVar = std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
  487. std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
  488. std::vector<std::string> compileCmds;
  489. cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
  490. // Maybe insert an include-what-you-use runner.
  491. if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) {
  492. std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
  493. const char* iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
  494. std::string const tidy_prop = lang + "_CLANG_TIDY";
  495. const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
  496. if ((iwyu && *iwyu) || (tidy && *tidy)) {
  497. std::string run_iwyu = this->GetLocalGenerator()->ConvertToOutputFormat(
  498. cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
  499. run_iwyu += " -E __run_iwyu";
  500. if (iwyu && *iwyu) {
  501. run_iwyu += " --iwyu=";
  502. run_iwyu += this->GetLocalGenerator()->EscapeForShell(iwyu);
  503. }
  504. if (tidy && *tidy) {
  505. run_iwyu += " --tidy=";
  506. run_iwyu += this->GetLocalGenerator()->EscapeForShell(tidy);
  507. run_iwyu += " --source=$in";
  508. }
  509. run_iwyu += " -- ";
  510. compileCmds.front().insert(0, run_iwyu);
  511. }
  512. }
  513. // Maybe insert a compiler launcher like ccache or distcc
  514. if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) {
  515. std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
  516. const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
  517. if (clauncher && *clauncher) {
  518. std::vector<std::string> launcher_cmd;
  519. cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
  520. for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
  521. e = launcher_cmd.end();
  522. i != e; ++i) {
  523. *i = this->LocalGenerator->EscapeForShell(*i);
  524. }
  525. std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
  526. compileCmds.front().insert(0, run_launcher);
  527. }
  528. }
  529. if (!compileCmds.empty()) {
  530. compileCmds.front().insert(0, cldeps);
  531. }
  532. for (std::vector<std::string>::iterator i = compileCmds.begin();
  533. i != compileCmds.end(); ++i) {
  534. this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
  535. }
  536. std::string cmdLine =
  537. this->GetLocalGenerator()->BuildCommandLine(compileCmds);
  538. // Write the rule for compiling file of the given language.
  539. std::ostringstream comment;
  540. comment << "Rule for compiling " << lang << " files.";
  541. std::ostringstream description;
  542. description << "Building " << lang << " object $out";
  543. this->GetGlobalGenerator()->AddRule(
  544. this->LanguageCompilerRule(lang), cmdLine, description.str(),
  545. comment.str(), depfile, deptype, rspfile, rspcontent,
  546. /*restat*/ "",
  547. /*generator*/ false);
  548. }
  549. void cmNinjaTargetGenerator::WriteObjectBuildStatements()
  550. {
  551. // Write comments.
  552. cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
  553. this->GetBuildFileStream()
  554. << "# Object build statements for "
  555. << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
  556. << " target " << this->GetTargetName() << "\n\n";
  557. std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  558. std::vector<cmSourceFile const*> customCommands;
  559. this->GeneratorTarget->GetCustomCommands(customCommands, config);
  560. for (std::vector<cmSourceFile const*>::const_iterator si =
  561. customCommands.begin();
  562. si != customCommands.end(); ++si) {
  563. cmCustomCommand const* cc = (*si)->GetCustomCommand();
  564. this->GetLocalGenerator()->AddCustomCommandTarget(
  565. cc, this->GetGeneratorTarget());
  566. // Record the custom commands for this target. The container is used
  567. // in WriteObjectBuildStatement when called in a loop below.
  568. this->CustomCommands.push_back(cc);
  569. }
  570. std::vector<cmSourceFile const*> headerSources;
  571. this->GeneratorTarget->GetHeaderSources(headerSources, config);
  572. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  573. headerSources, this->MacOSXContentGenerator);
  574. std::vector<cmSourceFile const*> extraSources;
  575. this->GeneratorTarget->GetExtraSources(extraSources, config);
  576. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  577. extraSources, this->MacOSXContentGenerator);
  578. std::vector<cmSourceFile const*> externalObjects;
  579. this->GeneratorTarget->GetExternalObjects(externalObjects, config);
  580. for (std::vector<cmSourceFile const*>::const_iterator si =
  581. externalObjects.begin();
  582. si != externalObjects.end(); ++si) {
  583. this->Objects.push_back(this->GetSourceFilePath(*si));
  584. }
  585. cmNinjaDeps orderOnlyDeps;
  586. this->GetLocalGenerator()->AppendTargetDepends(this->GeneratorTarget,
  587. orderOnlyDeps);
  588. // Add order-only dependencies on other files associated with the target.
  589. orderOnlyDeps.insert(orderOnlyDeps.end(), this->ExtraFiles.begin(),
  590. this->ExtraFiles.end());
  591. // Add order-only dependencies on custom command outputs.
  592. for (std::vector<cmCustomCommand const*>::const_iterator cci =
  593. this->CustomCommands.begin();
  594. cci != this->CustomCommands.end(); ++cci) {
  595. cmCustomCommand const* cc = *cci;
  596. cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
  597. this->GetLocalGenerator());
  598. const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
  599. const std::vector<std::string>& ccbyproducts = ccg.GetByproducts();
  600. std::transform(ccoutputs.begin(), ccoutputs.end(),
  601. std::back_inserter(orderOnlyDeps), MapToNinjaPath());
  602. std::transform(ccbyproducts.begin(), ccbyproducts.end(),
  603. std::back_inserter(orderOnlyDeps), MapToNinjaPath());
  604. }
  605. if (!orderOnlyDeps.empty()) {
  606. cmNinjaDeps orderOnlyTarget;
  607. orderOnlyTarget.push_back(this->OrderDependsTargetForTarget());
  608. this->GetGlobalGenerator()->WritePhonyBuild(
  609. this->GetBuildFileStream(),
  610. "Order-only phony target for " + this->GetTargetName(), orderOnlyTarget,
  611. cmNinjaDeps(), cmNinjaDeps(), orderOnlyDeps);
  612. }
  613. std::vector<cmSourceFile const*> objectSources;
  614. this->GeneratorTarget->GetObjectSources(objectSources, config);
  615. for (std::vector<cmSourceFile const*>::const_iterator si =
  616. objectSources.begin();
  617. si != objectSources.end(); ++si) {
  618. this->WriteObjectBuildStatement(*si, !orderOnlyDeps.empty());
  619. }
  620. if (!this->DDIFiles.empty()) {
  621. std::string const ddComment;
  622. std::string const ddRule = this->LanguageDyndepRule("Fortran");
  623. cmNinjaDeps ddOutputs;
  624. cmNinjaDeps ddImplicitOuts;
  625. cmNinjaDeps const& ddExplicitDeps = this->DDIFiles;
  626. cmNinjaDeps ddImplicitDeps;
  627. cmNinjaDeps ddOrderOnlyDeps;
  628. cmNinjaVars ddVars;
  629. this->WriteTargetDependInfo("Fortran");
  630. ddOutputs.push_back(this->GetDyndepFilePath("Fortran"));
  631. this->GetGlobalGenerator()->WriteBuild(
  632. this->GetBuildFileStream(), ddComment, ddRule, ddOutputs, ddImplicitOuts,
  633. ddExplicitDeps, ddImplicitDeps, ddOrderOnlyDeps, ddVars);
  634. }
  635. this->GetBuildFileStream() << "\n";
  636. }
  637. void cmNinjaTargetGenerator::WriteObjectBuildStatement(
  638. cmSourceFile const* source, bool writeOrderDependsTargetForTarget)
  639. {
  640. std::string const language = source->GetLanguage();
  641. std::string const sourceFileName = this->GetSourceFilePath(source);
  642. std::string const objectDir =
  643. this->ConvertToNinjaPath(this->GeneratorTarget->GetSupportDirectory());
  644. std::string const objectFileName =
  645. this->ConvertToNinjaPath(this->GetObjectFilePath(source));
  646. std::string const objectFileDir =
  647. cmSystemTools::GetFilenamePath(objectFileName);
  648. cmNinjaVars vars;
  649. vars["IN_ABS"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  650. source->GetFullPath(), cmOutputConverter::SHELL);
  651. vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
  652. vars["DEFINES"] = this->ComputeDefines(source, language);
  653. vars["INCLUDES"] = this->GetIncludes(language);
  654. if (!this->NeedDepTypeMSVC(language)) {
  655. vars["DEP_FILE"] =
  656. cmGlobalNinjaGenerator::EncodeDepfileSpace(objectFileName + ".d");
  657. }
  658. this->ExportObjectCompileCommand(
  659. language, sourceFileName, objectDir, objectFileName, objectFileDir,
  660. vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"]);
  661. std::string comment;
  662. std::string rule = this->LanguageCompilerRule(language);
  663. cmNinjaDeps outputs;
  664. outputs.push_back(objectFileName);
  665. // Add this object to the list of object files.
  666. this->Objects.push_back(objectFileName);
  667. cmNinjaDeps explicitDeps;
  668. explicitDeps.push_back(sourceFileName);
  669. cmNinjaDeps implicitDeps;
  670. if (const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) {
  671. std::vector<std::string> depList;
  672. cmSystemTools::ExpandListArgument(objectDeps, depList);
  673. for (std::vector<std::string>::iterator odi = depList.begin();
  674. odi != depList.end(); ++odi) {
  675. if (cmSystemTools::FileIsFullPath(*odi)) {
  676. *odi = cmSystemTools::CollapseFullPath(*odi);
  677. }
  678. }
  679. std::transform(depList.begin(), depList.end(),
  680. std::back_inserter(implicitDeps), MapToNinjaPath());
  681. }
  682. cmNinjaDeps orderOnlyDeps;
  683. if (writeOrderDependsTargetForTarget) {
  684. orderOnlyDeps.push_back(this->OrderDependsTargetForTarget());
  685. }
  686. // If the source file is GENERATED and does not have a custom command
  687. // (either attached to this source file or another one), assume that one of
  688. // the target dependencies, OBJECT_DEPENDS or header file custom commands
  689. // will rebuild the file.
  690. if (source->GetPropertyAsBool("GENERATED") && !source->GetCustomCommand() &&
  691. !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) {
  692. this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName,
  693. orderOnlyDeps);
  694. }
  695. // For some cases we need to generate a ninja dyndep file.
  696. bool const needDyndep = this->NeedDyndep(language);
  697. // For some cases we do an explicit preprocessor invocation.
  698. bool const explicitPP = this->NeedExplicitPreprocessing(language);
  699. if (explicitPP) {
  700. std::string const ppComment;
  701. std::string const ppRule = this->LanguagePreprocessRule(language);
  702. cmNinjaDeps ppOutputs;
  703. cmNinjaDeps ppImplicitOuts;
  704. cmNinjaDeps ppExplicitDeps;
  705. cmNinjaDeps ppImplicitDeps;
  706. cmNinjaDeps ppOrderOnlyDeps;
  707. cmNinjaVars ppVars;
  708. std::string const ppFileName =
  709. this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source));
  710. ppOutputs.push_back(ppFileName);
  711. // Move compilation dependencies to the preprocessing build statement.
  712. std::swap(ppExplicitDeps, explicitDeps);
  713. std::swap(ppImplicitDeps, implicitDeps);
  714. std::swap(ppOrderOnlyDeps, orderOnlyDeps);
  715. std::swap(ppVars["IN_ABS"], vars["IN_ABS"]);
  716. // The actual compilation will now use the preprocessed source.
  717. explicitDeps.push_back(ppFileName);
  718. // Preprocessing and compilation use the same flags.
  719. ppVars["FLAGS"] = vars["FLAGS"];
  720. // Move preprocessor definitions to the preprocessor build statement.
  721. std::swap(ppVars["DEFINES"], vars["DEFINES"]);
  722. // Copy include directories to the preprocessor build statement. The
  723. // Fortran compilation build statement still needs them for the INCLUDE
  724. // directive.
  725. ppVars["INCLUDES"] = vars["INCLUDES"];
  726. // Prepend source file's original directory as an include directory
  727. // so e.g. Fortran INCLUDE statements can look for files in it.
  728. std::vector<std::string> sourceDirectory;
  729. sourceDirectory.push_back(
  730. cmSystemTools::GetParentDirectory(source->GetFullPath()));
  731. std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags(
  732. sourceDirectory, this->GeneratorTarget, language, false, false,
  733. this->GetConfigName());
  734. vars["INCLUDES"] = sourceDirectoryFlag + " " + vars["INCLUDES"];
  735. // Explicit preprocessing always uses a depfile.
  736. ppVars["DEP_FILE"] =
  737. cmGlobalNinjaGenerator::EncodeDepfileSpace(ppFileName + ".d");
  738. // The actual compilation does not need a depfile because it
  739. // depends on the already-preprocessed source.
  740. vars.erase("DEP_FILE");
  741. if (needDyndep) {
  742. // Tell dependency scanner the object file that will result from
  743. // compiling the preprocessed source.
  744. ppVars["OBJ_FILE"] = objectFileName;
  745. // Tell dependency scanner where to store dyndep intermediate results.
  746. std::string const ddiFile = ppFileName + ".ddi";
  747. ppVars["DYNDEP_INTERMEDIATE_FILE"] = ddiFile;
  748. ppImplicitOuts.push_back(ddiFile);
  749. this->DDIFiles.push_back(ddiFile);
  750. }
  751. this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
  752. ppVars);
  753. this->GetGlobalGenerator()->WriteBuild(
  754. this->GetBuildFileStream(), ppComment, ppRule, ppOutputs, ppImplicitOuts,
  755. ppExplicitDeps, ppImplicitDeps, ppOrderOnlyDeps, ppVars);
  756. }
  757. if (needDyndep) {
  758. std::string const dyndep = this->GetDyndepFilePath(language);
  759. orderOnlyDeps.push_back(dyndep);
  760. vars["dyndep"] = dyndep;
  761. }
  762. EnsureParentDirectoryExists(objectFileName);
  763. vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  764. objectDir, cmOutputConverter::SHELL);
  765. vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  766. objectFileDir, cmOutputConverter::SHELL);
  767. this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
  768. vars);
  769. this->SetMsvcTargetPdbVariable(vars);
  770. bool const isRC = (language == "RC");
  771. int const commandLineLengthLimit =
  772. ((!isRC && this->ForceResponseFile())) ? -1 : 0;
  773. std::string const rspfile = objectFileName + ".rsp";
  774. this->GetGlobalGenerator()->WriteBuild(
  775. this->GetBuildFileStream(), comment, rule, outputs,
  776. /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps, orderOnlyDeps,
  777. vars, rspfile, commandLineLengthLimit);
  778. if (const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
  779. std::vector<std::string> outputList;
  780. cmSystemTools::ExpandListArgument(objectOutputs, outputList);
  781. std::transform(outputList.begin(), outputList.end(), outputList.begin(),
  782. MapToNinjaPath());
  783. this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
  784. "Additional output files.",
  785. outputList, outputs);
  786. }
  787. }
  788. void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang)
  789. {
  790. Json::Value tdi(Json::objectValue);
  791. tdi["language"] = lang;
  792. tdi["compiler-id"] =
  793. this->Makefile->GetSafeDefinition("CMAKE_" + lang + "_COMPILER_ID");
  794. if (lang == "Fortran") {
  795. std::string mod_dir = this->GeneratorTarget->GetFortranModuleDirectory(
  796. this->Makefile->GetHomeOutputDirectory());
  797. if (mod_dir.empty()) {
  798. mod_dir = this->Makefile->GetCurrentBinaryDirectory();
  799. }
  800. tdi["module-dir"] = mod_dir;
  801. }
  802. tdi["dir-cur-bld"] = this->Makefile->GetCurrentBinaryDirectory();
  803. tdi["dir-cur-src"] = this->Makefile->GetCurrentSourceDirectory();
  804. tdi["dir-top-bld"] = this->Makefile->GetHomeOutputDirectory();
  805. tdi["dir-top-src"] = this->Makefile->GetHomeDirectory();
  806. Json::Value& tdi_include_dirs = tdi["include-dirs"] = Json::arrayValue;
  807. std::vector<std::string> includes;
  808. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  809. lang, this->GetConfigName());
  810. for (std::vector<std::string>::iterator i = includes.begin();
  811. i != includes.end(); ++i) {
  812. tdi_include_dirs.append(*i);
  813. }
  814. Json::Value& tdi_linked_target_dirs = tdi["linked-target-dirs"] =
  815. Json::arrayValue;
  816. std::vector<std::string> linked = this->GetLinkedTargetDirectories();
  817. for (std::vector<std::string>::iterator i = linked.begin();
  818. i != linked.end(); ++i) {
  819. tdi_linked_target_dirs.append(*i);
  820. }
  821. std::string const tdin = this->GetTargetDependInfoPath(lang);
  822. cmGeneratedFileStream tdif(tdin.c_str());
  823. tdif << tdi;
  824. }
  825. void cmNinjaTargetGenerator::ExportObjectCompileCommand(
  826. std::string const& language, std::string const& sourceFileName,
  827. std::string const& objectDir, std::string const& objectFileName,
  828. std::string const& objectFileDir, std::string const& flags,
  829. std::string const& defines, std::string const& includes)
  830. {
  831. if (!this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS")) {
  832. return;
  833. }
  834. cmLocalGenerator::RuleVariables compileObjectVars;
  835. compileObjectVars.Language = language.c_str();
  836. std::string escapedSourceFileName = sourceFileName;
  837. if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str())) {
  838. escapedSourceFileName = cmSystemTools::CollapseFullPath(
  839. escapedSourceFileName, this->GetGlobalGenerator()
  840. ->GetCMakeInstance()
  841. ->GetHomeOutputDirectory());
  842. }
  843. escapedSourceFileName = this->LocalGenerator->ConvertToOutputFormat(
  844. escapedSourceFileName, cmOutputConverter::SHELL);
  845. compileObjectVars.Source = escapedSourceFileName.c_str();
  846. compileObjectVars.Object = objectFileName.c_str();
  847. compileObjectVars.ObjectDir = objectDir.c_str();
  848. compileObjectVars.ObjectFileDir = objectFileDir.c_str();
  849. compileObjectVars.Flags = flags.c_str();
  850. compileObjectVars.Defines = defines.c_str();
  851. compileObjectVars.Includes = includes.c_str();
  852. // Rule for compiling object file.
  853. std::string compileCmdVar = "CMAKE_";
  854. compileCmdVar += language;
  855. compileCmdVar += "_COMPILE_OBJECT";
  856. std::string compileCmd =
  857. this->GetMakefile()->GetRequiredDefinition(compileCmdVar);
  858. std::vector<std::string> compileCmds;
  859. cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
  860. for (std::vector<std::string>::iterator i = compileCmds.begin();
  861. i != compileCmds.end(); ++i) {
  862. this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars);
  863. }
  864. std::string cmdLine =
  865. this->GetLocalGenerator()->BuildCommandLine(compileCmds);
  866. this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName);
  867. }
  868. void cmNinjaTargetGenerator::EnsureDirectoryExists(
  869. const std::string& path) const
  870. {
  871. if (cmSystemTools::FileIsFullPath(path.c_str())) {
  872. cmSystemTools::MakeDirectory(path.c_str());
  873. } else {
  874. cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
  875. std::string fullPath =
  876. std::string(gg->GetCMakeInstance()->GetHomeOutputDirectory());
  877. // Also ensures their is a trailing slash.
  878. gg->StripNinjaOutputPathPrefixAsSuffix(fullPath);
  879. fullPath += path;
  880. cmSystemTools::MakeDirectory(fullPath.c_str());
  881. }
  882. }
  883. void cmNinjaTargetGenerator::EnsureParentDirectoryExists(
  884. const std::string& path) const
  885. {
  886. EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path));
  887. }
  888. void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
  889. cmSourceFile const& source, const char* pkgloc)
  890. {
  891. // Skip OS X content when not building a Framework or Bundle.
  892. if (!this->Generator->GetGeneratorTarget()->IsBundleOnApple()) {
  893. return;
  894. }
  895. std::string macdir =
  896. this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
  897. // Get the input file location.
  898. std::string input = source.GetFullPath();
  899. input = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(input);
  900. // Get the output file location.
  901. std::string output = macdir;
  902. output += "/";
  903. output += cmSystemTools::GetFilenameName(input);
  904. output = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(output);
  905. // Write a build statement to copy the content into the bundle.
  906. this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input,
  907. output);
  908. // Add as a dependency to the target so that it gets called.
  909. this->Generator->ExtraFiles.push_back(output);
  910. }
  911. void cmNinjaTargetGenerator::addPoolNinjaVariable(
  912. const std::string& pool_property, cmGeneratorTarget* target,
  913. cmNinjaVars& vars)
  914. {
  915. const char* pool = target->GetProperty(pool_property);
  916. if (pool) {
  917. vars["pool"] = pool;
  918. }
  919. }
  920. bool cmNinjaTargetGenerator::ForceResponseFile()
  921. {
  922. static std::string const forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE";
  923. return (this->GetMakefile()->IsDefinitionSet(forceRspFile) ||
  924. cmSystemTools::HasEnv(forceRspFile));
  925. }