1
0

cmNinjaTargetGenerator.cxx 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  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 <array>
  6. #include <cassert>
  7. #include <functional>
  8. #include <iterator>
  9. #include <map>
  10. #include <ostream>
  11. #include <type_traits>
  12. #include <unordered_map>
  13. #include <unordered_set>
  14. #include <utility>
  15. #include <cm/memory>
  16. #include <cm/string_view>
  17. #include <cmext/algorithm>
  18. #include <cmext/string_view>
  19. #include <cm3p/json/value.h>
  20. #include <cm3p/json/writer.h>
  21. #include "cmComputeLinkInformation.h"
  22. #include "cmCustomCommandGenerator.h"
  23. #include "cmDyndepCollation.h"
  24. #include "cmFileSet.h"
  25. #include "cmGeneratedFileStream.h"
  26. #include "cmGeneratorExpression.h"
  27. #include "cmGeneratorTarget.h"
  28. #include "cmGlobalCommonGenerator.h"
  29. #include "cmGlobalNinjaGenerator.h"
  30. #include "cmList.h"
  31. #include "cmLocalGenerator.h"
  32. #include "cmLocalNinjaGenerator.h"
  33. #include "cmMakefile.h"
  34. #include "cmMessageType.h"
  35. #include "cmNinjaNormalTargetGenerator.h"
  36. #include "cmNinjaUtilityTargetGenerator.h"
  37. #include "cmOutputConverter.h"
  38. #include "cmRange.h"
  39. #include "cmRulePlaceholderExpander.h"
  40. #include "cmSourceFile.h"
  41. #include "cmState.h"
  42. #include "cmStateTypes.h"
  43. #include "cmStringAlgorithms.h"
  44. #include "cmSystemTools.h"
  45. #include "cmTarget.h"
  46. #include "cmValue.h"
  47. #include "cmake.h"
  48. std::unique_ptr<cmNinjaTargetGenerator> cmNinjaTargetGenerator::New(
  49. cmGeneratorTarget* target)
  50. {
  51. switch (target->GetType()) {
  52. case cmStateEnums::EXECUTABLE:
  53. case cmStateEnums::SHARED_LIBRARY:
  54. case cmStateEnums::STATIC_LIBRARY:
  55. case cmStateEnums::MODULE_LIBRARY:
  56. case cmStateEnums::OBJECT_LIBRARY:
  57. return cm::make_unique<cmNinjaNormalTargetGenerator>(target);
  58. case cmStateEnums::UTILITY:
  59. case cmStateEnums::INTERFACE_LIBRARY:
  60. case cmStateEnums::GLOBAL_TARGET:
  61. return cm::make_unique<cmNinjaUtilityTargetGenerator>(target);
  62. default:
  63. return std::unique_ptr<cmNinjaTargetGenerator>();
  64. }
  65. }
  66. cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
  67. : cmCommonTargetGenerator(target)
  68. , OSXBundleGenerator(nullptr)
  69. , LocalGenerator(
  70. static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator()))
  71. {
  72. for (auto const& fileConfig :
  73. target->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig)) {
  74. this->Configs[fileConfig].MacOSXContentGenerator =
  75. cm::make_unique<MacOSXContentGeneratorType>(this, fileConfig);
  76. }
  77. }
  78. cmNinjaTargetGenerator::~cmNinjaTargetGenerator() = default;
  79. cmGeneratedFileStream& cmNinjaTargetGenerator::GetImplFileStream(
  80. const std::string& config) const
  81. {
  82. return *this->GetGlobalGenerator()->GetImplFileStream(config);
  83. }
  84. cmGeneratedFileStream& cmNinjaTargetGenerator::GetCommonFileStream() const
  85. {
  86. return *this->GetGlobalGenerator()->GetCommonFileStream();
  87. }
  88. cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const
  89. {
  90. return *this->GetGlobalGenerator()->GetRulesFileStream();
  91. }
  92. cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
  93. {
  94. return this->LocalGenerator->GetGlobalNinjaGenerator();
  95. }
  96. std::string cmNinjaTargetGenerator::LanguageCompilerRule(
  97. const std::string& lang, const std::string& config,
  98. WithScanning withScanning) const
  99. {
  100. return cmStrCat(
  101. lang, "_COMPILER__",
  102. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
  103. withScanning == WithScanning::Yes ? "_scanned_" : "_unscanned_", config);
  104. }
  105. std::string cmNinjaTargetGenerator::LanguagePreprocessAndScanRule(
  106. std::string const& lang, const std::string& config) const
  107. {
  108. return cmStrCat(
  109. lang, "_PREPROCESS_SCAN__",
  110. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
  111. '_', config);
  112. }
  113. std::string cmNinjaTargetGenerator::LanguageScanRule(
  114. std::string const& lang, const std::string& config) const
  115. {
  116. return cmStrCat(
  117. lang, "_SCAN__",
  118. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
  119. '_', config);
  120. }
  121. bool cmNinjaTargetGenerator::NeedExplicitPreprocessing(
  122. std::string const& lang) const
  123. {
  124. return lang == "Fortran";
  125. }
  126. bool cmNinjaTargetGenerator::CompileWithDefines(std::string const& lang) const
  127. {
  128. return this->Makefile->IsOn(
  129. cmStrCat("CMAKE_", lang, "_COMPILE_WITH_DEFINES"));
  130. }
  131. std::string cmNinjaTargetGenerator::LanguageDyndepRule(
  132. const std::string& lang, const std::string& config) const
  133. {
  134. return cmStrCat(
  135. lang, "_DYNDEP__",
  136. cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
  137. '_', config);
  138. }
  139. std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget(
  140. const std::string& config)
  141. {
  142. return this->GetGlobalGenerator()->OrderDependsTargetForTarget(
  143. this->GeneratorTarget, config);
  144. }
  145. // TODO: Most of the code is picked up from
  146. // void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink),
  147. // void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
  148. // Refactor it.
  149. std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
  150. cmSourceFile const* source, const std::string& language,
  151. const std::string& config)
  152. {
  153. std::unordered_map<std::string, std::string> pchSources;
  154. std::vector<std::string> architectures =
  155. this->GeneratorTarget->GetAppleArchs(config, language);
  156. if (architectures.empty()) {
  157. architectures.emplace_back();
  158. }
  159. std::string filterArch;
  160. for (const std::string& arch : architectures) {
  161. const std::string pchSource =
  162. this->GeneratorTarget->GetPchSource(config, language, arch);
  163. if (pchSource == source->GetFullPath()) {
  164. filterArch = arch;
  165. }
  166. if (!pchSource.empty()) {
  167. pchSources.insert(std::make_pair(pchSource, arch));
  168. }
  169. }
  170. std::string flags;
  171. // Explicitly add the explicit language flag before any other flag
  172. // so user flags can override it.
  173. this->GeneratorTarget->AddExplicitLanguageFlags(flags, *source);
  174. if (!flags.empty()) {
  175. flags += " ";
  176. }
  177. flags += this->GetFlags(language, config, filterArch);
  178. // Add Fortran format flags.
  179. if (language == "Fortran") {
  180. this->AppendFortranFormatFlags(flags, *source);
  181. this->AppendFortranPreprocessFlags(flags, *source,
  182. PreprocessFlagsRequired::NO);
  183. }
  184. // Add source file specific flags.
  185. cmGeneratorExpressionInterpreter genexInterpreter(
  186. this->LocalGenerator, config, this->GeneratorTarget, language);
  187. const std::string COMPILE_FLAGS("COMPILE_FLAGS");
  188. if (cmValue cflags = source->GetProperty(COMPILE_FLAGS)) {
  189. this->LocalGenerator->AppendFlags(
  190. flags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS));
  191. }
  192. const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
  193. if (cmValue coptions = source->GetProperty(COMPILE_OPTIONS)) {
  194. this->LocalGenerator->AppendCompileOptions(
  195. flags, genexInterpreter.Evaluate(*coptions, COMPILE_OPTIONS));
  196. }
  197. // Add precompile headers compile options.
  198. if (!pchSources.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  199. std::string pchOptions;
  200. auto pchIt = pchSources.find(source->GetFullPath());
  201. if (pchIt != pchSources.end()) {
  202. pchOptions = this->GeneratorTarget->GetPchCreateCompileOptions(
  203. config, language, pchIt->second);
  204. } else {
  205. pchOptions =
  206. this->GeneratorTarget->GetPchUseCompileOptions(config, language);
  207. }
  208. this->LocalGenerator->AppendCompileOptions(
  209. flags, genexInterpreter.Evaluate(pchOptions, COMPILE_OPTIONS));
  210. }
  211. auto const* fs = this->GeneratorTarget->GetFileSetForSource(config, source);
  212. if (fs &&
  213. (fs->GetType() == "CXX_MODULES"_s ||
  214. fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) {
  215. if (source->GetLanguage() != "CXX"_s) {
  216. this->GetMakefile()->IssueMessage(
  217. MessageType::FATAL_ERROR,
  218. cmStrCat("Target \"", this->GeneratorTarget->Target->GetName(),
  219. "\" contains the source\n ", source->GetFullPath(),
  220. "\nin a file set of type \"", fs->GetType(),
  221. R"(" but the source is not classified as a "CXX" source.)"));
  222. }
  223. }
  224. return flags;
  225. }
  226. void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
  227. std::string const& language,
  228. const std::string& config)
  229. {
  230. std::vector<std::string> includes;
  231. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  232. language, config);
  233. // Add include directory flags.
  234. std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
  235. includes, this->GeneratorTarget, language, config, false);
  236. if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
  237. std::replace(includeFlags.begin(), includeFlags.end(), '\\', '/');
  238. }
  239. this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
  240. }
  241. // TODO: Refactor with
  242. // void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
  243. std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
  244. const std::string& language,
  245. const std::string& config)
  246. {
  247. std::set<std::string> defines;
  248. cmGeneratorExpressionInterpreter genexInterpreter(
  249. this->LocalGenerator, config, this->GeneratorTarget, language);
  250. // Seriously??
  251. if (this->GetGlobalGenerator()->IsMultiConfig()) {
  252. defines.insert(cmStrCat("CMAKE_INTDIR=\"", config, '"'));
  253. }
  254. const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
  255. if (cmValue compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
  256. this->LocalGenerator->AppendDefines(
  257. defines, genexInterpreter.Evaluate(*compile_defs, COMPILE_DEFINITIONS));
  258. }
  259. std::string defPropName =
  260. cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(config));
  261. if (cmValue config_compile_defs = source->GetProperty(defPropName)) {
  262. this->LocalGenerator->AppendDefines(
  263. defines,
  264. genexInterpreter.Evaluate(*config_compile_defs, COMPILE_DEFINITIONS));
  265. }
  266. std::string definesString = this->GetDefines(language, config);
  267. this->LocalGenerator->JoinDefines(defines, definesString, language);
  268. return definesString;
  269. }
  270. std::string cmNinjaTargetGenerator::ComputeIncludes(
  271. cmSourceFile const* source, const std::string& language,
  272. const std::string& config)
  273. {
  274. std::vector<std::string> includes;
  275. cmGeneratorExpressionInterpreter genexInterpreter(
  276. this->LocalGenerator, config, this->GeneratorTarget, language);
  277. const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
  278. if (cmValue cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
  279. this->LocalGenerator->AppendIncludeDirectories(
  280. includes, genexInterpreter.Evaluate(*cincludes, INCLUDE_DIRECTORIES),
  281. *source);
  282. }
  283. std::string includesString = this->LocalGenerator->GetIncludeFlags(
  284. includes, this->GeneratorTarget, language, config, false);
  285. this->LocalGenerator->AppendFlags(includesString,
  286. this->GetIncludes(language, config));
  287. return includesString;
  288. }
  289. cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps(
  290. const std::string& linkLanguage, const std::string& config,
  291. bool ignoreType) const
  292. {
  293. // Static libraries never depend on other targets for linking.
  294. if (!ignoreType &&
  295. (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  296. this->GeneratorTarget->GetType() == cmStateEnums::OBJECT_LIBRARY)) {
  297. return cmNinjaDeps();
  298. }
  299. cmComputeLinkInformation* cli =
  300. this->GeneratorTarget->GetLinkInformation(config);
  301. if (!cli) {
  302. return cmNinjaDeps();
  303. }
  304. const std::vector<std::string>& deps = cli->GetDepends();
  305. cmNinjaDeps result(deps.size());
  306. std::transform(deps.begin(), deps.end(), result.begin(),
  307. this->MapToNinjaPath());
  308. // Add a dependency on the link definitions file, if any.
  309. if (cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  310. this->GeneratorTarget->GetModuleDefinitionInfo(config)) {
  311. for (cmSourceFile const* src : mdi->Sources) {
  312. result.push_back(this->ConvertToNinjaPath(src->GetFullPath()));
  313. }
  314. }
  315. // Add a dependency on user-specified manifest files, if any.
  316. std::vector<cmSourceFile const*> manifest_srcs;
  317. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  318. for (cmSourceFile const* manifest_src : manifest_srcs) {
  319. result.push_back(this->ConvertToNinjaPath(manifest_src->GetFullPath()));
  320. }
  321. // Add user-specified dependencies.
  322. std::vector<std::string> linkDeps;
  323. this->GeneratorTarget->GetLinkDepends(linkDeps, config, linkLanguage);
  324. std::transform(linkDeps.begin(), linkDeps.end(), std::back_inserter(result),
  325. this->MapToNinjaPath());
  326. return result;
  327. }
  328. std::string cmNinjaTargetGenerator::GetCompiledSourceNinjaPath(
  329. cmSourceFile const* source) const
  330. {
  331. // Pass source files to the compiler by absolute path.
  332. return this->ConvertToNinjaAbsPath(source->GetFullPath());
  333. }
  334. std::string cmNinjaTargetGenerator::GetObjectFilePath(
  335. cmSourceFile const* source, const std::string& config) const
  336. {
  337. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  338. if (!path.empty()) {
  339. path += '/';
  340. }
  341. std::string const& objectName = this->GeneratorTarget->GetObjectName(source);
  342. path += cmStrCat(
  343. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  344. this->GetGlobalGenerator()->ConfigDirectory(config), '/', objectName);
  345. return path;
  346. }
  347. std::string cmNinjaTargetGenerator::GetClangTidyReplacementsFilePath(
  348. const std::string& directory, cmSourceFile const* source,
  349. const std::string& config) const
  350. {
  351. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  352. if (!path.empty()) {
  353. path += '/';
  354. }
  355. path = cmStrCat(directory, '/', path);
  356. std::string const& objectName = this->GeneratorTarget->GetObjectName(source);
  357. path =
  358. cmStrCat(std::move(path),
  359. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  360. this->GetGlobalGenerator()->ConfigDirectory(config), '/',
  361. objectName, ".yaml");
  362. return path;
  363. }
  364. std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
  365. cmSourceFile const* source, const std::string& config) const
  366. {
  367. // Choose an extension to compile already-preprocessed source.
  368. std::string ppExt = source->GetExtension();
  369. if (cmHasLiteralPrefix(ppExt, "F")) {
  370. // Some Fortran compilers automatically enable preprocessing for
  371. // upper-case extensions. Since the source is already preprocessed,
  372. // use a lower-case extension.
  373. ppExt = cmSystemTools::LowerCase(ppExt);
  374. }
  375. if (ppExt == "fpp") {
  376. // Some Fortran compilers automatically enable preprocessing for
  377. // the ".fpp" extension. Since the source is already preprocessed,
  378. // use the ".f" extension.
  379. ppExt = "f";
  380. }
  381. // Take the object file name and replace the extension.
  382. std::string const& objName = this->GeneratorTarget->GetObjectName(source);
  383. std::string const& objExt =
  384. this->GetGlobalGenerator()->GetLanguageOutputExtension(*source);
  385. assert(objName.size() >= objExt.size());
  386. std::string const ppName =
  387. cmStrCat(objName.substr(0, objName.size() - objExt.size()), "-pp.", ppExt);
  388. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  389. if (!path.empty()) {
  390. path += '/';
  391. }
  392. path +=
  393. cmStrCat(this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  394. this->GetGlobalGenerator()->ConfigDirectory(config), '/', ppName);
  395. return path;
  396. }
  397. std::string cmNinjaTargetGenerator::GetDyndepFilePath(
  398. std::string const& lang, const std::string& config) const
  399. {
  400. std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
  401. if (!path.empty()) {
  402. path += '/';
  403. }
  404. path += cmStrCat(
  405. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  406. this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang, ".dd");
  407. return path;
  408. }
  409. std::string cmNinjaTargetGenerator::GetTargetDependInfoPath(
  410. std::string const& lang, const std::string& config) const
  411. {
  412. std::string path =
  413. cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
  414. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  415. this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang,
  416. "DependInfo.json");
  417. return path;
  418. }
  419. std::string cmNinjaTargetGenerator::GetTargetOutputDir(
  420. const std::string& config) const
  421. {
  422. std::string dir = this->GeneratorTarget->GetDirectory(config);
  423. return this->ConvertToNinjaPath(dir);
  424. }
  425. std::string cmNinjaTargetGenerator::GetTargetFilePath(
  426. const std::string& name, const std::string& config) const
  427. {
  428. std::string path = this->GetTargetOutputDir(config);
  429. if (path.empty() || path == ".") {
  430. return name;
  431. }
  432. path += cmStrCat('/', name);
  433. return path;
  434. }
  435. std::string cmNinjaTargetGenerator::GetTargetName() const
  436. {
  437. return this->GeneratorTarget->GetName();
  438. }
  439. bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(
  440. cmNinjaVars& vars, const std::string& config) const
  441. {
  442. cmMakefile* mf = this->GetMakefile();
  443. if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
  444. mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID") ||
  445. mf->GetDefinition("MSVC_CUDA_ARCHITECTURE_ID")) {
  446. std::string pdbPath;
  447. std::string compilePdbPath = this->ComputeTargetCompilePDB(config);
  448. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  449. this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  450. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  451. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  452. pdbPath = cmStrCat(this->GeneratorTarget->GetPDBDirectory(config), '/',
  453. this->GeneratorTarget->GetPDBName(config));
  454. }
  455. vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  456. this->ConvertToNinjaPath(pdbPath), cmOutputConverter::SHELL);
  457. vars["TARGET_COMPILE_PDB"] =
  458. this->GetLocalGenerator()->ConvertToOutputFormat(
  459. this->ConvertToNinjaPath(compilePdbPath), cmOutputConverter::SHELL);
  460. this->EnsureParentDirectoryExists(pdbPath);
  461. this->EnsureParentDirectoryExists(compilePdbPath);
  462. return true;
  463. }
  464. return false;
  465. }
  466. void cmNinjaTargetGenerator::WriteLanguageRules(const std::string& language,
  467. const std::string& config)
  468. {
  469. #ifdef NINJA_GEN_VERBOSE_FILES
  470. this->GetRulesFileStream() << "# Rules for language " << language << "\n\n";
  471. #endif
  472. this->WriteCompileRule(language, config);
  473. }
  474. namespace {
  475. // Create the command to run the dependency scanner
  476. std::string GetScanCommand(cm::string_view cmakeCmd, cm::string_view tdi,
  477. cm::string_view lang, cm::string_view srcFile,
  478. cm::string_view ddiFile)
  479. {
  480. return cmStrCat(cmakeCmd, " -E cmake_ninja_depends --tdi=", tdi,
  481. " --lang=", lang, " --src=", srcFile, " --out=$out",
  482. " --dep=$DEP_FILE --obj=$OBJ_FILE --ddi=", ddiFile);
  483. }
  484. // Helper function to create dependency scanning rule that may or may
  485. // not perform explicit preprocessing too.
  486. cmNinjaRule GetScanRule(
  487. std::string const& ruleName, std::string const& ppFileName,
  488. std::string const& deptype,
  489. cmRulePlaceholderExpander::RuleVariables const& vars,
  490. const std::string& responseFlag, const std::string& flags,
  491. cmRulePlaceholderExpander* const rulePlaceholderExpander,
  492. cmLocalNinjaGenerator* generator, std::vector<std::string> scanCmds,
  493. const std::string& outputConfig)
  494. {
  495. cmNinjaRule rule(ruleName);
  496. // Scanning always uses a depfile for preprocessor dependencies.
  497. if (deptype == "msvc"_s) {
  498. rule.DepType = deptype;
  499. rule.DepFile.clear();
  500. } else {
  501. rule.DepType.clear(); // no deps= for multiple outputs
  502. rule.DepFile = "$DEP_FILE";
  503. }
  504. cmRulePlaceholderExpander::RuleVariables scanVars;
  505. scanVars.CMTargetName = vars.CMTargetName;
  506. scanVars.CMTargetType = vars.CMTargetType;
  507. scanVars.Language = vars.Language;
  508. scanVars.Object = "$OBJ_FILE";
  509. scanVars.PreprocessedSource = ppFileName.c_str();
  510. scanVars.DynDepFile = "$DYNDEP_INTERMEDIATE_FILE";
  511. scanVars.DependencyFile = rule.DepFile.c_str();
  512. scanVars.DependencyTarget = "$out";
  513. // Scanning needs the same preprocessor settings as direct compilation would.
  514. scanVars.Source = vars.Source;
  515. scanVars.Defines = vars.Defines;
  516. scanVars.Includes = vars.Includes;
  517. // Scanning needs the compilation flags too.
  518. std::string scanFlags = flags;
  519. // If using a response file, move defines, includes, and flags into it.
  520. if (!responseFlag.empty()) {
  521. rule.RspFile = "$RSP_FILE";
  522. rule.RspContent =
  523. cmStrCat(' ', scanVars.Defines, ' ', scanVars.Includes, ' ', scanFlags);
  524. scanFlags = cmStrCat(responseFlag, rule.RspFile);
  525. scanVars.Defines = "";
  526. scanVars.Includes = "";
  527. }
  528. scanVars.Flags = scanFlags.c_str();
  529. // Rule for scanning a source file.
  530. for (std::string& scanCmd : scanCmds) {
  531. rulePlaceholderExpander->ExpandRuleVariables(generator, scanCmd, scanVars);
  532. }
  533. rule.Command =
  534. generator->BuildCommandLine(scanCmds, outputConfig, outputConfig);
  535. return rule;
  536. }
  537. }
  538. void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
  539. const std::string& config)
  540. {
  541. // For some cases we scan to dynamically discover dependencies.
  542. bool const needDyndep = this->GetGeneratorTarget()->NeedDyndep(lang, config);
  543. if (needDyndep) {
  544. this->WriteCompileRule(lang, config, WithScanning::Yes);
  545. }
  546. this->WriteCompileRule(lang, config, WithScanning::No);
  547. }
  548. void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
  549. const std::string& config,
  550. WithScanning withScanning)
  551. {
  552. cmRulePlaceholderExpander::RuleVariables vars;
  553. vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
  554. vars.CMTargetType =
  555. cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()).c_str();
  556. vars.Language = lang.c_str();
  557. vars.Source = "$in";
  558. vars.Object = "$out";
  559. vars.Defines = "$DEFINES";
  560. vars.Includes = "$INCLUDES";
  561. vars.TargetPDB = "$TARGET_PDB";
  562. vars.TargetCompilePDB = "$TARGET_COMPILE_PDB";
  563. vars.ObjectDir = "$OBJECT_DIR";
  564. vars.ObjectFileDir = "$OBJECT_FILE_DIR";
  565. vars.CudaCompileMode = "$CUDA_COMPILE_MODE";
  566. vars.ISPCHeader = "$ISPC_HEADER_FILE";
  567. cmMakefile* mf = this->GetMakefile();
  568. // For some cases we scan to dynamically discover dependencies.
  569. bool const compilationPreprocesses = !this->NeedExplicitPreprocessing(lang);
  570. std::string flags = "$FLAGS";
  571. std::string responseFlag;
  572. bool const lang_supports_response = lang != "RC";
  573. if (lang_supports_response && this->ForceResponseFile()) {
  574. std::string const responseFlagVar =
  575. cmStrCat("CMAKE_", lang, "_RESPONSE_FILE_FLAG");
  576. responseFlag = this->Makefile->GetSafeDefinition(responseFlagVar);
  577. if (responseFlag.empty() && lang != "CUDA") {
  578. responseFlag = "@";
  579. }
  580. }
  581. std::string const modmapFormatVar =
  582. cmStrCat("CMAKE_EXPERIMENTAL_", lang, "_MODULE_MAP_FORMAT");
  583. std::string const modmapFormat =
  584. this->Makefile->GetSafeDefinition(modmapFormatVar);
  585. auto rulePlaceholderExpander =
  586. this->GetLocalGenerator()->CreateRulePlaceholderExpander();
  587. std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat(
  588. this->ConvertToNinjaPath(this->GetTargetDependInfoPath(lang, config)),
  589. cmLocalGenerator::SHELL);
  590. std::string launcher;
  591. std::string val = this->GetLocalGenerator()->GetRuleLauncher(
  592. this->GetGeneratorTarget(), "RULE_LAUNCH_COMPILE", config);
  593. if (cmNonempty(val)) {
  594. launcher = cmStrCat(val, ' ');
  595. }
  596. std::string const cmakeCmd =
  597. this->GetLocalGenerator()->ConvertToOutputFormat(
  598. cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
  599. if (withScanning == WithScanning::Yes) {
  600. const auto& scanDepType = this->GetMakefile()->GetSafeDefinition(
  601. cmStrCat("CMAKE_EXPERIMENTAL_", lang, "_SCANDEP_DEPFILE_FORMAT"));
  602. // Rule to scan dependencies of sources that need preprocessing.
  603. {
  604. cmList scanCommands;
  605. std::string scanRuleName;
  606. std::string ppFileName;
  607. if (compilationPreprocesses) {
  608. scanRuleName = this->LanguageScanRule(lang, config);
  609. ppFileName = "$PREPROCESSED_OUTPUT_FILE";
  610. std::string const& scanCommand = mf->GetRequiredDefinition(
  611. cmStrCat("CMAKE_EXPERIMENTAL_", lang, "_SCANDEP_SOURCE"));
  612. scanCommands.assign(scanCommand);
  613. for (auto& i : scanCommands) {
  614. i = cmStrCat(launcher, i);
  615. }
  616. } else {
  617. scanRuleName = this->LanguagePreprocessAndScanRule(lang, config);
  618. ppFileName = "$out";
  619. std::string const& ppCommmand = mf->GetRequiredDefinition(
  620. cmStrCat("CMAKE_", lang, "_PREPROCESS_SOURCE"));
  621. scanCommands.assign(ppCommmand);
  622. for (auto& i : scanCommands) {
  623. i = cmStrCat(launcher, i);
  624. }
  625. scanCommands.emplace_back(GetScanCommand(cmakeCmd, tdi, lang, "$out",
  626. "$DYNDEP_INTERMEDIATE_FILE"));
  627. }
  628. auto scanRule = GetScanRule(
  629. scanRuleName, ppFileName, scanDepType, vars, responseFlag, flags,
  630. rulePlaceholderExpander.get(), this->GetLocalGenerator(),
  631. std::move(scanCommands), config);
  632. scanRule.Comment =
  633. cmStrCat("Rule for generating ", lang, " dependencies.");
  634. if (compilationPreprocesses) {
  635. scanRule.Description =
  636. cmStrCat("Scanning $in for ", lang, " dependencies");
  637. } else {
  638. scanRule.Description =
  639. cmStrCat("Building ", lang, " preprocessed $out");
  640. }
  641. this->GetGlobalGenerator()->AddRule(scanRule);
  642. }
  643. if (!compilationPreprocesses) {
  644. // Compilation will not preprocess, so it does not need the defines
  645. // unless the compiler wants them for some other purpose.
  646. if (!this->CompileWithDefines(lang)) {
  647. vars.Defines = "";
  648. }
  649. // Rule to scan dependencies of sources that do not need preprocessing.
  650. std::string const& scanRuleName = this->LanguageScanRule(lang, config);
  651. std::vector<std::string> scanCommands;
  652. scanCommands.emplace_back(
  653. GetScanCommand(cmakeCmd, tdi, lang, "$in", "$out"));
  654. auto scanRule =
  655. GetScanRule(scanRuleName, "", scanDepType, vars, "", flags,
  656. rulePlaceholderExpander.get(), this->GetLocalGenerator(),
  657. std::move(scanCommands), config);
  658. // Write the rule for generating dependencies for the given language.
  659. scanRule.Comment = cmStrCat("Rule for generating ", lang,
  660. " dependencies on non-preprocessed files.");
  661. scanRule.Description =
  662. cmStrCat("Generating ", lang, " dependencies for $in");
  663. this->GetGlobalGenerator()->AddRule(scanRule);
  664. }
  665. // Write the rule for ninja dyndep file generation.
  666. cmNinjaRule rule(this->LanguageDyndepRule(lang, config));
  667. // Command line length is almost always limited -> use response file for
  668. // dyndep rules
  669. rule.RspFile = "$out.rsp";
  670. rule.RspContent = "$in";
  671. // Run CMake dependency scanner on the source file (using the preprocessed
  672. // source if that was performed).
  673. std::string ddModmapArg;
  674. if (!modmapFormat.empty()) {
  675. ddModmapArg += cmStrCat(" --modmapfmt=", modmapFormat);
  676. }
  677. {
  678. std::vector<std::string> ddCmds;
  679. {
  680. std::string ccmd = cmStrCat(
  681. cmakeCmd, " -E cmake_ninja_dyndep --tdi=", tdi, " --lang=", lang,
  682. ddModmapArg, " --dd=$out @", rule.RspFile);
  683. ddCmds.emplace_back(std::move(ccmd));
  684. }
  685. rule.Command =
  686. this->GetLocalGenerator()->BuildCommandLine(ddCmds, config, config);
  687. }
  688. rule.Comment =
  689. cmStrCat("Rule to generate ninja dyndep files for ", lang, '.');
  690. rule.Description = cmStrCat("Generating ", lang, " dyndep file $out");
  691. this->GetGlobalGenerator()->AddRule(rule);
  692. }
  693. cmNinjaRule rule(this->LanguageCompilerRule(lang, config, withScanning));
  694. // If using a response file, move defines, includes, and flags into it.
  695. if (!responseFlag.empty()) {
  696. rule.RspFile = "$RSP_FILE";
  697. rule.RspContent =
  698. cmStrCat(' ', vars.Defines, ' ', vars.Includes, ' ', flags);
  699. flags = cmStrCat(responseFlag, rule.RspFile);
  700. vars.Defines = "";
  701. vars.Includes = "";
  702. }
  703. // Tell ninja dependency format so all deps can be loaded into a database
  704. std::string cldeps;
  705. if (!compilationPreprocesses) {
  706. // The compiler will not do preprocessing, so it has no such dependencies.
  707. } else if (mf->IsOn(cmStrCat("CMAKE_NINJA_CMCLDEPS_", lang))) {
  708. // For the MS resource compiler we need cmcldeps, but skip dependencies
  709. // for source-file try_compile cases because they are always fresh.
  710. if (!mf->GetIsSourceFileTryCompile()) {
  711. rule.DepType = "gcc";
  712. rule.DepFile = "$DEP_FILE";
  713. cmValue d = mf->GetDefinition("CMAKE_C_COMPILER");
  714. const std::string cl =
  715. d ? *d : mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
  716. std::string cmcldepsPath;
  717. cmSystemTools::GetShortPath(cmSystemTools::GetCMClDepsCommand(),
  718. cmcldepsPath);
  719. cldeps = cmStrCat(cmcldepsPath, ' ', lang, ' ', vars.Source,
  720. " $DEP_FILE $out \"",
  721. mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"),
  722. "\" \"", cl, "\" ");
  723. }
  724. } else {
  725. const auto& depType = this->GetMakefile()->GetSafeDefinition(
  726. cmStrCat("CMAKE_", lang, "_DEPFILE_FORMAT"));
  727. if (depType == "msvc"_s) {
  728. rule.DepType = "msvc";
  729. rule.DepFile.clear();
  730. } else {
  731. rule.DepType = "gcc";
  732. rule.DepFile = "$DEP_FILE";
  733. }
  734. vars.DependencyFile = rule.DepFile.c_str();
  735. vars.DependencyTarget = "$out";
  736. const std::string flagsName = cmStrCat("CMAKE_DEPFILE_FLAGS_", lang);
  737. std::string depfileFlags = mf->GetSafeDefinition(flagsName);
  738. if (!depfileFlags.empty()) {
  739. rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
  740. depfileFlags, vars);
  741. flags += cmStrCat(' ', depfileFlags);
  742. }
  743. }
  744. if (withScanning == WithScanning::Yes && !modmapFormat.empty()) {
  745. std::string modmapFlags = mf->GetRequiredDefinition(
  746. cmStrCat("CMAKE_EXPERIMENTAL_", lang, "_MODULE_MAP_FLAG"));
  747. cmSystemTools::ReplaceString(modmapFlags, "<MODULE_MAP_FILE>",
  748. "$DYNDEP_MODULE_MAP_FILE");
  749. flags += cmStrCat(' ', modmapFlags);
  750. }
  751. vars.Flags = flags.c_str();
  752. vars.DependencyFile = rule.DepFile.c_str();
  753. std::string cudaCompileMode;
  754. if (lang == "CUDA") {
  755. if (this->GeneratorTarget->GetPropertyAsBool(
  756. "CUDA_SEPARABLE_COMPILATION")) {
  757. const std::string& rdcFlag =
  758. this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_RDC_FLAG");
  759. cudaCompileMode = cmStrCat(cudaCompileMode, rdcFlag, " ");
  760. }
  761. static std::array<cm::string_view, 4> const compileModes{
  762. { "PTX"_s, "CUBIN"_s, "FATBIN"_s, "OPTIX"_s }
  763. };
  764. bool useNormalCompileMode = true;
  765. for (cm::string_view mode : compileModes) {
  766. auto propName = cmStrCat("CUDA_", mode, "_COMPILATION");
  767. auto defName = cmStrCat("_CMAKE_CUDA_", mode, "_FLAG");
  768. if (this->GeneratorTarget->GetPropertyAsBool(propName)) {
  769. const std::string& flag =
  770. this->Makefile->GetRequiredDefinition(defName);
  771. cudaCompileMode = cmStrCat(cudaCompileMode, flag);
  772. useNormalCompileMode = false;
  773. break;
  774. }
  775. }
  776. if (useNormalCompileMode) {
  777. const std::string& wholeFlag =
  778. this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_WHOLE_FLAG");
  779. cudaCompileMode = cmStrCat(cudaCompileMode, wholeFlag);
  780. }
  781. vars.CudaCompileMode = cudaCompileMode.c_str();
  782. }
  783. // Rule for compiling object file.
  784. const std::string cmdVar = cmStrCat("CMAKE_", lang, "_COMPILE_OBJECT");
  785. const std::string& compileCmd = mf->GetRequiredDefinition(cmdVar);
  786. cmList compileCmds(compileCmd);
  787. // See if we need to use a compiler launcher like ccache or distcc
  788. std::string compilerLauncher;
  789. if (!compileCmds.empty() &&
  790. (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" ||
  791. lang == "HIP" || lang == "ISPC" || lang == "OBJC" ||
  792. lang == "OBJCXX")) {
  793. std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER");
  794. cmValue clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
  795. std::string evaluatedClauncher = cmGeneratorExpression::Evaluate(
  796. *clauncher, this->LocalGenerator, config, this->GeneratorTarget, nullptr,
  797. this->GeneratorTarget, lang);
  798. if (!evaluatedClauncher.empty()) {
  799. compilerLauncher = evaluatedClauncher;
  800. }
  801. }
  802. // Maybe insert an include-what-you-use runner.
  803. if (!compileCmds.empty() &&
  804. (lang == "C" || lang == "CXX" || lang == "OBJC" || lang == "OBJCXX")) {
  805. cmValue tidy = nullptr;
  806. cmValue iwyu = nullptr;
  807. cmValue cpplint = nullptr;
  808. cmValue cppcheck = nullptr;
  809. std::string evaluatedTIDY;
  810. std::string evaluatedIWYU;
  811. std::string evaluatedCPPlint;
  812. std::string evaluatedCPPcheck;
  813. std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
  814. tidy = this->GeneratorTarget->GetProperty(tidy_prop);
  815. evaluatedTIDY = cmGeneratorExpression::Evaluate(
  816. *tidy, this->LocalGenerator, config, this->GeneratorTarget, nullptr,
  817. this->GeneratorTarget, lang);
  818. if (!evaluatedTIDY.empty()) {
  819. tidy = cmValue(&evaluatedTIDY);
  820. }
  821. if (lang == "C" || lang == "CXX") {
  822. std::string const iwyu_prop = cmStrCat(lang, "_INCLUDE_WHAT_YOU_USE");
  823. iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
  824. evaluatedIWYU = cmGeneratorExpression::Evaluate(
  825. *iwyu, this->LocalGenerator, config, this->GeneratorTarget, nullptr,
  826. this->GeneratorTarget, lang);
  827. if (!evaluatedIWYU.empty()) {
  828. iwyu = cmValue(&evaluatedIWYU);
  829. }
  830. std::string const cpplint_prop = cmStrCat(lang, "_CPPLINT");
  831. cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
  832. evaluatedCPPlint = cmGeneratorExpression::Evaluate(
  833. *cpplint, this->LocalGenerator, config, this->GeneratorTarget, nullptr,
  834. this->GeneratorTarget, lang);
  835. if (!evaluatedCPPlint.empty()) {
  836. cpplint = cmValue(&evaluatedCPPlint);
  837. }
  838. std::string const cppcheck_prop = cmStrCat(lang, "_CPPCHECK");
  839. cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
  840. evaluatedCPPcheck = cmGeneratorExpression::Evaluate(
  841. *cppcheck, this->LocalGenerator, config, this->GeneratorTarget,
  842. nullptr, this->GeneratorTarget, lang);
  843. if (!evaluatedCPPcheck.empty()) {
  844. cppcheck = cmValue(&evaluatedCPPcheck);
  845. }
  846. }
  847. if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
  848. cmNonempty(cppcheck)) {
  849. std::string run_iwyu = cmStrCat(cmakeCmd, " -E __run_co_compile");
  850. if (!compilerLauncher.empty()) {
  851. // In __run_co_compile case the launcher command is supplied
  852. // via --launcher=<maybe-list> and consumed
  853. run_iwyu +=
  854. cmStrCat(" --launcher=",
  855. this->LocalGenerator->EscapeForShell(compilerLauncher));
  856. compilerLauncher.clear();
  857. }
  858. if (cmNonempty(iwyu)) {
  859. run_iwyu += " --iwyu=";
  860. // Only add --driver-mode if it is not already specified, as adding
  861. // it unconditionally might override a user-specified driver-mode
  862. if (iwyu.Get()->find("--driver-mode=") == std::string::npos) {
  863. cmValue p = this->Makefile->GetDefinition(
  864. cmStrCat("CMAKE_", lang, "_INCLUDE_WHAT_YOU_USE_DRIVER_MODE"));
  865. std::string driverMode;
  866. if (cmNonempty(p)) {
  867. driverMode = *p;
  868. } else {
  869. driverMode = lang == "C" ? "gcc" : "g++";
  870. }
  871. run_iwyu += this->LocalGenerator->EscapeForShell(
  872. cmStrCat(*iwyu, ";--driver-mode=", driverMode));
  873. } else {
  874. run_iwyu += this->LocalGenerator->EscapeForShell(*iwyu);
  875. }
  876. }
  877. if (cmNonempty(tidy)) {
  878. run_iwyu += " --tidy=";
  879. cmValue p = this->Makefile->GetDefinition(
  880. cmStrCat("CMAKE_", lang, "_CLANG_TIDY_DRIVER_MODE"));
  881. std::string driverMode;
  882. if (cmNonempty(p)) {
  883. driverMode = *p;
  884. } else {
  885. driverMode = lang == "C" ? "gcc" : "g++";
  886. }
  887. const bool haveClangTidyExportFixesDir =
  888. !this->GeneratorTarget->GetClangTidyExportFixesDirectory(lang)
  889. .empty();
  890. std::string exportFixes;
  891. if (haveClangTidyExportFixesDir) {
  892. exportFixes = ";--export-fixes=$CLANG_TIDY_EXPORT_FIXES";
  893. }
  894. run_iwyu += this->GetLocalGenerator()->EscapeForShell(
  895. cmStrCat(*tidy, ";--extra-arg-before=--driver-mode=", driverMode,
  896. exportFixes));
  897. if (haveClangTidyExportFixesDir) {
  898. std::string search = cmStrCat(
  899. this->GetLocalGenerator()->GetState()->UseWindowsShell() ? ""
  900. : "\\",
  901. "$$CLANG_TIDY_EXPORT_FIXES");
  902. auto loc = run_iwyu.rfind(search);
  903. run_iwyu.replace(loc, search.length(), "$CLANG_TIDY_EXPORT_FIXES");
  904. }
  905. }
  906. if (cmNonempty(cpplint)) {
  907. run_iwyu += cmStrCat(
  908. " --cpplint=", this->GetLocalGenerator()->EscapeForShell(*cpplint));
  909. }
  910. if (cmNonempty(cppcheck)) {
  911. run_iwyu +=
  912. cmStrCat(" --cppcheck=",
  913. this->GetLocalGenerator()->EscapeForShell(*cppcheck));
  914. }
  915. if (cmNonempty(tidy) || cmNonempty(cpplint) || cmNonempty(cppcheck)) {
  916. run_iwyu += " --source=$in";
  917. }
  918. run_iwyu += " -- ";
  919. compileCmds.front().insert(0, run_iwyu);
  920. }
  921. }
  922. // If compiler launcher was specified and not consumed above, it
  923. // goes to the beginning of the command line.
  924. if (!compileCmds.empty() && !compilerLauncher.empty()) {
  925. cmList args{ compilerLauncher, cmList::EmptyElements::Yes };
  926. if (!args.empty()) {
  927. args[0] = this->LocalGenerator->ConvertToOutputFormat(
  928. args[0], cmOutputConverter::SHELL);
  929. for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
  930. i = this->LocalGenerator->EscapeForShell(i);
  931. }
  932. }
  933. compileCmds.front().insert(0, cmStrCat(args.join(" "), ' '));
  934. }
  935. if (!compileCmds.empty()) {
  936. compileCmds.front().insert(0, cldeps);
  937. }
  938. const auto& extraCommands = this->GetMakefile()->GetSafeDefinition(
  939. cmStrCat("CMAKE_", lang, "_DEPENDS_EXTRA_COMMANDS"));
  940. if (!extraCommands.empty()) {
  941. compileCmds.append(extraCommands);
  942. }
  943. for (auto& i : compileCmds) {
  944. i = cmStrCat(launcher, i);
  945. rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), i,
  946. vars);
  947. }
  948. rule.Command =
  949. this->GetLocalGenerator()->BuildCommandLine(compileCmds, config, config);
  950. // Write the rule for compiling file of the given language.
  951. rule.Comment = cmStrCat("Rule for compiling ", lang, " files.");
  952. rule.Description = cmStrCat("Building ", lang, " object $out");
  953. this->GetGlobalGenerator()->AddRule(rule);
  954. }
  955. void cmNinjaTargetGenerator::WriteObjectBuildStatements(
  956. const std::string& config, const std::string& fileConfig,
  957. bool firstForConfig)
  958. {
  959. this->GeneratorTarget->CheckCxxModuleStatus(config);
  960. // Write comments.
  961. cmGlobalNinjaGenerator::WriteDivider(this->GetImplFileStream(fileConfig));
  962. this->GetImplFileStream(fileConfig)
  963. << "# Object build statements for "
  964. << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
  965. << " target " << this->GetTargetName() << "\n\n";
  966. {
  967. std::vector<cmSourceFile const*> customCommands;
  968. this->GeneratorTarget->GetCustomCommands(customCommands, config);
  969. for (cmSourceFile const* sf : customCommands) {
  970. cmCustomCommand const* cc = sf->GetCustomCommand();
  971. this->GetLocalGenerator()->AddCustomCommandTarget(
  972. cc, this->GetGeneratorTarget());
  973. // Record the custom commands for this target. The container is used
  974. // in WriteObjectBuildStatement when called in a loop below.
  975. this->Configs[config].CustomCommands.push_back(cc);
  976. }
  977. }
  978. {
  979. std::vector<cmSourceFile const*> headerSources;
  980. this->GeneratorTarget->GetHeaderSources(headerSources, config);
  981. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  982. headerSources, this->Configs[fileConfig].MacOSXContentGenerator.get(),
  983. config);
  984. }
  985. {
  986. std::vector<cmSourceFile const*> extraSources;
  987. this->GeneratorTarget->GetExtraSources(extraSources, config);
  988. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  989. extraSources, this->Configs[fileConfig].MacOSXContentGenerator.get(),
  990. config);
  991. }
  992. if (firstForConfig) {
  993. cmValue pchExtension =
  994. this->GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION");
  995. std::vector<cmSourceFile const*> externalObjects;
  996. this->GeneratorTarget->GetExternalObjects(externalObjects, config);
  997. for (cmSourceFile const* sf : externalObjects) {
  998. auto objectFileName = this->GetGlobalGenerator()->ExpandCFGIntDir(
  999. this->ConvertToNinjaPath(sf->GetFullPath()), config);
  1000. if (!cmHasSuffix(objectFileName, pchExtension)) {
  1001. this->Configs[config].Objects.push_back(objectFileName);
  1002. }
  1003. }
  1004. }
  1005. {
  1006. cmNinjaBuild build("phony");
  1007. build.Comment =
  1008. cmStrCat("Order-only phony target for ", this->GetTargetName());
  1009. build.Outputs.push_back(this->OrderDependsTargetForTarget(config));
  1010. cmNinjaDeps& orderOnlyDeps = build.OrderOnlyDeps;
  1011. this->GetLocalGenerator()->AppendTargetDepends(
  1012. this->GeneratorTarget, orderOnlyDeps, config, fileConfig,
  1013. DependOnTargetOrdering);
  1014. // Add order-only dependencies on other files associated with the target.
  1015. cm::append(orderOnlyDeps, this->Configs[config].ExtraFiles);
  1016. // Add order-only dependencies on custom command outputs.
  1017. for (cmCustomCommand const* cc : this->Configs[config].CustomCommands) {
  1018. cmCustomCommandGenerator ccg(*cc, config, this->GetLocalGenerator());
  1019. const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
  1020. const std::vector<std::string>& ccbyproducts = ccg.GetByproducts();
  1021. std::transform(ccoutputs.begin(), ccoutputs.end(),
  1022. std::back_inserter(orderOnlyDeps),
  1023. this->MapToNinjaPath());
  1024. std::transform(ccbyproducts.begin(), ccbyproducts.end(),
  1025. std::back_inserter(orderOnlyDeps),
  1026. this->MapToNinjaPath());
  1027. }
  1028. std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end());
  1029. orderOnlyDeps.erase(
  1030. std::unique(orderOnlyDeps.begin(), orderOnlyDeps.end()),
  1031. orderOnlyDeps.end());
  1032. // The phony target must depend on at least one input or ninja will explain
  1033. // that "output ... of phony edge with no inputs doesn't exist" and
  1034. // consider the phony output "dirty".
  1035. if (orderOnlyDeps.empty()) {
  1036. // Any path that always exists will work here. It would be nice to
  1037. // use just "." but that is not supported by Ninja < 1.7.
  1038. std::string tgtDir = cmStrCat(
  1039. this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
  1040. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget));
  1041. orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir));
  1042. }
  1043. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  1044. build);
  1045. }
  1046. {
  1047. std::vector<cmSourceFile const*> objectSources;
  1048. this->GeneratorTarget->GetObjectSources(objectSources, config);
  1049. for (cmSourceFile const* sf : objectSources) {
  1050. this->WriteObjectBuildStatement(sf, config, fileConfig, firstForConfig);
  1051. }
  1052. }
  1053. for (auto const& langScanningFiles : this->Configs[config].ScanningInfo) {
  1054. std::string const& language = langScanningFiles.first;
  1055. std::vector<ScanningFiles> const& scanningFiles = langScanningFiles.second;
  1056. cmNinjaBuild build(this->LanguageDyndepRule(language, config));
  1057. build.Outputs.push_back(this->GetDyndepFilePath(language, config));
  1058. build.ImplicitOuts.push_back(
  1059. cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
  1060. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
  1061. this->GetGlobalGenerator()->ConfigDirectory(config), '/',
  1062. language, "Modules.json"));
  1063. for (auto const& scanFiles : scanningFiles) {
  1064. if (!scanFiles.ScanningOutput.empty()) {
  1065. build.ExplicitDeps.push_back(scanFiles.ScanningOutput);
  1066. }
  1067. if (!scanFiles.ModuleMapFile.empty()) {
  1068. build.ImplicitOuts.push_back(scanFiles.ModuleMapFile);
  1069. }
  1070. }
  1071. this->WriteTargetDependInfo(language, config);
  1072. for (std::string const& l :
  1073. this->GetLinkedTargetDirectories(language, config)) {
  1074. build.ImplicitDeps.push_back(cmStrCat(l, '/', language, "Modules.json"));
  1075. }
  1076. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  1077. build);
  1078. }
  1079. this->GetImplFileStream(fileConfig) << "\n";
  1080. }
  1081. void cmNinjaTargetGenerator::GenerateSwiftOutputFileMap(
  1082. const std::string& config, std::string& flags)
  1083. {
  1084. if (this->Configs[config].SwiftOutputMap.empty()) {
  1085. return;
  1086. }
  1087. std::string const targetSwiftDepsPath = [this, config]() -> std::string {
  1088. cmGeneratorTarget const* target = this->GeneratorTarget;
  1089. if (cmValue name = target->GetProperty("Swift_DEPENDENCIES_FILE")) {
  1090. return *name;
  1091. }
  1092. return this->ConvertToNinjaPath(cmStrCat(target->GetSupportDirectory(),
  1093. '/', config, '/',
  1094. target->GetName(), ".swiftdeps"));
  1095. }();
  1096. std::string mapFilePath =
  1097. cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config, '/',
  1098. "output-file-map.json");
  1099. // build the global target dependencies
  1100. // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps
  1101. Json::Value deps(Json::objectValue);
  1102. deps["swift-dependencies"] = targetSwiftDepsPath;
  1103. this->Configs[config].SwiftOutputMap[""] = deps;
  1104. cmGeneratedFileStream output(mapFilePath);
  1105. output << this->Configs[config].SwiftOutputMap;
  1106. // Add flag
  1107. this->LocalGenerator->AppendFlags(flags, "-output-file-map");
  1108. this->LocalGenerator->AppendFlagEscape(flags,
  1109. ConvertToNinjaPath(mapFilePath));
  1110. }
  1111. namespace {
  1112. cmNinjaBuild GetScanBuildStatement(const std::string& ruleName,
  1113. const std::string& ppFileName,
  1114. bool compilePP, bool compilePPWithDefines,
  1115. bool compilationPreprocesses,
  1116. cmNinjaBuild& objBuild, cmNinjaVars& vars,
  1117. const std::string& objectFileName,
  1118. cmLocalGenerator* lg)
  1119. {
  1120. cmNinjaBuild scanBuild(ruleName);
  1121. scanBuild.RspFile = "$out.rsp";
  1122. if (compilePP) {
  1123. // Move compilation dependencies to the scan/preprocessing build statement.
  1124. std::swap(scanBuild.ExplicitDeps, objBuild.ExplicitDeps);
  1125. std::swap(scanBuild.ImplicitDeps, objBuild.ImplicitDeps);
  1126. std::swap(scanBuild.OrderOnlyDeps, objBuild.OrderOnlyDeps);
  1127. std::swap(scanBuild.Variables["IN_ABS"], vars["IN_ABS"]);
  1128. // The actual compilation will now use the preprocessed source.
  1129. objBuild.ExplicitDeps.push_back(ppFileName);
  1130. } else {
  1131. // Copy compilation dependencies to the scan/preprocessing build statement.
  1132. scanBuild.ExplicitDeps = objBuild.ExplicitDeps;
  1133. scanBuild.ImplicitDeps = objBuild.ImplicitDeps;
  1134. scanBuild.OrderOnlyDeps = objBuild.OrderOnlyDeps;
  1135. scanBuild.Variables["IN_ABS"] = vars["IN_ABS"];
  1136. }
  1137. // Scanning and compilation generally use the same flags.
  1138. scanBuild.Variables["FLAGS"] = vars["FLAGS"];
  1139. if (compilePP && !compilePPWithDefines) {
  1140. // Move preprocessor definitions to the scan/preprocessor build statement.
  1141. std::swap(scanBuild.Variables["DEFINES"], vars["DEFINES"]);
  1142. } else {
  1143. // Copy preprocessor definitions to the scan/preprocessor build statement.
  1144. scanBuild.Variables["DEFINES"] = vars["DEFINES"];
  1145. }
  1146. // Copy include directories to the preprocessor build statement. The
  1147. // Fortran compilation build statement still needs them for the INCLUDE
  1148. // directive.
  1149. scanBuild.Variables["INCLUDES"] = vars["INCLUDES"];
  1150. // Tell dependency scanner the object file that will result from
  1151. // compiling the source.
  1152. scanBuild.Variables["OBJ_FILE"] = objectFileName;
  1153. // Tell dependency scanner where to store dyndep intermediate results.
  1154. std::string const& ddiFile = cmStrCat(objectFileName, ".ddi");
  1155. scanBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile;
  1156. // Outputs of the scan/preprocessor build statement.
  1157. if (compilePP) {
  1158. scanBuild.Outputs.push_back(ppFileName);
  1159. scanBuild.ImplicitOuts.push_back(ddiFile);
  1160. } else {
  1161. scanBuild.Outputs.push_back(ddiFile);
  1162. scanBuild.Variables["PREPROCESSED_OUTPUT_FILE"] = ppFileName;
  1163. if (!compilationPreprocesses) {
  1164. // Compilation does not preprocess and we are not compiling an
  1165. // already-preprocessed source. Make compilation depend on the scan
  1166. // results to honor implicit dependencies discovered during scanning
  1167. // (such as Fortran INCLUDE directives).
  1168. objBuild.ImplicitDeps.emplace_back(ddiFile);
  1169. }
  1170. }
  1171. // Scanning always provides a depfile for preprocessor dependencies. This
  1172. // variable is unused in `msvc`-deptype scanners.
  1173. std::string const& depFileName = cmStrCat(scanBuild.Outputs.front(), ".d");
  1174. scanBuild.Variables["DEP_FILE"] =
  1175. lg->ConvertToOutputFormat(depFileName, cmOutputConverter::SHELL);
  1176. if (compilePP) {
  1177. // The actual compilation does not need a depfile because it
  1178. // depends on the already-preprocessed source.
  1179. vars.erase("DEP_FILE");
  1180. }
  1181. return scanBuild;
  1182. }
  1183. }
  1184. void cmNinjaTargetGenerator::WriteObjectBuildStatement(
  1185. cmSourceFile const* source, const std::string& config,
  1186. const std::string& fileConfig, bool firstForConfig)
  1187. {
  1188. std::string const language = source->GetLanguage();
  1189. std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source);
  1190. std::string const objectDir = this->ConvertToNinjaPath(
  1191. cmStrCat(this->GeneratorTarget->GetSupportDirectory(),
  1192. this->GetGlobalGenerator()->ConfigDirectory(config)));
  1193. std::string const objectFileName =
  1194. this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
  1195. std::string const objectFileDir =
  1196. cmSystemTools::GetFilenamePath(objectFileName);
  1197. std::string cmakeVarLang = cmStrCat("CMAKE_", language);
  1198. // build response file name
  1199. std::string cmakeLinkVar = cmStrCat(cmakeVarLang, "_RESPONSE_FILE_FLAG");
  1200. cmValue flag = this->GetMakefile()->GetDefinition(cmakeLinkVar);
  1201. bool const lang_supports_response =
  1202. !(language == "RC" || (language == "CUDA" && !flag));
  1203. int const commandLineLengthLimit =
  1204. ((lang_supports_response && this->ForceResponseFile())) ? -1 : 0;
  1205. bool const needDyndep =
  1206. this->GeneratorTarget->NeedDyndepForSource(language, config, source);
  1207. cmNinjaBuild objBuild(this->LanguageCompilerRule(
  1208. language, config, needDyndep ? WithScanning::Yes : WithScanning::No));
  1209. cmNinjaVars& vars = objBuild.Variables;
  1210. vars["FLAGS"] = this->ComputeFlagsForObject(source, language, config);
  1211. vars["DEFINES"] = this->ComputeDefines(source, language, config);
  1212. vars["INCLUDES"] = this->ComputeIncludes(source, language, config);
  1213. if (this->GetMakefile()->GetSafeDefinition(
  1214. cmStrCat("CMAKE_", language, "_DEPFILE_FORMAT")) != "msvc"_s) {
  1215. bool replaceExt(false);
  1216. if (!language.empty()) {
  1217. std::string repVar =
  1218. cmStrCat("CMAKE_", language, "_DEPFILE_EXTENSION_REPLACE");
  1219. replaceExt = this->Makefile->IsOn(repVar);
  1220. }
  1221. if (!replaceExt) {
  1222. // use original code
  1223. vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  1224. cmStrCat(objectFileName, ".d"), cmOutputConverter::SHELL);
  1225. } else {
  1226. // Replace the original source file extension with the
  1227. // depend file extension.
  1228. std::string dependFileName = cmStrCat(
  1229. cmSystemTools::GetFilenameWithoutLastExtension(objectFileName), ".d");
  1230. vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  1231. cmStrCat(objectFileDir, '/', dependFileName),
  1232. cmOutputConverter::SHELL);
  1233. }
  1234. }
  1235. std::string d =
  1236. this->GeneratorTarget->GetClangTidyExportFixesDirectory(language);
  1237. if (!d.empty()) {
  1238. this->GlobalCommonGenerator->AddClangTidyExportFixesDir(d);
  1239. std::string fixesFile =
  1240. this->GetClangTidyReplacementsFilePath(d, source, config);
  1241. this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
  1242. cmSystemTools::MakeDirectory(cmSystemTools::GetFilenamePath(fixesFile));
  1243. fixesFile = this->ConvertToNinjaPath(fixesFile);
  1244. vars["CLANG_TIDY_EXPORT_FIXES"] = fixesFile;
  1245. }
  1246. if (firstForConfig) {
  1247. this->ExportObjectCompileCommand(
  1248. language, sourceFilePath, objectDir, objectFileName, objectFileDir,
  1249. vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"], config);
  1250. }
  1251. objBuild.Outputs.push_back(objectFileName);
  1252. if (firstForConfig) {
  1253. cmValue pchExtension =
  1254. this->GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION");
  1255. if (!cmHasSuffix(objectFileName, pchExtension)) {
  1256. // Add this object to the list of object files.
  1257. this->Configs[config].Objects.push_back(objectFileName);
  1258. }
  1259. }
  1260. objBuild.ExplicitDeps.push_back(sourceFilePath);
  1261. // Add precompile headers dependencies
  1262. std::vector<std::string> depList;
  1263. std::vector<std::string> architectures =
  1264. this->GeneratorTarget->GetAppleArchs(config, language);
  1265. if (architectures.empty()) {
  1266. architectures.emplace_back();
  1267. }
  1268. std::unordered_set<std::string> pchSources;
  1269. for (const std::string& arch : architectures) {
  1270. const std::string pchSource =
  1271. this->GeneratorTarget->GetPchSource(config, language, arch);
  1272. if (!pchSource.empty()) {
  1273. pchSources.insert(pchSource);
  1274. }
  1275. }
  1276. if (!pchSources.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  1277. for (const std::string& arch : architectures) {
  1278. depList.push_back(
  1279. this->GeneratorTarget->GetPchHeader(config, language, arch));
  1280. if (pchSources.find(source->GetFullPath()) == pchSources.end()) {
  1281. depList.push_back(
  1282. this->GeneratorTarget->GetPchFile(config, language, arch));
  1283. }
  1284. }
  1285. }
  1286. if (cmValue objectDeps = source->GetProperty("OBJECT_DEPENDS")) {
  1287. cmList objDepList{ *objectDeps };
  1288. std::copy(objDepList.begin(), objDepList.end(),
  1289. std::back_inserter(depList));
  1290. }
  1291. if (!depList.empty()) {
  1292. for (std::string& odi : depList) {
  1293. if (cmSystemTools::FileIsFullPath(odi)) {
  1294. odi = cmSystemTools::CollapseFullPath(odi);
  1295. }
  1296. }
  1297. std::transform(depList.begin(), depList.end(),
  1298. std::back_inserter(objBuild.ImplicitDeps),
  1299. this->MapToNinjaPath());
  1300. }
  1301. objBuild.OrderOnlyDeps.push_back(this->OrderDependsTargetForTarget(config));
  1302. // If the source file is GENERATED and does not have a custom command
  1303. // (either attached to this source file or another one), assume that one of
  1304. // the target dependencies, OBJECT_DEPENDS or header file custom commands
  1305. // will rebuild the file.
  1306. if (source->GetIsGenerated() &&
  1307. !source->GetPropertyAsBool("__CMAKE_GENERATED_BY_CMAKE") &&
  1308. !source->GetCustomCommand() &&
  1309. !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFilePath)) {
  1310. this->GetGlobalGenerator()->AddAssumedSourceDependencies(
  1311. sourceFilePath, objBuild.OrderOnlyDeps);
  1312. }
  1313. // For some cases we scan to dynamically discover dependencies.
  1314. bool const compilationPreprocesses =
  1315. !this->NeedExplicitPreprocessing(language);
  1316. std::string modmapFormat;
  1317. if (needDyndep) {
  1318. std::string const modmapFormatVar =
  1319. cmStrCat("CMAKE_EXPERIMENTAL_", language, "_MODULE_MAP_FORMAT");
  1320. modmapFormat = this->Makefile->GetSafeDefinition(modmapFormatVar);
  1321. }
  1322. if (needDyndep) {
  1323. // If source/target has preprocessing turned off, we still need to
  1324. // generate an explicit dependency step
  1325. const auto srcpp = source->GetSafeProperty("Fortran_PREPROCESS");
  1326. cmOutputConverter::FortranPreprocess preprocess =
  1327. cmOutputConverter::GetFortranPreprocess(srcpp);
  1328. if (preprocess == cmOutputConverter::FortranPreprocess::Unset) {
  1329. const auto& tgtpp =
  1330. this->GeneratorTarget->GetSafeProperty("Fortran_PREPROCESS");
  1331. preprocess = cmOutputConverter::GetFortranPreprocess(tgtpp);
  1332. }
  1333. bool const compilePP = !compilationPreprocesses &&
  1334. (preprocess != cmOutputConverter::FortranPreprocess::NotNeeded);
  1335. bool const compilePPWithDefines =
  1336. compilePP && this->CompileWithDefines(language);
  1337. std::string scanRuleName;
  1338. std::string ppFileName;
  1339. if (compilePP) {
  1340. scanRuleName = this->LanguagePreprocessAndScanRule(language, config);
  1341. ppFileName = this->ConvertToNinjaPath(
  1342. this->GetPreprocessedFilePath(source, config));
  1343. } else {
  1344. scanRuleName = this->LanguageScanRule(language, config);
  1345. ppFileName = cmStrCat(objectFileName, ".ddi.i");
  1346. }
  1347. cmNinjaBuild ppBuild = GetScanBuildStatement(
  1348. scanRuleName, ppFileName, compilePP, compilePPWithDefines,
  1349. compilationPreprocesses, objBuild, vars, objectFileName,
  1350. this->LocalGenerator);
  1351. if (compilePP) {
  1352. // In case compilation requires flags that are incompatible with
  1353. // preprocessing, include them here.
  1354. std::string const& postFlag = this->Makefile->GetSafeDefinition(
  1355. cmStrCat("CMAKE_", language, "_POSTPROCESS_FLAG"));
  1356. this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag);
  1357. // Prepend source file's original directory as an include directory
  1358. // so e.g. Fortran INCLUDE statements can look for files in it.
  1359. std::vector<std::string> sourceDirectory;
  1360. sourceDirectory.push_back(
  1361. cmSystemTools::GetParentDirectory(source->GetFullPath()));
  1362. std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags(
  1363. sourceDirectory, this->GeneratorTarget, language, config, false);
  1364. vars["INCLUDES"] = cmStrCat(sourceDirectoryFlag, ' ', vars["INCLUDES"]);
  1365. }
  1366. ScanningFiles scanningFiles;
  1367. if (firstForConfig) {
  1368. scanningFiles.ScanningOutput = cmStrCat(objectFileName, ".ddi");
  1369. }
  1370. this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
  1371. ppBuild.Variables);
  1372. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  1373. ppBuild, commandLineLengthLimit);
  1374. std::string const dyndep = this->GetDyndepFilePath(language, config);
  1375. objBuild.OrderOnlyDeps.push_back(dyndep);
  1376. vars["dyndep"] = dyndep;
  1377. if (!modmapFormat.empty()) {
  1378. // XXX(modmap): If changing this path construction, change
  1379. // `cmGlobalNinjaGenerator::WriteDyndep` to expect the corresponding file
  1380. // path.
  1381. std::string ddModmapFile = cmStrCat(objectFileName, ".modmap");
  1382. vars["DYNDEP_MODULE_MAP_FILE"] = ddModmapFile;
  1383. objBuild.OrderOnlyDeps.push_back(ddModmapFile);
  1384. scanningFiles.ModuleMapFile = std::move(ddModmapFile);
  1385. }
  1386. if (!scanningFiles.IsEmpty()) {
  1387. this->Configs[config].ScanningInfo[language].emplace_back(scanningFiles);
  1388. }
  1389. }
  1390. this->EnsureParentDirectoryExists(objectFileName);
  1391. vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  1392. objectDir, cmOutputConverter::SHELL);
  1393. vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
  1394. objectFileDir, cmOutputConverter::SHELL);
  1395. this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
  1396. vars);
  1397. if (!pchSources.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  1398. auto pchIt = pchSources.find(source->GetFullPath());
  1399. if (pchIt != pchSources.end()) {
  1400. this->addPoolNinjaVariable("JOB_POOL_PRECOMPILE_HEADER",
  1401. this->GetGeneratorTarget(), vars);
  1402. }
  1403. }
  1404. this->SetMsvcTargetPdbVariable(vars, config);
  1405. objBuild.RspFile = cmStrCat(objectFileName, ".rsp");
  1406. if (language == "ISPC") {
  1407. std::string const& objectName =
  1408. this->GeneratorTarget->GetObjectName(source);
  1409. std::string ispcSource =
  1410. cmSystemTools::GetFilenameWithoutLastExtension(objectName);
  1411. ispcSource = cmSystemTools::GetFilenameWithoutLastExtension(ispcSource);
  1412. cmValue ispcSuffixProp =
  1413. this->GeneratorTarget->GetProperty("ISPC_HEADER_SUFFIX");
  1414. assert(ispcSuffixProp);
  1415. std::string ispcHeaderDirectory =
  1416. this->GeneratorTarget->GetObjectDirectory(config);
  1417. if (cmValue prop =
  1418. this->GeneratorTarget->GetProperty("ISPC_HEADER_DIRECTORY")) {
  1419. ispcHeaderDirectory =
  1420. cmStrCat(this->LocalGenerator->GetBinaryDirectory(), '/', *prop);
  1421. }
  1422. std::string ispcHeader =
  1423. cmStrCat(ispcHeaderDirectory, '/', ispcSource, *ispcSuffixProp);
  1424. ispcHeader = this->ConvertToNinjaPath(ispcHeader);
  1425. // Make sure ninja knows what command generates the header
  1426. objBuild.ImplicitOuts.push_back(ispcHeader);
  1427. // Make sure ninja knows how to clean the generated header
  1428. this->GetGlobalGenerator()->AddAdditionalCleanFile(ispcHeader, config);
  1429. auto ispcSuffixes =
  1430. detail::ComputeISPCObjectSuffixes(this->GeneratorTarget);
  1431. if (ispcSuffixes.size() > 1) {
  1432. std::string rootObjectDir =
  1433. this->GeneratorTarget->GetObjectDirectory(config);
  1434. auto ispcSideEfffectObjects = detail::ComputeISPCExtraObjects(
  1435. objectName, rootObjectDir, ispcSuffixes);
  1436. for (auto sideEffect : ispcSideEfffectObjects) {
  1437. sideEffect = this->ConvertToNinjaPath(sideEffect);
  1438. objBuild.ImplicitOuts.emplace_back(sideEffect);
  1439. this->GetGlobalGenerator()->AddAdditionalCleanFile(sideEffect, config);
  1440. }
  1441. }
  1442. vars["ISPC_HEADER_FILE"] =
  1443. this->GetLocalGenerator()->ConvertToOutputFormat(
  1444. ispcHeader, cmOutputConverter::SHELL);
  1445. } else {
  1446. auto headers = this->GeneratorTarget->GetGeneratedISPCHeaders(config);
  1447. if (!headers.empty()) {
  1448. std::transform(headers.begin(), headers.end(), headers.begin(),
  1449. this->MapToNinjaPath());
  1450. objBuild.OrderOnlyDeps.insert(objBuild.OrderOnlyDeps.end(),
  1451. headers.begin(), headers.end());
  1452. }
  1453. }
  1454. if (language == "Swift") {
  1455. this->EmitSwiftDependencyInfo(source, config);
  1456. } else {
  1457. this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
  1458. objBuild, commandLineLengthLimit);
  1459. }
  1460. if (cmValue objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
  1461. std::string evaluatedObjectOutputs = cmGeneratorExpression::Evaluate(
  1462. *objectOutputs, this->LocalGenerator, config);
  1463. if (!evaluatedObjectOutputs.empty()) {
  1464. cmNinjaBuild build("phony");
  1465. build.Comment = "Additional output files.";
  1466. build.Outputs = cmList{ evaluatedObjectOutputs }.data();
  1467. std::transform(build.Outputs.begin(), build.Outputs.end(),
  1468. build.Outputs.begin(), this->MapToNinjaPath());
  1469. build.ExplicitDeps = objBuild.Outputs;
  1470. this->GetGlobalGenerator()->WriteBuild(
  1471. this->GetImplFileStream(fileConfig), build);
  1472. }
  1473. }
  1474. }
  1475. void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang,
  1476. const std::string& config)
  1477. {
  1478. Json::Value tdi(Json::objectValue);
  1479. tdi["language"] = lang;
  1480. tdi["compiler-id"] = this->Makefile->GetSafeDefinition(
  1481. cmStrCat("CMAKE_", lang, "_COMPILER_ID"));
  1482. tdi["compiler-simulate-id"] = this->Makefile->GetSafeDefinition(
  1483. cmStrCat("CMAKE_", lang, "_SIMULATE_ID"));
  1484. tdi["compiler-frontend-variant"] = this->Makefile->GetSafeDefinition(
  1485. cmStrCat("CMAKE_", lang, "_COMPILER_FRONTEND_VARIANT"));
  1486. std::string mod_dir;
  1487. if (lang == "Fortran") {
  1488. mod_dir = this->GeneratorTarget->GetFortranModuleDirectory(
  1489. this->Makefile->GetHomeOutputDirectory());
  1490. } else if (lang == "CXX") {
  1491. mod_dir = this->GetGlobalGenerator()->ExpandCFGIntDir(
  1492. cmSystemTools::CollapseFullPath(this->GeneratorTarget->ObjectDirectory),
  1493. config);
  1494. }
  1495. if (mod_dir.empty()) {
  1496. mod_dir = this->Makefile->GetCurrentBinaryDirectory();
  1497. }
  1498. tdi["module-dir"] = mod_dir;
  1499. if (lang == "Fortran") {
  1500. tdi["submodule-sep"] =
  1501. this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_SEP");
  1502. tdi["submodule-ext"] =
  1503. this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_EXT");
  1504. } else if (lang == "CXX") {
  1505. // No extra information necessary.
  1506. }
  1507. tdi["dir-cur-bld"] = this->Makefile->GetCurrentBinaryDirectory();
  1508. tdi["dir-cur-src"] = this->Makefile->GetCurrentSourceDirectory();
  1509. tdi["dir-top-bld"] = this->Makefile->GetHomeOutputDirectory();
  1510. tdi["dir-top-src"] = this->Makefile->GetHomeDirectory();
  1511. Json::Value& tdi_include_dirs = tdi["include-dirs"] = Json::arrayValue;
  1512. std::vector<std::string> includes;
  1513. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  1514. lang, config);
  1515. for (std::string const& i : includes) {
  1516. // Convert the include directories the same way we do for -I flags.
  1517. // See upstream ninja issue 1251.
  1518. tdi_include_dirs.append(this->ConvertToNinjaPath(i));
  1519. }
  1520. Json::Value& tdi_linked_target_dirs = tdi["linked-target-dirs"] =
  1521. Json::arrayValue;
  1522. for (std::string const& l : this->GetLinkedTargetDirectories(lang, config)) {
  1523. tdi_linked_target_dirs.append(l);
  1524. }
  1525. cmDyndepGeneratorCallbacks cb;
  1526. cb.ObjectFilePath = [this](cmSourceFile const* sf, std::string const& cnf) {
  1527. return this->GetObjectFilePath(sf, cnf);
  1528. };
  1529. #if !defined(CMAKE_BOOTSTRAP)
  1530. cmDyndepCollation::AddCollationInformation(tdi, this->GeneratorTarget,
  1531. config, cb);
  1532. #endif
  1533. std::string const tdin = this->GetTargetDependInfoPath(lang, config);
  1534. cmGeneratedFileStream tdif(tdin);
  1535. tdif << tdi;
  1536. }
  1537. void cmNinjaTargetGenerator::EmitSwiftDependencyInfo(
  1538. cmSourceFile const* source, const std::string& config)
  1539. {
  1540. std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source);
  1541. std::string const objectFilePath =
  1542. this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
  1543. std::string const swiftDepsPath = [source, objectFilePath]() -> std::string {
  1544. if (cmValue name = source->GetProperty("Swift_DEPENDENCIES_FILE")) {
  1545. return *name;
  1546. }
  1547. return cmStrCat(objectFilePath, ".swiftdeps");
  1548. }();
  1549. std::string const swiftDiaPath = [source, objectFilePath]() -> std::string {
  1550. if (cmValue name = source->GetProperty("Swift_DIAGNOSTICS_FILE")) {
  1551. return *name;
  1552. }
  1553. return cmStrCat(objectFilePath, ".dia");
  1554. }();
  1555. std::string const makeDepsPath = [this, source, config]() -> std::string {
  1556. cmLocalNinjaGenerator const* local = this->GetLocalGenerator();
  1557. std::string const objectFileName =
  1558. this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
  1559. std::string const objectFileDir =
  1560. cmSystemTools::GetFilenamePath(objectFileName);
  1561. if (this->Makefile->IsOn("CMAKE_Swift_DEPFLE_EXTNSION_REPLACE")) {
  1562. std::string dependFileName = cmStrCat(
  1563. cmSystemTools::GetFilenameWithoutLastExtension(objectFileName), ".d");
  1564. return local->ConvertToOutputFormat(
  1565. cmStrCat(objectFileDir, '/', dependFileName),
  1566. cmOutputConverter::SHELL);
  1567. }
  1568. return local->ConvertToOutputFormat(cmStrCat(objectFileName, ".d"),
  1569. cmOutputConverter::SHELL);
  1570. }();
  1571. // build the source file mapping
  1572. // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps
  1573. Json::Value entry = Json::Value(Json::objectValue);
  1574. entry["object"] = objectFilePath;
  1575. entry["dependencies"] = makeDepsPath;
  1576. entry["swift-dependencies"] = swiftDepsPath;
  1577. entry["diagnostics"] = swiftDiaPath;
  1578. this->Configs[config].SwiftOutputMap[sourceFilePath] = entry;
  1579. }
  1580. void cmNinjaTargetGenerator::ExportObjectCompileCommand(
  1581. std::string const& language, std::string const& sourceFileName,
  1582. std::string const& objectDir, std::string const& objectFileName,
  1583. std::string const& objectFileDir, std::string const& flags,
  1584. std::string const& defines, std::string const& includes,
  1585. std::string const& outputConfig)
  1586. {
  1587. if (!this->GeneratorTarget->GetPropertyAsBool("EXPORT_COMPILE_COMMANDS")) {
  1588. return;
  1589. }
  1590. cmRulePlaceholderExpander::RuleVariables compileObjectVars;
  1591. compileObjectVars.Language = language.c_str();
  1592. std::string escapedSourceFileName = sourceFileName;
  1593. if (!cmSystemTools::FileIsFullPath(sourceFileName)) {
  1594. escapedSourceFileName =
  1595. cmSystemTools::CollapseFullPath(escapedSourceFileName,
  1596. this->GetGlobalGenerator()
  1597. ->GetCMakeInstance()
  1598. ->GetHomeOutputDirectory());
  1599. }
  1600. escapedSourceFileName = this->LocalGenerator->ConvertToOutputFormat(
  1601. escapedSourceFileName, cmOutputConverter::SHELL);
  1602. compileObjectVars.Source = escapedSourceFileName.c_str();
  1603. compileObjectVars.Object = objectFileName.c_str();
  1604. compileObjectVars.ObjectDir = objectDir.c_str();
  1605. compileObjectVars.ObjectFileDir = objectFileDir.c_str();
  1606. compileObjectVars.Flags = flags.c_str();
  1607. compileObjectVars.Defines = defines.c_str();
  1608. compileObjectVars.Includes = includes.c_str();
  1609. // Rule for compiling object file.
  1610. std::string cudaCompileMode;
  1611. if (language == "CUDA") {
  1612. if (this->GeneratorTarget->GetPropertyAsBool(
  1613. "CUDA_SEPARABLE_COMPILATION")) {
  1614. const std::string& rdcFlag =
  1615. this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_RDC_FLAG");
  1616. cudaCompileMode = cmStrCat(cudaCompileMode, rdcFlag, " ");
  1617. }
  1618. static std::array<cm::string_view, 4> const compileModes{
  1619. { "PTX"_s, "CUBIN"_s, "FATBIN"_s, "OPTIX"_s }
  1620. };
  1621. bool useNormalCompileMode = true;
  1622. for (cm::string_view mode : compileModes) {
  1623. auto propName = cmStrCat("CUDA_", mode, "_COMPILATION");
  1624. auto defName = cmStrCat("_CMAKE_CUDA_", mode, "_FLAG");
  1625. if (this->GeneratorTarget->GetPropertyAsBool(propName)) {
  1626. const std::string& flag =
  1627. this->Makefile->GetRequiredDefinition(defName);
  1628. cudaCompileMode = cmStrCat(cudaCompileMode, flag);
  1629. useNormalCompileMode = false;
  1630. break;
  1631. }
  1632. }
  1633. if (useNormalCompileMode) {
  1634. const std::string& wholeFlag =
  1635. this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_WHOLE_FLAG");
  1636. cudaCompileMode = cmStrCat(cudaCompileMode, wholeFlag);
  1637. }
  1638. compileObjectVars.CudaCompileMode = cudaCompileMode.c_str();
  1639. }
  1640. const std::string cmdVar = cmStrCat("CMAKE_", language, "_COMPILE_OBJECT");
  1641. const std::string& compileCmd =
  1642. this->Makefile->GetRequiredDefinition(cmdVar);
  1643. cmList compileCmds(compileCmd);
  1644. auto rulePlaceholderExpander =
  1645. this->GetLocalGenerator()->CreateRulePlaceholderExpander();
  1646. for (auto& i : compileCmds) {
  1647. // no launcher for CMAKE_EXPORT_COMPILE_COMMANDS
  1648. rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), i,
  1649. compileObjectVars);
  1650. }
  1651. std::string cmdLine = this->GetLocalGenerator()->BuildCommandLine(
  1652. compileCmds, outputConfig, outputConfig);
  1653. this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName,
  1654. objectFileName);
  1655. }
  1656. void cmNinjaTargetGenerator::AdditionalCleanFiles(const std::string& config)
  1657. {
  1658. if (cmValue prop_value =
  1659. this->GeneratorTarget->GetProperty("ADDITIONAL_CLEAN_FILES")) {
  1660. cmLocalNinjaGenerator* lg = this->LocalGenerator;
  1661. cmList cleanFiles(cmGeneratorExpression::Evaluate(*prop_value, lg, config,
  1662. this->GeneratorTarget));
  1663. std::string const& binaryDir = lg->GetCurrentBinaryDirectory();
  1664. cmGlobalNinjaGenerator* gg = lg->GetGlobalNinjaGenerator();
  1665. for (auto const& cleanFile : cleanFiles) {
  1666. // Support relative paths
  1667. gg->AddAdditionalCleanFile(
  1668. cmSystemTools::CollapseFullPath(cleanFile, binaryDir), config);
  1669. }
  1670. }
  1671. }
  1672. cmNinjaDeps cmNinjaTargetGenerator::GetObjects(const std::string& config) const
  1673. {
  1674. auto const it = this->Configs.find(config);
  1675. if (it != this->Configs.end()) {
  1676. return it->second.Objects;
  1677. }
  1678. return {};
  1679. }
  1680. void cmNinjaTargetGenerator::EnsureDirectoryExists(
  1681. const std::string& path) const
  1682. {
  1683. if (cmSystemTools::FileIsFullPath(path)) {
  1684. cmSystemTools::MakeDirectory(path);
  1685. } else {
  1686. cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
  1687. std::string fullPath = gg->GetCMakeInstance()->GetHomeOutputDirectory();
  1688. // Also ensures there is a trailing slash.
  1689. gg->StripNinjaOutputPathPrefixAsSuffix(fullPath);
  1690. fullPath += path;
  1691. cmSystemTools::MakeDirectory(fullPath);
  1692. }
  1693. }
  1694. void cmNinjaTargetGenerator::EnsureParentDirectoryExists(
  1695. const std::string& path) const
  1696. {
  1697. this->EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path));
  1698. }
  1699. void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
  1700. cmSourceFile const& source, const char* pkgloc, const std::string& config)
  1701. {
  1702. // Skip OS X content when not building a Framework or Bundle.
  1703. if (!this->Generator->GetGeneratorTarget()->IsBundleOnApple()) {
  1704. return;
  1705. }
  1706. std::string macdir =
  1707. this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc,
  1708. config);
  1709. // Reject files that collide with files from the Ninja file's native config.
  1710. if (config != this->FileConfig) {
  1711. std::string nativeMacdir =
  1712. this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(
  1713. pkgloc, this->FileConfig);
  1714. if (macdir == nativeMacdir) {
  1715. return;
  1716. }
  1717. }
  1718. // Get the input file location.
  1719. std::string input = source.GetFullPath();
  1720. input = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(input);
  1721. // Get the output file location.
  1722. std::string output =
  1723. cmStrCat(macdir, '/', cmSystemTools::GetFilenameName(input));
  1724. output = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(output);
  1725. // Write a build statement to copy the content into the bundle.
  1726. this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(
  1727. input, output, this->FileConfig);
  1728. // Add as a dependency to the target so that it gets called.
  1729. this->Generator->Configs[config].ExtraFiles.push_back(std::move(output));
  1730. }
  1731. void cmNinjaTargetGenerator::addPoolNinjaVariable(
  1732. const std::string& pool_property, cmGeneratorTarget* target,
  1733. cmNinjaVars& vars)
  1734. {
  1735. cmValue pool = target->GetProperty(pool_property);
  1736. if (pool) {
  1737. vars["pool"] = *pool;
  1738. }
  1739. }
  1740. bool cmNinjaTargetGenerator::ForceResponseFile()
  1741. {
  1742. static std::string const forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE";
  1743. return (this->GetMakefile()->IsDefinitionSet(forceRspFile) ||
  1744. cmSystemTools::HasEnv(forceRspFile));
  1745. }