cmNinjaTargetGenerator.cxx 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  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 <algorithm>
  5. #include <cassert>
  6. #include <iterator>
  7. #include <map>
  8. #include <ostream>
  9. #include <utility>
  10. #include <cm/memory>
  11. #include <cmext/algorithm>
  12. #include "cm_jsoncpp_value.h"
  13. #include "cm_jsoncpp_writer.h"
  14. #include "cmComputeLinkInformation.h"
  15. #include "cmCustomCommandGenerator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmGeneratorExpression.h"
  18. #include "cmGeneratorTarget.h"
  19. #include "cmGlobalNinjaGenerator.h"
  20. #include "cmLocalGenerator.h"
  21. #include "cmLocalNinjaGenerator.h"
  22. #include "cmMakefile.h"
  23. #include "cmNinjaNormalTargetGenerator.h"
  24. #include "cmNinjaUtilityTargetGenerator.h"
  25. #include "cmOutputConverter.h"
  26. #include "cmRange.h"
  27. #include "cmRulePlaceholderExpander.h"
  28. #include "cmSourceFile.h"
  29. #include "cmState.h"
  30. #include "cmStateTypes.h"
  31. #include "cmStringAlgorithms.h"
  32. #include "cmSystemTools.h"
  33. #include "cmake.h"
  34. std::unique_ptr<cmNinjaTargetGenerator> cmNinjaTargetGenerator::New(
  35. cmGeneratorTarget* target)
  36. {
  37. switch (target->GetType()) {
  38. case cmStateEnums::EXECUTABLE:
  39. case cmStateEnums::SHARED_LIBRARY:
  40. case cmStateEnums::STATIC_LIBRARY:
  41. case cmStateEnums::MODULE_LIBRARY:
  42. case cmStateEnums::OBJECT_LIBRARY:
  43. return cm::make_unique<cmNinjaNormalTargetGenerator>(target);
  44. case cmStateEnums::UTILITY:
  45. case cmStateEnums::GLOBAL_TARGET:
  46. return cm::make_unique<cmNinjaUtilityTargetGenerator>(target);
  47. default:
  48. return std::unique_ptr<cmNinjaTargetGenerator>();
  49. }
  50. }
  51. cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
  52. : cmCommonTargetGenerator(target)
  53. , OSXBundleGenerator(nullptr)
  54. , LocalGenerator(
  55. static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator()))
  56. {
  57. for (auto const& fileConfig : target->Makefile->GetGeneratorConfigs()) {
  58. this->Configs[fileConfig].MacOSXContentGenerator =
  59. cm::make_unique<MacOSXContentGeneratorType>(this, fileConfig);
  60. }
  61. }
  62. cmNinjaTargetGenerator::~cmNinjaTargetGenerator() = default;
  63. cmGeneratedFileStream& cmNinjaTargetGenerator::GetImplFileStream(
  64. const std::string& config) const
  65. {
  66. return *this->GetGlobalGenerator()->GetImplFileStream(config);
  67. }
  68. cmGeneratedFileStream& cmNinjaTargetGenerator::GetCommonFileStream() const
  69. {
  70. return *this->GetGlobalGenerator()->GetCommonFileStream();
  71. }
  72. cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const
  73. {
  74. return *this->GetGlobalGenerator()->GetRulesFileStream();
  75. }
  76. cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
  77. {
  78. return this->LocalGenerator->GetGlobalNinjaGenerator();
  79. }
  80. std::string cmNinjaTargetGenerator::LanguageCompilerRule(
  81. const std::string& lang, const std::string& config) const
  82. {
  83. return cmStrCat(
  84. lang, "_COMPILER__",
  85. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
  86. '_', config);
  87. }
  88. std::string cmNinjaTargetGenerator::LanguagePreprocessRule(
  89. std::string const& lang, const std::string& config) const
  90. {
  91. return cmStrCat(
  92. lang, "_PREPROCESS__",
  93. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
  94. '_', config);
  95. }
  96. bool cmNinjaTargetGenerator::NeedExplicitPreprocessing(
  97. std::string const& lang) const
  98. {
  99. return lang == "Fortran";
  100. }
  101. bool cmNinjaTargetGenerator::UsePreprocessedSource(
  102. std::string const& lang) const
  103. {
  104. return lang == "Fortran";
  105. }
  106. bool cmNinjaTargetGenerator::CompilePreprocessedSourceWithDefines(
  107. std::string const& lang) const
  108. {
  109. return this->Makefile->IsOn(
  110. cmStrCat("CMAKE_", lang, "_COMPILE_WITH_DEFINES"));
  111. }
  112. std::string cmNinjaTargetGenerator::LanguageDyndepRule(
  113. const std::string& lang, const std::string& config) const
  114. {
  115. return cmStrCat(
  116. lang, "_DYNDEP__",
  117. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
  118. '_', config);
  119. }
  120. bool cmNinjaTargetGenerator::NeedDyndep(std::string const& lang) const
  121. {
  122. return lang == "Fortran";
  123. }
  124. std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget(
  125. const std::string& config)
  126. {
  127. return cmGlobalNinjaGenerator::OrderDependsTargetForTarget(
  128. this->GeneratorTarget, config);
  129. }
  130. // TODO: Most of the code is picked up from
  131. // void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink),
  132. // void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
  133. // Refactor it.
  134. std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
  135. cmSourceFile const* source, const std::string& language,
  136. const std::string& config)
  137. {
  138. std::string flags = this->GetFlags(language, config);
  139. // Add Fortran format flags.
  140. if (language == "Fortran") {
  141. this->AppendFortranFormatFlags(flags, *source);
  142. }
  143. // Add source file specific flags.
  144. cmGeneratorExpressionInterpreter genexInterpreter(
  145. this->LocalGenerator, config, this->GeneratorTarget, language);
  146. const std::string COMPILE_FLAGS("COMPILE_FLAGS");
  147. if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
  148. this->LocalGenerator->AppendFlags(
  149. flags, genexInterpreter.Evaluate(cflags, COMPILE_FLAGS));
  150. }
  151. const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
  152. if (const char* coptions = source->GetProperty(COMPILE_OPTIONS)) {
  153. this->LocalGenerator->AppendCompileOptions(
  154. flags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
  155. }
  156. // Add precompile headers compile options.
  157. const std::string pchSource =
  158. this->GeneratorTarget->GetPchSource(config, language);
  159. if (!pchSource.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  160. std::string pchOptions;
  161. if (source->GetFullPath() == pchSource) {
  162. pchOptions =
  163. this->GeneratorTarget->GetPchCreateCompileOptions(config, language);
  164. } else {
  165. pchOptions =
  166. this->GeneratorTarget->GetPchUseCompileOptions(config, language);
  167. }
  168. this->LocalGenerator->AppendCompileOptions(
  169. flags, genexInterpreter.Evaluate(pchOptions, COMPILE_OPTIONS));
  170. }
  171. return flags;
  172. }
  173. void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
  174. std::string const& language,
  175. const std::string& config)
  176. {
  177. std::vector<std::string> includes;
  178. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  179. language, config);
  180. // Add include directory flags.
  181. std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
  182. includes, this->GeneratorTarget, language,
  183. language == "RC", // full include paths for RC needed by cmcldeps
  184. false, config);
  185. if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
  186. std::replace(includeFlags.begin(), includeFlags.end(), '\\', '/');
  187. }
  188. this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
  189. }
  190. bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const
  191. {
  192. std::string const& deptype = this->GetMakefile()->GetSafeDefinition(
  193. cmStrCat("CMAKE_NINJA_DEPTYPE_", lang));
  194. if (deptype == "msvc") {
  195. return true;
  196. }
  197. if (deptype == "intel") {
  198. // Ninja does not really define "intel", but we use it to switch based
  199. // on whether this environment supports "gcc" or "msvc" deptype.
  200. if (!this->GetGlobalGenerator()->SupportsMultilineDepfile()) {
  201. // This ninja version is too old to support the Intel depfile format.
  202. // Fall back to msvc deptype.
  203. return true;
  204. }
  205. if ((this->Makefile->GetHomeDirectory().find(' ') != std::string::npos) ||
  206. (this->Makefile->GetHomeOutputDirectory().find(' ') !=
  207. std::string::npos)) {
  208. // The Intel compiler does not properly escape spaces in a depfile.
  209. // Fall back to msvc deptype.
  210. return true;
  211. }
  212. }
  213. return false;
  214. }
  215. // TODO: Refactor with
  216. // void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
  217. std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
  218. const std::string& language,
  219. const std::string& config)
  220. {
  221. std::set<std::string> defines;
  222. cmGeneratorExpressionInterpreter genexInterpreter(
  223. this->LocalGenerator, config, this->GeneratorTarget, language);
  224. // Seriously??
  225. if (this->GetGlobalGenerator()->IsMultiConfig()) {
  226. defines.insert(cmStrCat("CMAKE_INTDIR=\"", config, '"'));
  227. }
  228. const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
  229. if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
  230. this->LocalGenerator->AppendDefines(
  231. defines, genexInterpreter.Evaluate(compile_defs, COMPILE_DEFINITIONS));
  232. }
  233. std::string defPropName =
  234. cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(config));
  235. if (const char* config_compile_defs = source->GetProperty(defPropName)) {
  236. this->LocalGenerator->AppendDefines(
  237. defines,
  238. genexInterpreter.Evaluate(config_compile_defs, COMPILE_DEFINITIONS));
  239. }
  240. std::string definesString = this->GetDefines(language, config);
  241. this->LocalGenerator->JoinDefines(defines, definesString, language);
  242. return definesString;
  243. }
  244. std::string cmNinjaTargetGenerator::ComputeIncludes(
  245. cmSourceFile const* source, const std::string& language,
  246. const std::string& config)
  247. {
  248. std::vector<std::string> includes;
  249. cmGeneratorExpressionInterpreter genexInterpreter(
  250. this->LocalGenerator, config, this->GeneratorTarget, language);
  251. const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
  252. if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
  253. this->LocalGenerator->AppendIncludeDirectories(
  254. includes, genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES),
  255. *source);
  256. }
  257. std::string includesString = this->LocalGenerator->GetIncludeFlags(
  258. includes, this->GeneratorTarget, language, true, false, config);
  259. this->LocalGenerator->AppendFlags(includesString,
  260. this->GetIncludes(language, config));
  261. return includesString;
  262. }
  263. cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps(
  264. const std::string& linkLanguage, const std::string& config) const
  265. {
  266. // Static libraries never depend on other targets for linking.
  267. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  268. this->GeneratorTarget->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  269. return cmNinjaDeps();
  270. }
  271. cmComputeLinkInformation* cli =
  272. this->GeneratorTarget->GetLinkInformation(config);
  273. if (!cli) {
  274. return cmNinjaDeps();
  275. }
  276. const std::vector<std::string>& deps = cli->GetDepends();
  277. cmNinjaDeps result(deps.size());
  278. std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
  279. // Add a dependency on the link definitions file, if any.
  280. if (cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  281. this->GeneratorTarget->GetModuleDefinitionInfo(config)) {
  282. for (cmSourceFile const* src : mdi->Sources) {
  283. result.push_back(this->ConvertToNinjaPath(src->GetFullPath()));
  284. }
  285. }
  286. // Add a dependency on user-specified manifest files, if any.
  287. std::vector<cmSourceFile const*> manifest_srcs;
  288. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  289. for (cmSourceFile const* manifest_src : manifest_srcs) {
  290. result.push_back(this->ConvertToNinjaPath(manifest_src->GetFullPath()));
  291. }
  292. // Add user-specified dependencies.
  293. std::vector<std::string> linkDeps;
  294. this->GeneratorTarget->GetLinkDepends(linkDeps, config, linkLanguage);
  295. std::transform(linkDeps.begin(), linkDeps.end(), std::back_inserter(result),
  296. MapToNinjaPath());
  297. return result;
  298. }
  299. std::string cmNinjaTargetGenerator::GetSourceFilePath(
  300. cmSourceFile const* source) const
  301. {
  302. return ConvertToNinjaPath(source->GetFullPath());
  303. }
  304. std::string cmNinjaTargetGenerator::GetObjectFilePath(
  305. cmSourceFile const* source, const std::string& config) const
  306. {
  307. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  308. if (!path.empty()) {
  309. path += '/';
  310. }
  311. std::string const& objectName = this->GeneratorTarget->GetObjectName(source);
  312. path += cmStrCat(
  313. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  314. this->GetGlobalGenerator()->ConfigDirectory(config), '/', objectName);
  315. return path;
  316. }
  317. std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
  318. cmSourceFile const* source, const std::string& config) const
  319. {
  320. // Choose an extension to compile already-preprocessed source.
  321. std::string ppExt = source->GetExtension();
  322. if (cmHasLiteralPrefix(ppExt, "F")) {
  323. // Some Fortran compilers automatically enable preprocessing for
  324. // upper-case extensions. Since the source is already preprocessed,
  325. // use a lower-case extension.
  326. ppExt = cmSystemTools::LowerCase(ppExt);
  327. }
  328. if (ppExt == "fpp") {
  329. // Some Fortran compilers automatically enable preprocessing for
  330. // the ".fpp" extension. Since the source is already preprocessed,
  331. // use the ".f" extension.
  332. ppExt = "f";
  333. }
  334. // Take the object file name and replace the extension.
  335. std::string const& objName = this->GeneratorTarget->GetObjectName(source);
  336. std::string const& objExt =
  337. this->GetGlobalGenerator()->GetLanguageOutputExtension(*source);
  338. assert(objName.size() >= objExt.size());
  339. std::string const ppName =
  340. cmStrCat(objName.substr(0, objName.size() - objExt.size()), "-pp.", ppExt);
  341. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  342. if (!path.empty()) {
  343. path += '/';
  344. }
  345. path +=
  346. cmStrCat(this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  347. this->GetGlobalGenerator()->ConfigDirectory(config), '/', ppName);
  348. return path;
  349. }
  350. std::string cmNinjaTargetGenerator::GetDyndepFilePath(
  351. std::string const& lang, const std::string& config) const
  352. {
  353. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  354. if (!path.empty()) {
  355. path += '/';
  356. }
  357. path += cmStrCat(
  358. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  359. this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang, ".dd");
  360. return path;
  361. }
  362. std::string cmNinjaTargetGenerator::GetTargetDependInfoPath(
  363. std::string const& lang, const std::string& config) const
  364. {
  365. std::string path =
  366. cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
  367. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  368. this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang,
  369. "DependInfo.json");
  370. return path;
  371. }
  372. std::string cmNinjaTargetGenerator::GetTargetOutputDir(
  373. const std::string& config) const
  374. {
  375. std::string dir = this->GeneratorTarget->GetDirectory(config);
  376. return ConvertToNinjaPath(dir);
  377. }
  378. std::string cmNinjaTargetGenerator::GetTargetFilePath(
  379. const std::string& name, const std::string& config) const
  380. {
  381. std::string path = this->GetTargetOutputDir(config);
  382. if (path.empty() || path == ".") {
  383. return name;
  384. }
  385. path += cmStrCat('/', name);
  386. return path;
  387. }
  388. std::string cmNinjaTargetGenerator::GetTargetName() const
  389. {
  390. return this->GeneratorTarget->GetName();
  391. }
  392. bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(
  393. cmNinjaVars& vars, const std::string& config) const
  394. {
  395. cmMakefile* mf = this->GetMakefile();
  396. if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
  397. mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID") ||
  398. mf->GetDefinition("MSVC_CUDA_ARCHITECTURE_ID")) {
  399. std::string pdbPath;
  400. std::string compilePdbPath = this->ComputeTargetCompilePDB(config);
  401. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  402. this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  403. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  404. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  405. pdbPath = cmStrCat(this->GeneratorTarget->GetPDBDirectory(config), '/',
  406. this->GeneratorTarget->GetPDBName(config));
  407. }
  408. vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  409. ConvertToNinjaPath(pdbPath), cmOutputConverter::SHELL);
  410. vars["TARGET_COMPILE_PDB"] =
  411. this->GetLocalGenerator()->ConvertToOutputFormat(
  412. ConvertToNinjaPath(compilePdbPath), cmOutputConverter::SHELL);
  413. EnsureParentDirectoryExists(pdbPath);
  414. EnsureParentDirectoryExists(compilePdbPath);
  415. return true;
  416. }
  417. return false;
  418. }
  419. void cmNinjaTargetGenerator::WriteLanguageRules(const std::string& language,
  420. const std::string& config)
  421. {
  422. #ifdef NINJA_GEN_VERBOSE_FILES
  423. this->GetRulesFileStream() << "# Rules for language " << language << "\n\n";
  424. #endif
  425. this->WriteCompileRule(language, config);
  426. }
  427. void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
  428. const std::string& config)
  429. {
  430. cmRulePlaceholderExpander::RuleVariables vars;
  431. vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
  432. vars.CMTargetType =
  433. cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()).c_str();
  434. vars.Language = lang.c_str();
  435. vars.Source = "$in";
  436. vars.Object = "$out";
  437. vars.Defines = "$DEFINES";
  438. vars.Includes = "$INCLUDES";
  439. vars.TargetPDB = "$TARGET_PDB";
  440. vars.TargetCompilePDB = "$TARGET_COMPILE_PDB";
  441. vars.ObjectDir = "$OBJECT_DIR";
  442. vars.ObjectFileDir = "$OBJECT_FILE_DIR";
  443. cmMakefile* mf = this->GetMakefile();
  444. // For some cases we do an explicit preprocessor invocation.
  445. bool const explicitPP = this->NeedExplicitPreprocessing(lang);
  446. bool const compilePPWithDefines = this->UsePreprocessedSource(lang) &&
  447. this->CompilePreprocessedSourceWithDefines(lang);
  448. bool const needDyndep = this->NeedDyndep(lang);
  449. std::string flags = "$FLAGS";
  450. std::string responseFlag;
  451. bool const lang_supports_response = lang != "RC";
  452. if (lang_supports_response && this->ForceResponseFile()) {
  453. std::string const responseFlagVar =
  454. cmStrCat("CMAKE_", lang, "_RESPONSE_FILE_FLAG");
  455. responseFlag = this->Makefile->GetSafeDefinition(responseFlagVar);
  456. if (responseFlag.empty() && lang != "CUDA") {
  457. responseFlag = "@";
  458. }
  459. }
  460. std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
  461. this->GetLocalGenerator()->CreateRulePlaceholderExpander());
  462. std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat(
  463. ConvertToNinjaPath(this->GetTargetDependInfoPath(lang, config)),
  464. cmLocalGenerator::SHELL);
  465. std::string launcher;
  466. const char* val = this->GetLocalGenerator()->GetRuleLauncher(
  467. this->GetGeneratorTarget(), "RULE_LAUNCH_COMPILE");
  468. if (val && *val) {
  469. launcher = cmStrCat(val, ' ');
  470. }
  471. std::string const cmakeCmd =
  472. this->GetLocalGenerator()->ConvertToOutputFormat(
  473. cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
  474. if (explicitPP) {
  475. cmNinjaRule rule(this->LanguagePreprocessRule(lang, config));
  476. // Explicit preprocessing always uses a depfile.
  477. rule.DepType = ""; // no deps= for multiple outputs
  478. rule.DepFile = "$DEP_FILE";
  479. cmRulePlaceholderExpander::RuleVariables ppVars;
  480. ppVars.CMTargetName = vars.CMTargetName;
  481. ppVars.CMTargetType = vars.CMTargetType;
  482. ppVars.Language = vars.Language;
  483. ppVars.Object = "$out"; // for RULE_LAUNCH_COMPILE
  484. ppVars.PreprocessedSource = "$out";
  485. ppVars.DependencyFile = rule.DepFile.c_str();
  486. // Preprocessing uses the original source,
  487. // compilation uses preprocessed output.
  488. ppVars.Source = vars.Source;
  489. vars.Source = "$in";
  490. // Preprocessing and compilation use the same flags.
  491. std::string ppFlags = flags;
  492. if (!compilePPWithDefines) {
  493. // Move preprocessor definitions to the preprocessor rule.
  494. ppVars.Defines = vars.Defines;
  495. vars.Defines = "";
  496. } else {
  497. // Copy preprocessor definitions to the preprocessor rule.
  498. ppVars.Defines = vars.Defines;
  499. }
  500. // Copy include directories to the preprocessor rule. The Fortran
  501. // compilation rule still needs them for the INCLUDE directive.
  502. ppVars.Includes = vars.Includes;
  503. // If using a response file, move defines, includes, and flags into it.
  504. if (!responseFlag.empty()) {
  505. rule.RspFile = "$RSP_FILE";
  506. rule.RspContent =
  507. cmStrCat(' ', ppVars.Defines, ' ', ppVars.Includes, ' ', ppFlags);
  508. ppFlags = cmStrCat(responseFlag, rule.RspFile);
  509. ppVars.Defines = "";
  510. ppVars.Includes = "";
  511. }
  512. ppVars.Flags = ppFlags.c_str();
  513. // Rule for preprocessing source file.
  514. std::vector<std::string> ppCmds;
  515. {
  516. // Lookup the explicit preprocessing rule.
  517. std::string ppVar = cmStrCat("CMAKE_", lang, "_PREPROCESS_SOURCE");
  518. cmExpandList(this->GetMakefile()->GetRequiredDefinition(ppVar), ppCmds);
  519. }
  520. for (std::string& i : ppCmds) {
  521. i = cmStrCat(launcher, i);
  522. rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
  523. i, ppVars);
  524. }
  525. // Run CMake dependency scanner on preprocessed output.
  526. {
  527. std::string ccmd =
  528. cmStrCat(cmakeCmd, " -E cmake_ninja_depends --tdi=", tdi,
  529. " --lang=", lang, " --pp=$out --dep=$DEP_FILE");
  530. if (needDyndep) {
  531. ccmd += " --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE";
  532. }
  533. ppCmds.emplace_back(std::move(ccmd));
  534. }
  535. rule.Command = this->GetLocalGenerator()->BuildCommandLine(ppCmds);
  536. // Write the rule for preprocessing file of the given language.
  537. rule.Comment = cmStrCat("Rule for preprocessing ", lang, " files.");
  538. rule.Description = cmStrCat("Building ", lang, " preprocessed $out");
  539. this->GetGlobalGenerator()->AddRule(rule);
  540. }
  541. if (needDyndep) {
  542. // Write the rule for ninja dyndep file generation.
  543. cmNinjaRule rule(this->LanguageDyndepRule(lang, config));
  544. // Command line length is almost always limited -> use response file for
  545. // dyndep rules
  546. rule.RspFile = "$out.rsp";
  547. rule.RspContent = "$in";
  548. // Run CMake dependency scanner on the source file (using the preprocessed
  549. // source if that was performed).
  550. {
  551. std::vector<std::string> ddCmds;
  552. {
  553. std::string ccmd =
  554. cmStrCat(cmakeCmd, " -E cmake_ninja_dyndep --tdi=", tdi,
  555. " --lang=", lang, " --dd=$out @", rule.RspFile);
  556. ddCmds.emplace_back(std::move(ccmd));
  557. }
  558. rule.Command = this->GetLocalGenerator()->BuildCommandLine(ddCmds);
  559. }
  560. rule.Comment =
  561. cmStrCat("Rule to generate ninja dyndep files for ", lang, '.');
  562. rule.Description = cmStrCat("Generating ", lang, " dyndep file $out");
  563. this->GetGlobalGenerator()->AddRule(rule);
  564. }
  565. cmNinjaRule rule(this->LanguageCompilerRule(lang, config));
  566. // If using a response file, move defines, includes, and flags into it.
  567. if (!responseFlag.empty()) {
  568. rule.RspFile = "$RSP_FILE";
  569. rule.RspContent =
  570. cmStrCat(' ', vars.Defines, ' ', vars.Includes, ' ', flags);
  571. flags = cmStrCat(responseFlag, rule.RspFile);
  572. vars.Defines = "";
  573. vars.Includes = "";
  574. }
  575. // Tell ninja dependency format so all deps can be loaded into a database
  576. std::string cldeps;
  577. if (explicitPP) {
  578. // The explicit preprocessing step will handle dependency scanning.
  579. } else if (this->NeedDepTypeMSVC(lang)) {
  580. rule.DepType = "msvc";
  581. rule.DepFile.clear();
  582. flags += " /showIncludes";
  583. } else if (mf->IsOn(cmStrCat("CMAKE_NINJA_CMCLDEPS_", lang))) {
  584. // For the MS resource compiler we need cmcldeps, but skip dependencies
  585. // for source-file try_compile cases because they are always fresh.
  586. if (!mf->GetIsSourceFileTryCompile()) {
  587. rule.DepType = "gcc";
  588. rule.DepFile = "$DEP_FILE";
  589. const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER")
  590. ? mf->GetSafeDefinition("CMAKE_C_COMPILER")
  591. : mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
  592. cldeps = cmStrCat('"', cmSystemTools::GetCMClDepsCommand(), "\" ", lang,
  593. ' ', vars.Source, " $DEP_FILE $out \"",
  594. mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"),
  595. "\" \"", cl, "\" ");
  596. }
  597. } else {
  598. rule.DepType = "gcc";
  599. rule.DepFile = "$DEP_FILE";
  600. const std::string flagsName = cmStrCat("CMAKE_DEPFILE_FLAGS_", lang);
  601. std::string depfileFlags = mf->GetSafeDefinition(flagsName);
  602. if (!depfileFlags.empty()) {
  603. cmSystemTools::ReplaceString(depfileFlags, "<DEPFILE>", "$DEP_FILE");
  604. cmSystemTools::ReplaceString(depfileFlags, "<OBJECT>", "$out");
  605. cmSystemTools::ReplaceString(depfileFlags, "<CMAKE_C_COMPILER>",
  606. mf->GetDefinition("CMAKE_C_COMPILER"));
  607. flags += cmStrCat(' ', depfileFlags);
  608. }
  609. }
  610. vars.Flags = flags.c_str();
  611. vars.DependencyFile = rule.DepFile.c_str();
  612. // Rule for compiling object file.
  613. std::vector<std::string> compileCmds;
  614. if (lang == "CUDA") {
  615. std::string cmdVar;
  616. if (this->GeneratorTarget->GetPropertyAsBool(
  617. "CUDA_SEPARABLE_COMPILATION")) {
  618. cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION";
  619. } else if (this->GeneratorTarget->GetPropertyAsBool(
  620. "CUDA_PTX_COMPILATION")) {
  621. cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION";
  622. } else {
  623. cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION";
  624. }
  625. const std::string& compileCmd = mf->GetRequiredDefinition(cmdVar);
  626. cmExpandList(compileCmd, compileCmds);
  627. } else {
  628. const std::string cmdVar = cmStrCat("CMAKE_", lang, "_COMPILE_OBJECT");
  629. const std::string& compileCmd = mf->GetRequiredDefinition(cmdVar);
  630. cmExpandList(compileCmd, compileCmds);
  631. }
  632. // See if we need to use a compiler launcher like ccache or distcc
  633. std::string compilerLauncher;
  634. if (!compileCmds.empty() &&
  635. (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" ||
  636. lang == "OBJC" || lang == "OBJCXX")) {
  637. std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER");
  638. const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
  639. if (clauncher && *clauncher) {
  640. compilerLauncher = clauncher;
  641. }
  642. }
  643. // Maybe insert an include-what-you-use runner.
  644. if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) {
  645. std::string const iwyu_prop = cmStrCat(lang, "_INCLUDE_WHAT_YOU_USE");
  646. const char* iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
  647. std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
  648. const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
  649. std::string const cpplint_prop = cmStrCat(lang, "_CPPLINT");
  650. const char* cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
  651. std::string const cppcheck_prop = cmStrCat(lang, "_CPPCHECK");
  652. const char* cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
  653. if ((iwyu && *iwyu) || (tidy && *tidy) || (cpplint && *cpplint) ||
  654. (cppcheck && *cppcheck)) {
  655. std::string run_iwyu = cmStrCat(cmakeCmd, " -E __run_co_compile");
  656. if (!compilerLauncher.empty()) {
  657. // In __run_co_compile case the launcher command is supplied
  658. // via --launcher=<maybe-list> and consumed
  659. run_iwyu +=
  660. cmStrCat(" --launcher=",
  661. this->LocalGenerator->EscapeForShell(compilerLauncher));
  662. compilerLauncher.clear();
  663. }
  664. if (iwyu && *iwyu) {
  665. run_iwyu += cmStrCat(" --iwyu=",
  666. this->GetLocalGenerator()->EscapeForShell(iwyu));
  667. }
  668. if (tidy && *tidy) {
  669. run_iwyu += " --tidy=";
  670. const char* driverMode = this->Makefile->GetDefinition(
  671. cmStrCat("CMAKE_", lang, "_CLANG_TIDY_DRIVER_MODE"));
  672. if (!(driverMode && *driverMode)) {
  673. driverMode = lang == "C" ? "gcc" : "g++";
  674. }
  675. run_iwyu += this->GetLocalGenerator()->EscapeForShell(
  676. cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode));
  677. }
  678. if (cpplint && *cpplint) {
  679. run_iwyu += cmStrCat(
  680. " --cpplint=", this->GetLocalGenerator()->EscapeForShell(cpplint));
  681. }
  682. if (cppcheck && *cppcheck) {
  683. run_iwyu += cmStrCat(
  684. " --cppcheck=", this->GetLocalGenerator()->EscapeForShell(cppcheck));
  685. }
  686. if ((tidy && *tidy) || (cpplint && *cpplint) ||
  687. (cppcheck && *cppcheck)) {
  688. run_iwyu += " --source=$in";
  689. }
  690. run_iwyu += " -- ";
  691. compileCmds.front().insert(0, run_iwyu);
  692. }
  693. }
  694. // If compiler launcher was specified and not consumed above, it
  695. // goes to the beginning of the command line.
  696. if (!compileCmds.empty() && !compilerLauncher.empty()) {
  697. std::vector<std::string> args = cmExpandedList(compilerLauncher, true);
  698. if (!args.empty()) {
  699. args[0] = this->LocalGenerator->ConvertToOutputFormat(
  700. args[0], cmOutputConverter::SHELL);
  701. for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
  702. i = this->LocalGenerator->EscapeForShell(i);
  703. }
  704. }
  705. compileCmds.front().insert(0, cmStrCat(cmJoin(args, " "), ' '));
  706. }
  707. if (!compileCmds.empty()) {
  708. compileCmds.front().insert(0, cldeps);
  709. }
  710. for (std::string& i : compileCmds) {
  711. i = cmStrCat(launcher, i);
  712. rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), i,
  713. vars);
  714. }
  715. rule.Command = this->GetLocalGenerator()->BuildCommandLine(compileCmds);
  716. // Write the rule for compiling file of the given language.
  717. rule.Comment = cmStrCat("Rule for compiling ", lang, " files.");
  718. rule.Description = cmStrCat("Building ", lang, " object $out");
  719. this->GetGlobalGenerator()->AddRule(rule);
  720. }
  721. void cmNinjaTargetGenerator::WriteObjectBuildStatements(
  722. const std::string& config, const std::string& fileConfig,
  723. bool firstForConfig)
  724. {
  725. // Write comments.
  726. cmGlobalNinjaGenerator::WriteDivider(this->GetImplFileStream(fileConfig));
  727. this->GetImplFileStream(fileConfig)
  728. << "# Object build statements for "
  729. << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
  730. << " target " << this->GetTargetName() << "\n\n";
  731. {
  732. std::vector<cmSourceFile const*> customCommands;
  733. this->GeneratorTarget->GetCustomCommands(customCommands, config);
  734. for (cmSourceFile const* sf : customCommands) {
  735. cmCustomCommand const* cc = sf->GetCustomCommand();
  736. this->GetLocalGenerator()->AddCustomCommandTarget(
  737. cc, this->GetGeneratorTarget());
  738. // Record the custom commands for this target. The container is used
  739. // in WriteObjectBuildStatement when called in a loop below.
  740. this->Configs[config].CustomCommands.push_back(cc);
  741. }
  742. }
  743. {
  744. std::vector<cmSourceFile const*> headerSources;
  745. this->GeneratorTarget->GetHeaderSources(headerSources, config);
  746. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  747. headerSources, this->Configs[fileConfig].MacOSXContentGenerator.get(),
  748. config);
  749. }
  750. {
  751. std::vector<cmSourceFile const*> extraSources;
  752. this->GeneratorTarget->GetExtraSources(extraSources, config);
  753. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  754. extraSources, this->Configs[fileConfig].MacOSXContentGenerator.get(),
  755. config);
  756. }
  757. if (firstForConfig) {
  758. const char* pchExtension =
  759. GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION");
  760. std::vector<cmSourceFile const*> externalObjects;
  761. this->GeneratorTarget->GetExternalObjects(externalObjects, config);
  762. for (cmSourceFile const* sf : externalObjects) {
  763. auto objectFileName = this->GetGlobalGenerator()->ExpandCFGIntDir(
  764. this->GetSourceFilePath(sf), config);
  765. if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) {
  766. this->Configs[config].Objects.push_back(objectFileName);
  767. }
  768. }
  769. }
  770. {
  771. cmNinjaBuild build("phony");
  772. build.Comment =
  773. cmStrCat("Order-only phony target for ", this->GetTargetName());
  774. build.Outputs.push_back(this->OrderDependsTargetForTarget(config));
  775. cmNinjaDeps& orderOnlyDeps = build.OrderOnlyDeps;
  776. this->GetLocalGenerator()->AppendTargetDepends(
  777. this->GeneratorTarget, orderOnlyDeps, config, fileConfig,
  778. DependOnTargetOrdering);
  779. // Add order-only dependencies on other files associated with the target.
  780. cm::append(orderOnlyDeps, this->Configs[config].ExtraFiles);
  781. // Add order-only dependencies on custom command outputs.
  782. for (cmCustomCommand const* cc : this->Configs[config].CustomCommands) {
  783. cmCustomCommandGenerator ccg(*cc, config, this->GetLocalGenerator());
  784. const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
  785. const std::vector<std::string>& ccbyproducts = ccg.GetByproducts();
  786. std::transform(ccoutputs.begin(), ccoutputs.end(),
  787. std::back_inserter(orderOnlyDeps), MapToNinjaPath());
  788. std::transform(ccbyproducts.begin(), ccbyproducts.end(),
  789. std::back_inserter(orderOnlyDeps), MapToNinjaPath());
  790. }
  791. std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end());
  792. orderOnlyDeps.erase(
  793. std::unique(orderOnlyDeps.begin(), orderOnlyDeps.end()),
  794. orderOnlyDeps.end());
  795. // The phony target must depend on at least one input or ninja will explain
  796. // that "output ... of phony edge with no inputs doesn't exist" and
  797. // consider the phony output "dirty".
  798. if (orderOnlyDeps.empty()) {
  799. // Any path that always exists will work here. It would be nice to
  800. // use just "." but that is not supported by Ninja < 1.7.
  801. std::string tgtDir = cmStrCat(
  802. this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
  803. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget));
  804. orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir));
  805. }
  806. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  807. build);
  808. }
  809. {
  810. std::vector<cmSourceFile const*> objectSources;
  811. this->GeneratorTarget->GetObjectSources(objectSources, config);
  812. for (cmSourceFile const* sf : objectSources) {
  813. this->WriteObjectBuildStatement(sf, config, fileConfig, firstForConfig);
  814. }
  815. }
  816. for (auto const& langDDIFiles : this->Configs[config].DDIFiles) {
  817. std::string const& language = langDDIFiles.first;
  818. cmNinjaDeps const& ddiFiles = langDDIFiles.second;
  819. cmNinjaBuild build(this->LanguageDyndepRule(language, config));
  820. build.Outputs.push_back(this->GetDyndepFilePath(language, config));
  821. build.ExplicitDeps = ddiFiles;
  822. this->WriteTargetDependInfo(language, config);
  823. // Make sure dyndep files for all our dependencies have already
  824. // been generated so that the '<LANG>Modules.json' files they
  825. // produced as side-effects are available for us to read.
  826. // Ideally we should depend on the '<LANG>Modules.json' files
  827. // from our dependencies directly, but we don't know which of
  828. // our dependencies produces them. Fixing this will require
  829. // refactoring the Ninja generator to generate targets in
  830. // dependency order so that we can collect the needed information.
  831. this->GetLocalGenerator()->AppendTargetDepends(
  832. this->GeneratorTarget, build.OrderOnlyDeps, config, fileConfig,
  833. DependOnTargetArtifact);
  834. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  835. build);
  836. }
  837. this->GetImplFileStream(fileConfig) << "\n";
  838. if (!this->Configs[config].SwiftOutputMap.empty()) {
  839. std::string const mapFilePath =
  840. cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config, '/',
  841. "output-file-map.json");
  842. std::string const targetSwiftDepsPath = [this, config]() -> std::string {
  843. cmGeneratorTarget const* target = this->GeneratorTarget;
  844. if (const char* name = target->GetProperty("Swift_DEPENDENCIES_FILE")) {
  845. return name;
  846. }
  847. return this->ConvertToNinjaPath(
  848. cmStrCat(target->GetSupportDirectory(), '/', config, '/',
  849. target->GetName(), ".swiftdeps"));
  850. }();
  851. // build the global target dependencies
  852. // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps
  853. Json::Value deps(Json::objectValue);
  854. deps["swift-dependencies"] = targetSwiftDepsPath;
  855. this->Configs[config].SwiftOutputMap[""] = deps;
  856. cmGeneratedFileStream output(mapFilePath);
  857. output << this->Configs[config].SwiftOutputMap;
  858. }
  859. }
  860. void cmNinjaTargetGenerator::WriteObjectBuildStatement(
  861. cmSourceFile const* source, const std::string& config,
  862. const std::string& fileConfig, bool firstForConfig)
  863. {
  864. std::string const language = source->GetLanguage();
  865. std::string const sourceFileName =
  866. language == "RC" ? source->GetFullPath() : this->GetSourceFilePath(source);
  867. std::string const objectDir = this->ConvertToNinjaPath(
  868. cmStrCat(this->GeneratorTarget->GetSupportDirectory(),
  869. this->GetGlobalGenerator()->ConfigDirectory(config)));
  870. std::string const objectFileName =
  871. this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
  872. std::string const objectFileDir =
  873. cmSystemTools::GetFilenamePath(objectFileName);
  874. std::string cmakeVarLang = cmStrCat("CMAKE_", language);
  875. // build response file name
  876. std::string cmakeLinkVar = cmStrCat(cmakeVarLang, "_RESPONSE_FILE_FLAG");
  877. const char* flag = GetMakefile()->GetDefinition(cmakeLinkVar);
  878. bool const lang_supports_response =
  879. !(language == "RC" || (language == "CUDA" && !flag));
  880. int const commandLineLengthLimit =
  881. ((lang_supports_response && this->ForceResponseFile())) ? -1 : 0;
  882. cmNinjaBuild objBuild(this->LanguageCompilerRule(language, config));
  883. cmNinjaVars& vars = objBuild.Variables;
  884. vars["FLAGS"] = this->ComputeFlagsForObject(source, language, config);
  885. vars["DEFINES"] = this->ComputeDefines(source, language, config);
  886. vars["INCLUDES"] = this->ComputeIncludes(source, language, config);
  887. if (!this->NeedDepTypeMSVC(language)) {
  888. bool replaceExt(false);
  889. if (!language.empty()) {
  890. std::string repVar =
  891. cmStrCat("CMAKE_", language, "_DEPFILE_EXTENSION_REPLACE");
  892. replaceExt = this->Makefile->IsOn(repVar);
  893. }
  894. if (!replaceExt) {
  895. // use original code
  896. vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  897. cmStrCat(objectFileName, ".d"), cmOutputConverter::SHELL);
  898. } else {
  899. // Replace the original source file extension with the
  900. // depend file extension.
  901. std::string dependFileName = cmStrCat(
  902. cmSystemTools::GetFilenameWithoutLastExtension(objectFileName), ".d");
  903. vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  904. cmStrCat(objectFileDir, '/', dependFileName),
  905. cmOutputConverter::SHELL);
  906. }
  907. }
  908. this->ExportObjectCompileCommand(
  909. language, sourceFileName, objectDir, objectFileName, objectFileDir,
  910. vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"]);
  911. objBuild.Outputs.push_back(objectFileName);
  912. if (firstForConfig) {
  913. const char* pchExtension =
  914. this->GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION");
  915. if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) {
  916. // Add this object to the list of object files.
  917. this->Configs[config].Objects.push_back(objectFileName);
  918. }
  919. }
  920. objBuild.ExplicitDeps.push_back(sourceFileName);
  921. // Add precompile headers dependencies
  922. std::vector<std::string> depList;
  923. const std::string pchSource =
  924. this->GeneratorTarget->GetPchSource(config, language);
  925. if (!pchSource.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  926. depList.push_back(this->GeneratorTarget->GetPchHeader(config, language));
  927. if (source->GetFullPath() != pchSource) {
  928. depList.push_back(this->GeneratorTarget->GetPchFile(config, language));
  929. }
  930. }
  931. if (const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) {
  932. std::vector<std::string> objDepList = cmExpandedList(objectDeps);
  933. std::copy(objDepList.begin(), objDepList.end(),
  934. std::back_inserter(depList));
  935. }
  936. if (!depList.empty()) {
  937. for (std::string& odi : depList) {
  938. if (cmSystemTools::FileIsFullPath(odi)) {
  939. odi = cmSystemTools::CollapseFullPath(odi);
  940. }
  941. }
  942. std::transform(depList.begin(), depList.end(),
  943. std::back_inserter(objBuild.ImplicitDeps),
  944. MapToNinjaPath());
  945. }
  946. objBuild.OrderOnlyDeps.push_back(this->OrderDependsTargetForTarget(config));
  947. // If the source file is GENERATED and does not have a custom command
  948. // (either attached to this source file or another one), assume that one of
  949. // the target dependencies, OBJECT_DEPENDS or header file custom commands
  950. // will rebuild the file.
  951. if (source->GetIsGenerated() &&
  952. !source->GetPropertyAsBool("__CMAKE_GENERATED_BY_CMAKE") &&
  953. !source->GetCustomCommand() &&
  954. !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) {
  955. this->GetGlobalGenerator()->AddAssumedSourceDependencies(
  956. sourceFileName, objBuild.OrderOnlyDeps);
  957. }
  958. // For some cases we need to generate a ninja dyndep file.
  959. bool const needDyndep = this->NeedDyndep(language);
  960. // For some cases we do an explicit preprocessor invocation.
  961. bool const explicitPP = this->NeedExplicitPreprocessing(language);
  962. if (explicitPP) {
  963. cmNinjaBuild ppBuild(this->LanguagePreprocessRule(language, config));
  964. std::string const ppFileName =
  965. this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source, config));
  966. ppBuild.Outputs.push_back(ppFileName);
  967. ppBuild.RspFile = cmStrCat(ppFileName, ".rsp");
  968. bool const compilePP = this->UsePreprocessedSource(language);
  969. bool const compilePPWithDefines =
  970. compilePP && this->CompilePreprocessedSourceWithDefines(language);
  971. if (compilePP) {
  972. // Move compilation dependencies to the preprocessing build statement.
  973. std::swap(ppBuild.ExplicitDeps, objBuild.ExplicitDeps);
  974. std::swap(ppBuild.ImplicitDeps, objBuild.ImplicitDeps);
  975. std::swap(ppBuild.OrderOnlyDeps, objBuild.OrderOnlyDeps);
  976. std::swap(ppBuild.Variables["IN_ABS"], vars["IN_ABS"]);
  977. // The actual compilation will now use the preprocessed source.
  978. objBuild.ExplicitDeps.push_back(ppFileName);
  979. } else {
  980. // Copy compilation dependencies to the preprocessing build statement.
  981. ppBuild.ExplicitDeps = objBuild.ExplicitDeps;
  982. ppBuild.ImplicitDeps = objBuild.ImplicitDeps;
  983. ppBuild.OrderOnlyDeps = objBuild.OrderOnlyDeps;
  984. ppBuild.Variables["IN_ABS"] = vars["IN_ABS"];
  985. }
  986. // Preprocessing and compilation generally use the same flags.
  987. ppBuild.Variables["FLAGS"] = vars["FLAGS"];
  988. if (compilePP) {
  989. // In case compilation requires flags that are incompatible with
  990. // preprocessing, include them here.
  991. std::string const& postFlag = this->Makefile->GetSafeDefinition(
  992. cmStrCat("CMAKE_", language, "_POSTPROCESS_FLAG"));
  993. this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag);
  994. }
  995. if (compilePP && !compilePPWithDefines) {
  996. // Move preprocessor definitions to the preprocessor build statement.
  997. std::swap(ppBuild.Variables["DEFINES"], vars["DEFINES"]);
  998. } else {
  999. // Copy preprocessor definitions to the preprocessor build statement.
  1000. ppBuild.Variables["DEFINES"] = vars["DEFINES"];
  1001. }
  1002. // Copy include directories to the preprocessor build statement. The
  1003. // Fortran compilation build statement still needs them for the INCLUDE
  1004. // directive.
  1005. ppBuild.Variables["INCLUDES"] = vars["INCLUDES"];
  1006. if (compilePP) {
  1007. // Prepend source file's original directory as an include directory
  1008. // so e.g. Fortran INCLUDE statements can look for files in it.
  1009. std::vector<std::string> sourceDirectory;
  1010. sourceDirectory.push_back(
  1011. cmSystemTools::GetParentDirectory(source->GetFullPath()));
  1012. std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags(
  1013. sourceDirectory, this->GeneratorTarget, language, false, false,
  1014. config);
  1015. vars["INCLUDES"] = cmStrCat(sourceDirectoryFlag, ' ', vars["INCLUDES"]);
  1016. }
  1017. // Explicit preprocessing always uses a depfile.
  1018. ppBuild.Variables["DEP_FILE"] =
  1019. this->GetLocalGenerator()->ConvertToOutputFormat(
  1020. cmStrCat(objectFileName, ".pp.d"), cmOutputConverter::SHELL);
  1021. if (compilePP) {
  1022. // The actual compilation does not need a depfile because it
  1023. // depends on the already-preprocessed source.
  1024. vars.erase("DEP_FILE");
  1025. }
  1026. if (needDyndep) {
  1027. // Tell dependency scanner the object file that will result from
  1028. // compiling the source.
  1029. ppBuild.Variables["OBJ_FILE"] = objectFileName;
  1030. // Tell dependency scanner where to store dyndep intermediate results.
  1031. std::string const ddiFile = cmStrCat(objectFileName, ".ddi");
  1032. ppBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile;
  1033. ppBuild.ImplicitOuts.push_back(ddiFile);
  1034. if (firstForConfig) {
  1035. this->Configs[config].DDIFiles[language].push_back(ddiFile);
  1036. }
  1037. }
  1038. this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
  1039. ppBuild.Variables);
  1040. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  1041. ppBuild, commandLineLengthLimit);
  1042. }
  1043. if (needDyndep) {
  1044. std::string const dyndep = this->GetDyndepFilePath(language, config);
  1045. objBuild.OrderOnlyDeps.push_back(dyndep);
  1046. vars["dyndep"] = dyndep;
  1047. }
  1048. EnsureParentDirectoryExists(objectFileName);
  1049. vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  1050. objectDir, cmOutputConverter::SHELL);
  1051. vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  1052. objectFileDir, cmOutputConverter::SHELL);
  1053. this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
  1054. vars);
  1055. if (!pchSource.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  1056. if (source->GetFullPath() == pchSource) {
  1057. this->addPoolNinjaVariable("JOB_POOL_PRECOMPILE_HEADER",
  1058. this->GetGeneratorTarget(), vars);
  1059. }
  1060. }
  1061. this->SetMsvcTargetPdbVariable(vars, config);
  1062. objBuild.RspFile = cmStrCat(objectFileName, ".rsp");
  1063. if (language == "Swift") {
  1064. this->EmitSwiftDependencyInfo(source, config);
  1065. } else {
  1066. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  1067. objBuild, commandLineLengthLimit);
  1068. }
  1069. if (const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
  1070. cmNinjaBuild build("phony");
  1071. build.Comment = "Additional output files.";
  1072. build.Outputs = cmExpandedList(objectOutputs);
  1073. std::transform(build.Outputs.begin(), build.Outputs.end(),
  1074. build.Outputs.begin(), MapToNinjaPath());
  1075. build.ExplicitDeps = objBuild.Outputs;
  1076. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  1077. build);
  1078. }
  1079. }
  1080. void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang,
  1081. const std::string& config)
  1082. {
  1083. Json::Value tdi(Json::objectValue);
  1084. tdi["language"] = lang;
  1085. tdi["compiler-id"] = this->Makefile->GetSafeDefinition(
  1086. cmStrCat("CMAKE_", lang, "_COMPILER_ID"));
  1087. if (lang == "Fortran") {
  1088. std::string mod_dir = this->GeneratorTarget->GetFortranModuleDirectory(
  1089. this->Makefile->GetHomeOutputDirectory());
  1090. if (mod_dir.empty()) {
  1091. mod_dir = this->Makefile->GetCurrentBinaryDirectory();
  1092. }
  1093. tdi["module-dir"] = mod_dir;
  1094. tdi["submodule-sep"] =
  1095. this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_SEP");
  1096. tdi["submodule-ext"] =
  1097. this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_EXT");
  1098. }
  1099. tdi["dir-cur-bld"] = this->Makefile->GetCurrentBinaryDirectory();
  1100. tdi["dir-cur-src"] = this->Makefile->GetCurrentSourceDirectory();
  1101. tdi["dir-top-bld"] = this->Makefile->GetHomeOutputDirectory();
  1102. tdi["dir-top-src"] = this->Makefile->GetHomeDirectory();
  1103. Json::Value& tdi_include_dirs = tdi["include-dirs"] = Json::arrayValue;
  1104. std::vector<std::string> includes;
  1105. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  1106. lang, config);
  1107. for (std::string const& i : includes) {
  1108. // Convert the include directories the same way we do for -I flags.
  1109. // See upstream ninja issue 1251.
  1110. tdi_include_dirs.append(this->ConvertToNinjaPath(i));
  1111. }
  1112. Json::Value& tdi_linked_target_dirs = tdi["linked-target-dirs"] =
  1113. Json::arrayValue;
  1114. for (std::string const& l : this->GetLinkedTargetDirectories(config)) {
  1115. tdi_linked_target_dirs.append(l);
  1116. }
  1117. std::string const tdin = this->GetTargetDependInfoPath(lang, config);
  1118. cmGeneratedFileStream tdif(tdin);
  1119. tdif << tdi;
  1120. }
  1121. void cmNinjaTargetGenerator::EmitSwiftDependencyInfo(
  1122. cmSourceFile const* source, const std::string& config)
  1123. {
  1124. std::string const sourceFilePath =
  1125. this->ConvertToNinjaPath(this->GetSourceFilePath(source));
  1126. std::string const objectFilePath =
  1127. this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
  1128. std::string const swiftDepsPath = [source, objectFilePath]() -> std::string {
  1129. if (const char* name = source->GetProperty("Swift_DEPENDENCIES_FILE")) {
  1130. return name;
  1131. }
  1132. return cmStrCat(objectFilePath, ".swiftdeps");
  1133. }();
  1134. std::string const swiftDiaPath = [source, objectFilePath]() -> std::string {
  1135. if (const char* name = source->GetProperty("Swift_DIAGNOSTICS_FILE")) {
  1136. return name;
  1137. }
  1138. return cmStrCat(objectFilePath, ".dia");
  1139. }();
  1140. std::string const makeDepsPath = [this, source, config]() -> std::string {
  1141. cmLocalNinjaGenerator const* local = this->GetLocalGenerator();
  1142. std::string const objectFileName =
  1143. this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
  1144. std::string const objectFileDir =
  1145. cmSystemTools::GetFilenamePath(objectFileName);
  1146. if (this->Makefile->IsOn("CMAKE_Swift_DEPFLE_EXTNSION_REPLACE")) {
  1147. std::string dependFileName = cmStrCat(
  1148. cmSystemTools::GetFilenameWithoutLastExtension(objectFileName), ".d");
  1149. return local->ConvertToOutputFormat(
  1150. cmStrCat(objectFileDir, '/', dependFileName),
  1151. cmOutputConverter::SHELL);
  1152. }
  1153. return local->ConvertToOutputFormat(cmStrCat(objectFileName, ".d"),
  1154. cmOutputConverter::SHELL);
  1155. }();
  1156. // build the source file mapping
  1157. // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps
  1158. Json::Value entry = Json::Value(Json::objectValue);
  1159. entry["object"] = objectFilePath;
  1160. entry["dependencies"] = makeDepsPath;
  1161. entry["swift-dependencies"] = swiftDepsPath;
  1162. entry["diagnostics"] = swiftDiaPath;
  1163. this->Configs[config].SwiftOutputMap[sourceFilePath] = entry;
  1164. }
  1165. void cmNinjaTargetGenerator::ExportObjectCompileCommand(
  1166. std::string const& language, std::string const& sourceFileName,
  1167. std::string const& objectDir, std::string const& objectFileName,
  1168. std::string const& objectFileDir, std::string const& flags,
  1169. std::string const& defines, std::string const& includes)
  1170. {
  1171. if (!this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS")) {
  1172. return;
  1173. }
  1174. cmRulePlaceholderExpander::RuleVariables compileObjectVars;
  1175. compileObjectVars.Language = language.c_str();
  1176. std::string escapedSourceFileName = sourceFileName;
  1177. if (!cmSystemTools::FileIsFullPath(sourceFileName)) {
  1178. escapedSourceFileName =
  1179. cmSystemTools::CollapseFullPath(escapedSourceFileName,
  1180. this->GetGlobalGenerator()
  1181. ->GetCMakeInstance()
  1182. ->GetHomeOutputDirectory());
  1183. }
  1184. escapedSourceFileName = this->LocalGenerator->ConvertToOutputFormat(
  1185. escapedSourceFileName, cmOutputConverter::SHELL);
  1186. compileObjectVars.Source = escapedSourceFileName.c_str();
  1187. compileObjectVars.Object = objectFileName.c_str();
  1188. compileObjectVars.ObjectDir = objectDir.c_str();
  1189. compileObjectVars.ObjectFileDir = objectFileDir.c_str();
  1190. compileObjectVars.Flags = flags.c_str();
  1191. compileObjectVars.Defines = defines.c_str();
  1192. compileObjectVars.Includes = includes.c_str();
  1193. // Rule for compiling object file.
  1194. std::vector<std::string> compileCmds;
  1195. if (language == "CUDA") {
  1196. std::string cmdVar;
  1197. if (this->GeneratorTarget->GetPropertyAsBool(
  1198. "CUDA_SEPARABLE_COMPILATION")) {
  1199. cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION";
  1200. } else if (this->GeneratorTarget->GetPropertyAsBool(
  1201. "CUDA_PTX_COMPILATION")) {
  1202. cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION";
  1203. } else {
  1204. cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION";
  1205. }
  1206. const std::string& compileCmd =
  1207. this->GetMakefile()->GetRequiredDefinition(cmdVar);
  1208. cmExpandList(compileCmd, compileCmds);
  1209. } else {
  1210. const std::string cmdVar = cmStrCat("CMAKE_", language, "_COMPILE_OBJECT");
  1211. const std::string& compileCmd =
  1212. this->GetMakefile()->GetRequiredDefinition(cmdVar);
  1213. cmExpandList(compileCmd, compileCmds);
  1214. }
  1215. std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
  1216. this->GetLocalGenerator()->CreateRulePlaceholderExpander());
  1217. for (std::string& i : compileCmds) {
  1218. // no launcher for CMAKE_EXPORT_COMPILE_COMMANDS
  1219. rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), i,
  1220. compileObjectVars);
  1221. }
  1222. std::string cmdLine =
  1223. this->GetLocalGenerator()->BuildCommandLine(compileCmds);
  1224. this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName);
  1225. }
  1226. void cmNinjaTargetGenerator::AdditionalCleanFiles(const std::string& config)
  1227. {
  1228. if (const char* prop_value =
  1229. this->GeneratorTarget->GetProperty("ADDITIONAL_CLEAN_FILES")) {
  1230. cmLocalNinjaGenerator* lg = this->LocalGenerator;
  1231. std::vector<std::string> cleanFiles;
  1232. cmExpandList(cmGeneratorExpression::Evaluate(prop_value, lg, config,
  1233. this->GeneratorTarget),
  1234. cleanFiles);
  1235. std::string const& binaryDir = lg->GetCurrentBinaryDirectory();
  1236. cmGlobalNinjaGenerator* gg = lg->GetGlobalNinjaGenerator();
  1237. for (std::string const& cleanFile : cleanFiles) {
  1238. // Support relative paths
  1239. gg->AddAdditionalCleanFile(
  1240. cmSystemTools::CollapseFullPath(cleanFile, binaryDir), config);
  1241. }
  1242. }
  1243. }
  1244. cmNinjaDeps cmNinjaTargetGenerator::GetObjects(const std::string& config) const
  1245. {
  1246. auto const it = this->Configs.find(config);
  1247. if (it != this->Configs.end()) {
  1248. return it->second.Objects;
  1249. }
  1250. return {};
  1251. }
  1252. void cmNinjaTargetGenerator::EnsureDirectoryExists(
  1253. const std::string& path) const
  1254. {
  1255. if (cmSystemTools::FileIsFullPath(path)) {
  1256. cmSystemTools::MakeDirectory(path);
  1257. } else {
  1258. cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
  1259. std::string fullPath = gg->GetCMakeInstance()->GetHomeOutputDirectory();
  1260. // Also ensures their is a trailing slash.
  1261. gg->StripNinjaOutputPathPrefixAsSuffix(fullPath);
  1262. fullPath += path;
  1263. cmSystemTools::MakeDirectory(fullPath);
  1264. }
  1265. }
  1266. void cmNinjaTargetGenerator::EnsureParentDirectoryExists(
  1267. const std::string& path) const
  1268. {
  1269. EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path));
  1270. }
  1271. void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
  1272. cmSourceFile const& source, const char* pkgloc, const std::string& config)
  1273. {
  1274. // Skip OS X content when not building a Framework or Bundle.
  1275. if (!this->Generator->GetGeneratorTarget()->IsBundleOnApple()) {
  1276. return;
  1277. }
  1278. std::string macdir =
  1279. this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc,
  1280. config);
  1281. // Reject files that collide with files from the Ninja file's native config.
  1282. if (config != this->FileConfig) {
  1283. std::string nativeMacdir =
  1284. this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(
  1285. pkgloc, this->FileConfig);
  1286. if (macdir == nativeMacdir) {
  1287. return;
  1288. }
  1289. }
  1290. // Get the input file location.
  1291. std::string input = source.GetFullPath();
  1292. input = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(input);
  1293. // Get the output file location.
  1294. std::string output =
  1295. cmStrCat(macdir, '/', cmSystemTools::GetFilenameName(input));
  1296. output = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(output);
  1297. // Write a build statement to copy the content into the bundle.
  1298. this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(
  1299. input, output, this->FileConfig);
  1300. // Add as a dependency to the target so that it gets called.
  1301. this->Generator->Configs[config].ExtraFiles.push_back(std::move(output));
  1302. }
  1303. void cmNinjaTargetGenerator::addPoolNinjaVariable(
  1304. const std::string& pool_property, cmGeneratorTarget* target,
  1305. cmNinjaVars& vars)
  1306. {
  1307. const char* pool = target->GetProperty(pool_property);
  1308. if (pool) {
  1309. vars["pool"] = pool;
  1310. }
  1311. }
  1312. bool cmNinjaTargetGenerator::ForceResponseFile()
  1313. {
  1314. static std::string const forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE";
  1315. return (this->GetMakefile()->IsDefinitionSet(forceRspFile) ||
  1316. cmSystemTools::HasEnv(forceRspFile));
  1317. }