cmMakefileTargetGenerator.cxx 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmMakefileTargetGenerator.h"
  11. #include "cmAlgorithms.h"
  12. #include "cmComputeLinkInformation.h"
  13. #include "cmCustomCommandGenerator.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include "cmGeneratorExpression.h"
  16. #include "cmGeneratorTarget.h"
  17. #include "cmGlobalGenerator.h"
  18. #include "cmGlobalUnixMakefileGenerator3.h"
  19. #include "cmLocalUnixMakefileGenerator3.h"
  20. #include "cmMakefile.h"
  21. #include "cmSourceFile.h"
  22. #include "cmState.h"
  23. #include "cmake.h"
  24. #include "cmMakefileExecutableTargetGenerator.h"
  25. #include "cmMakefileLibraryTargetGenerator.h"
  26. #include "cmMakefileUtilityTargetGenerator.h"
  27. #include <ctype.h>
  28. cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target)
  29. : cmCommonTargetGenerator(cmOutputConverter::START_OUTPUT, target)
  30. , OSXBundleGenerator(0)
  31. , MacOSXContentGenerator(0)
  32. {
  33. this->BuildFileStream = 0;
  34. this->InfoFileStream = 0;
  35. this->FlagFileStream = 0;
  36. this->CustomCommandDriver = OnBuild;
  37. this->LocalGenerator =
  38. static_cast<cmLocalUnixMakefileGenerator3*>(target->GetLocalGenerator());
  39. this->GlobalGenerator = static_cast<cmGlobalUnixMakefileGenerator3*>(
  40. this->LocalGenerator->GetGlobalGenerator());
  41. cmake* cm = this->GlobalGenerator->GetCMakeInstance();
  42. this->NoRuleMessages = false;
  43. if (const char* ruleStatus =
  44. cm->GetState()->GetGlobalProperty("RULE_MESSAGES")) {
  45. this->NoRuleMessages = cmSystemTools::IsOff(ruleStatus);
  46. }
  47. MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
  48. }
  49. cmMakefileTargetGenerator::~cmMakefileTargetGenerator()
  50. {
  51. delete MacOSXContentGenerator;
  52. }
  53. cmMakefileTargetGenerator* cmMakefileTargetGenerator::New(
  54. cmGeneratorTarget* tgt)
  55. {
  56. cmMakefileTargetGenerator* result = 0;
  57. switch (tgt->GetType()) {
  58. case cmState::EXECUTABLE:
  59. result = new cmMakefileExecutableTargetGenerator(tgt);
  60. break;
  61. case cmState::STATIC_LIBRARY:
  62. case cmState::SHARED_LIBRARY:
  63. case cmState::MODULE_LIBRARY:
  64. case cmState::OBJECT_LIBRARY:
  65. result = new cmMakefileLibraryTargetGenerator(tgt);
  66. break;
  67. case cmState::UTILITY:
  68. result = new cmMakefileUtilityTargetGenerator(tgt);
  69. break;
  70. default:
  71. return result;
  72. // break; /* unreachable */
  73. }
  74. return result;
  75. }
  76. void cmMakefileTargetGenerator::CreateRuleFile()
  77. {
  78. // Create a directory for this target.
  79. this->TargetBuildDirectory =
  80. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  81. this->TargetBuildDirectoryFull =
  82. this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
  83. cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
  84. // Construct the rule file name.
  85. this->BuildFileName = this->TargetBuildDirectory;
  86. this->BuildFileName += "/build.make";
  87. this->BuildFileNameFull = this->TargetBuildDirectoryFull;
  88. this->BuildFileNameFull += "/build.make";
  89. // Construct the rule file name.
  90. this->ProgressFileNameFull = this->TargetBuildDirectoryFull;
  91. this->ProgressFileNameFull += "/progress.make";
  92. // reset the progress count
  93. this->NumberOfProgressActions = 0;
  94. // Open the rule file. This should be copy-if-different because the
  95. // rules may depend on this file itself.
  96. this->BuildFileStream =
  97. new cmGeneratedFileStream(this->BuildFileNameFull.c_str());
  98. this->BuildFileStream->SetCopyIfDifferent(true);
  99. if (!this->BuildFileStream) {
  100. return;
  101. }
  102. this->LocalGenerator->WriteDisclaimer(*this->BuildFileStream);
  103. if (this->GlobalGenerator->AllowDeleteOnError()) {
  104. std::vector<std::string> no_depends;
  105. std::vector<std::string> no_commands;
  106. this->LocalGenerator->WriteMakeRule(
  107. *this->BuildFileStream, "Delete rule output on recipe failure.",
  108. ".DELETE_ON_ERROR", no_depends, no_commands, false);
  109. }
  110. this->LocalGenerator->WriteSpecialTargetsTop(*this->BuildFileStream);
  111. }
  112. void cmMakefileTargetGenerator::WriteTargetBuildRules()
  113. {
  114. const std::string& config =
  115. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  116. // write the custom commands for this target
  117. // Look for files registered for cleaning in this directory.
  118. if (const char* additional_clean_files =
  119. this->Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES")) {
  120. cmGeneratorExpression ge;
  121. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  122. ge.Parse(additional_clean_files);
  123. cmSystemTools::ExpandListArgument(
  124. cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget,
  125. 0, 0),
  126. this->CleanFiles);
  127. }
  128. // add custom commands to the clean rules?
  129. const char* clean_no_custom = this->Makefile->GetProperty("CLEAN_NO_CUSTOM");
  130. bool clean = cmSystemTools::IsOff(clean_no_custom);
  131. // First generate the object rule files. Save a list of all object
  132. // files for this target.
  133. std::vector<cmSourceFile const*> customCommands;
  134. this->GeneratorTarget->GetCustomCommands(customCommands, config);
  135. for (std::vector<cmSourceFile const*>::const_iterator si =
  136. customCommands.begin();
  137. si != customCommands.end(); ++si) {
  138. cmCustomCommandGenerator ccg(*(*si)->GetCustomCommand(), this->ConfigName,
  139. this->LocalGenerator);
  140. this->GenerateCustomRuleFile(ccg);
  141. if (clean) {
  142. const std::vector<std::string>& outputs = ccg.GetOutputs();
  143. for (std::vector<std::string>::const_iterator o = outputs.begin();
  144. o != outputs.end(); ++o) {
  145. this->CleanFiles.push_back(this->Convert(
  146. *o, cmLocalGenerator::START_OUTPUT, cmLocalGenerator::UNCHANGED));
  147. }
  148. }
  149. }
  150. std::vector<cmSourceFile const*> headerSources;
  151. this->GeneratorTarget->GetHeaderSources(headerSources, config);
  152. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  153. headerSources, this->MacOSXContentGenerator);
  154. std::vector<cmSourceFile const*> extraSources;
  155. this->GeneratorTarget->GetExtraSources(extraSources, config);
  156. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  157. extraSources, this->MacOSXContentGenerator);
  158. std::vector<cmSourceFile const*> externalObjects;
  159. this->GeneratorTarget->GetExternalObjects(externalObjects, config);
  160. for (std::vector<cmSourceFile const*>::const_iterator si =
  161. externalObjects.begin();
  162. si != externalObjects.end(); ++si) {
  163. this->ExternalObjects.push_back((*si)->GetFullPath());
  164. }
  165. std::vector<cmSourceFile const*> objectSources;
  166. this->GeneratorTarget->GetObjectSources(objectSources, config);
  167. for (std::vector<cmSourceFile const*>::const_iterator si =
  168. objectSources.begin();
  169. si != objectSources.end(); ++si) {
  170. // Generate this object file's rule file.
  171. this->WriteObjectRuleFiles(**si);
  172. }
  173. }
  174. void cmMakefileTargetGenerator::WriteCommonCodeRules()
  175. {
  176. const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")
  177. ? "$(CMAKE_BINARY_DIR)/"
  178. : "");
  179. // Include the dependencies for the target.
  180. std::string dependFileNameFull = this->TargetBuildDirectoryFull;
  181. dependFileNameFull += "/depend.make";
  182. *this->BuildFileStream
  183. << "# Include any dependencies generated for this target.\n"
  184. << this->GlobalGenerator->IncludeDirective << " " << root
  185. << this->Convert(dependFileNameFull, cmLocalGenerator::HOME_OUTPUT,
  186. cmLocalGenerator::MAKERULE)
  187. << "\n\n";
  188. if (!this->NoRuleMessages) {
  189. // Include the progress variables for the target.
  190. *this->BuildFileStream
  191. << "# Include the progress variables for this target.\n"
  192. << this->GlobalGenerator->IncludeDirective << " " << root
  193. << this->Convert(this->ProgressFileNameFull,
  194. cmLocalGenerator::HOME_OUTPUT,
  195. cmLocalGenerator::MAKERULE)
  196. << "\n\n";
  197. }
  198. // make sure the depend file exists
  199. if (!cmSystemTools::FileExists(dependFileNameFull.c_str())) {
  200. // Write an empty dependency file.
  201. cmGeneratedFileStream depFileStream(dependFileNameFull.c_str());
  202. depFileStream << "# Empty dependencies file for "
  203. << this->GeneratorTarget->GetName() << ".\n"
  204. << "# This may be replaced when dependencies are built."
  205. << std::endl;
  206. }
  207. // Open the flags file. This should be copy-if-different because the
  208. // rules may depend on this file itself.
  209. this->FlagFileNameFull = this->TargetBuildDirectoryFull;
  210. this->FlagFileNameFull += "/flags.make";
  211. this->FlagFileStream =
  212. new cmGeneratedFileStream(this->FlagFileNameFull.c_str());
  213. this->FlagFileStream->SetCopyIfDifferent(true);
  214. if (!this->FlagFileStream) {
  215. return;
  216. }
  217. this->LocalGenerator->WriteDisclaimer(*this->FlagFileStream);
  218. // Include the flags for the target.
  219. *this->BuildFileStream
  220. << "# Include the compile flags for this target's objects.\n"
  221. << this->GlobalGenerator->IncludeDirective << " " << root
  222. << this->Convert(this->FlagFileNameFull, cmLocalGenerator::HOME_OUTPUT,
  223. cmLocalGenerator::MAKERULE)
  224. << "\n\n";
  225. }
  226. void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
  227. {
  228. // write language flags for target
  229. std::set<std::string> languages;
  230. this->GeneratorTarget->GetLanguages(
  231. languages, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  232. // put the compiler in the rules.make file so that if it changes
  233. // things rebuild
  234. for (std::set<std::string>::const_iterator l = languages.begin();
  235. l != languages.end(); ++l) {
  236. std::string compiler = "CMAKE_";
  237. compiler += *l;
  238. compiler += "_COMPILER";
  239. *this->FlagFileStream << "# compile " << *l << " with "
  240. << this->Makefile->GetSafeDefinition(compiler)
  241. << "\n";
  242. }
  243. for (std::set<std::string>::const_iterator l = languages.begin();
  244. l != languages.end(); ++l) {
  245. std::string flags = this->GetFlags(*l);
  246. std::string defines = this->GetDefines(*l);
  247. std::string includes = this->GetIncludes(*l);
  248. // Escape comment characters so they do not terminate assignment.
  249. cmSystemTools::ReplaceString(flags, "#", "\\#");
  250. cmSystemTools::ReplaceString(defines, "#", "\\#");
  251. cmSystemTools::ReplaceString(includes, "#", "\\#");
  252. *this->FlagFileStream << *l << "_FLAGS = " << flags << "\n\n";
  253. *this->FlagFileStream << *l << "_DEFINES = " << defines << "\n\n";
  254. *this->FlagFileStream << *l << "_INCLUDES = " << includes << "\n\n";
  255. }
  256. }
  257. void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
  258. cmSourceFile const& source, const char* pkgloc)
  259. {
  260. // Skip OS X content when not building a Framework or Bundle.
  261. if (!this->Generator->GetGeneratorTarget()->IsBundleOnApple()) {
  262. return;
  263. }
  264. std::string macdir =
  265. this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
  266. // Get the input file location.
  267. std::string input = source.GetFullPath();
  268. // Get the output file location.
  269. std::string output = macdir;
  270. output += "/";
  271. output += cmSystemTools::GetFilenameName(input);
  272. this->Generator->CleanFiles.push_back(
  273. this->Generator->Convert(output, cmLocalGenerator::START_OUTPUT));
  274. output = this->Generator->Convert(output, cmLocalGenerator::HOME_OUTPUT);
  275. // Create a rule to copy the content into the bundle.
  276. std::vector<std::string> depends;
  277. std::vector<std::string> commands;
  278. depends.push_back(input);
  279. std::string copyEcho = "Copying OS X content ";
  280. copyEcho += output;
  281. this->Generator->LocalGenerator->AppendEcho(
  282. commands, copyEcho.c_str(), cmLocalUnixMakefileGenerator3::EchoBuild);
  283. std::string copyCommand = "$(CMAKE_COMMAND) -E copy ";
  284. copyCommand += this->Generator->Convert(input, cmLocalGenerator::NONE,
  285. cmLocalGenerator::SHELL);
  286. copyCommand += " ";
  287. copyCommand += this->Generator->Convert(output, cmLocalGenerator::NONE,
  288. cmLocalGenerator::SHELL);
  289. commands.push_back(copyCommand);
  290. this->Generator->LocalGenerator->WriteMakeRule(
  291. *this->Generator->BuildFileStream, 0, output, depends, commands, false);
  292. this->Generator->ExtraFiles.insert(output);
  293. }
  294. void cmMakefileTargetGenerator::WriteObjectRuleFiles(
  295. cmSourceFile const& source)
  296. {
  297. // Identify the language of the source file.
  298. const std::string& lang =
  299. this->LocalGenerator->GetSourceFileLanguage(source);
  300. if (lang.empty()) {
  301. // don't know anything about this file so skip it
  302. return;
  303. }
  304. // Get the full path name of the object file.
  305. std::string const& objectName =
  306. this->GeneratorTarget->GetObjectName(&source);
  307. std::string obj =
  308. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  309. obj += "/";
  310. obj += objectName;
  311. // Avoid generating duplicate rules.
  312. if (this->ObjectFiles.find(obj) == this->ObjectFiles.end()) {
  313. this->ObjectFiles.insert(obj);
  314. } else {
  315. std::ostringstream err;
  316. err << "Warning: Source file \"" << source.GetFullPath()
  317. << "\" is listed multiple times for target \""
  318. << this->GeneratorTarget->GetName() << "\".";
  319. cmSystemTools::Message(err.str().c_str(), "Warning");
  320. return;
  321. }
  322. // Create the directory containing the object file. This may be a
  323. // subdirectory under the target's directory.
  324. std::string dir = cmSystemTools::GetFilenamePath(obj);
  325. cmSystemTools::MakeDirectory(
  326. this->LocalGenerator->ConvertToFullPath(dir).c_str());
  327. // Save this in the target's list of object files.
  328. this->Objects.push_back(obj);
  329. this->CleanFiles.push_back(obj);
  330. // TODO: Remove
  331. // std::string relativeObj
  332. //= this->LocalGenerator->GetHomeRelativeOutputPath();
  333. // relativeObj += obj;
  334. // we compute some depends when writing the depend.make that we will also
  335. // use in the build.make, same with depMakeFile
  336. std::vector<std::string> depends;
  337. // generate the build rule file
  338. this->WriteObjectBuildFile(obj, lang, source, depends);
  339. // The object file should be checked for dependency integrity.
  340. std::string objFullPath = this->LocalGenerator->GetCurrentBinaryDirectory();
  341. objFullPath += "/";
  342. objFullPath += obj;
  343. objFullPath = this->Convert(objFullPath, cmLocalGenerator::FULL);
  344. std::string srcFullPath =
  345. this->Convert(source.GetFullPath(), cmLocalGenerator::FULL);
  346. this->LocalGenerator->AddImplicitDepends(
  347. this->GeneratorTarget, lang, objFullPath.c_str(), srcFullPath.c_str());
  348. }
  349. void cmMakefileTargetGenerator::WriteObjectBuildFile(
  350. std::string& obj, const std::string& lang, cmSourceFile const& source,
  351. std::vector<std::string>& depends)
  352. {
  353. this->LocalGenerator->AppendRuleDepend(depends,
  354. this->FlagFileNameFull.c_str());
  355. this->LocalGenerator->AppendRuleDepends(depends,
  356. this->FlagFileDepends[lang]);
  357. // generate the depend scanning rule
  358. this->WriteObjectDependRules(source, depends);
  359. std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
  360. relativeObj += obj;
  361. // Write the build rule.
  362. // Build the set of compiler flags.
  363. std::string flags;
  364. // Add language-specific flags.
  365. std::string langFlags = "$(";
  366. langFlags += lang;
  367. langFlags += "_FLAGS)";
  368. this->LocalGenerator->AppendFlags(flags, langFlags);
  369. std::string configUpper =
  370. cmSystemTools::UpperCase(this->LocalGenerator->GetConfigName());
  371. // Add Fortran format flags.
  372. if (lang == "Fortran") {
  373. this->AppendFortranFormatFlags(flags, source);
  374. }
  375. // Add flags from source file properties.
  376. if (source.GetProperty("COMPILE_FLAGS")) {
  377. this->LocalGenerator->AppendFlags(flags,
  378. source.GetProperty("COMPILE_FLAGS"));
  379. *this->FlagFileStream << "# Custom flags: " << relativeObj
  380. << "_FLAGS = " << source.GetProperty("COMPILE_FLAGS")
  381. << "\n"
  382. << "\n";
  383. }
  384. // Add language-specific defines.
  385. std::set<std::string> defines;
  386. // Add source-sepcific preprocessor definitions.
  387. if (const char* compile_defs = source.GetProperty("COMPILE_DEFINITIONS")) {
  388. this->LocalGenerator->AppendDefines(defines, compile_defs);
  389. *this->FlagFileStream << "# Custom defines: " << relativeObj
  390. << "_DEFINES = " << compile_defs << "\n"
  391. << "\n";
  392. }
  393. std::string defPropName = "COMPILE_DEFINITIONS_";
  394. defPropName += configUpper;
  395. if (const char* config_compile_defs = source.GetProperty(defPropName)) {
  396. this->LocalGenerator->AppendDefines(defines, config_compile_defs);
  397. *this->FlagFileStream << "# Custom defines: " << relativeObj << "_DEFINES_"
  398. << configUpper << " = " << config_compile_defs
  399. << "\n"
  400. << "\n";
  401. }
  402. // Get the output paths for source and object files.
  403. std::string sourceFile = this->Convert(
  404. source.GetFullPath(), cmLocalGenerator::NONE, cmLocalGenerator::SHELL);
  405. // Construct the build message.
  406. std::vector<std::string> no_commands;
  407. std::vector<std::string> commands;
  408. // add in a progress call if needed
  409. this->NumberOfProgressActions++;
  410. if (!this->NoRuleMessages) {
  411. cmLocalUnixMakefileGenerator3::EchoProgress progress;
  412. this->MakeEchoProgress(progress);
  413. std::string buildEcho = "Building ";
  414. buildEcho += lang;
  415. buildEcho += " object ";
  416. buildEcho += relativeObj;
  417. this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
  418. cmLocalUnixMakefileGenerator3::EchoBuild,
  419. &progress);
  420. }
  421. std::string targetOutPathReal;
  422. std::string targetOutPathPDB;
  423. std::string targetOutPathCompilePDB;
  424. {
  425. std::string targetFullPathReal;
  426. std::string targetFullPathPDB;
  427. std::string targetFullPathCompilePDB;
  428. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
  429. this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
  430. this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  431. this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
  432. targetFullPathReal =
  433. this->GeneratorTarget->GetFullPath(this->ConfigName, false, true);
  434. targetFullPathPDB =
  435. this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
  436. targetFullPathPDB += "/";
  437. targetFullPathPDB += this->GeneratorTarget->GetPDBName(this->ConfigName);
  438. }
  439. if (this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY) {
  440. targetFullPathCompilePDB =
  441. this->GeneratorTarget->GetCompilePDBPath(this->ConfigName);
  442. if (targetFullPathCompilePDB.empty()) {
  443. targetFullPathCompilePDB =
  444. this->GeneratorTarget->GetSupportDirectory() + "/";
  445. }
  446. }
  447. targetOutPathReal =
  448. this->Convert(targetFullPathReal, cmLocalGenerator::START_OUTPUT,
  449. cmLocalGenerator::SHELL);
  450. targetOutPathPDB = this->Convert(targetFullPathPDB, cmLocalGenerator::NONE,
  451. cmLocalGenerator::SHELL);
  452. targetOutPathCompilePDB =
  453. this->Convert(targetFullPathCompilePDB, cmLocalGenerator::START_OUTPUT,
  454. cmLocalGenerator::SHELL);
  455. if (this->LocalGenerator->IsMinGWMake() &&
  456. cmHasLiteralSuffix(targetOutPathCompilePDB, "\\")) {
  457. // mingw32-make incorrectly interprets 'a\ b c' as 'a b' and 'c'
  458. // (but 'a\ b "c"' as 'a\', 'b', and 'c'!). Workaround this by
  459. // avoiding a trailing backslash in the argument.
  460. targetOutPathCompilePDB[targetOutPathCompilePDB.size() - 1] = '/';
  461. }
  462. }
  463. cmLocalGenerator::RuleVariables vars;
  464. vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
  465. vars.CMTarget = this->GeneratorTarget;
  466. vars.Language = lang.c_str();
  467. vars.Target = targetOutPathReal.c_str();
  468. vars.TargetPDB = targetOutPathPDB.c_str();
  469. vars.TargetCompilePDB = targetOutPathCompilePDB.c_str();
  470. vars.Source = sourceFile.c_str();
  471. std::string shellObj =
  472. this->Convert(obj, cmLocalGenerator::NONE, cmLocalGenerator::SHELL);
  473. vars.Object = shellObj.c_str();
  474. std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
  475. objectDir = this->Convert(objectDir, cmLocalGenerator::START_OUTPUT,
  476. cmLocalGenerator::SHELL);
  477. vars.ObjectDir = objectDir.c_str();
  478. std::string objectFileDir = cmSystemTools::GetFilenamePath(obj);
  479. objectFileDir = this->Convert(objectFileDir, cmLocalGenerator::START_OUTPUT,
  480. cmLocalGenerator::SHELL);
  481. vars.ObjectFileDir = objectFileDir.c_str();
  482. vars.Flags = flags.c_str();
  483. std::string definesString = "$(";
  484. definesString += lang;
  485. definesString += "_DEFINES)";
  486. this->LocalGenerator->JoinDefines(defines, definesString, lang);
  487. vars.Defines = definesString.c_str();
  488. std::string const includesString = "$(" + lang + "_INCLUDES)";
  489. vars.Includes = includesString.c_str();
  490. // At the moment, it is assumed that C, C++, and Fortran have both
  491. // assembly and preprocessor capabilities. The same is true for the
  492. // ability to export compile commands
  493. bool lang_has_preprocessor =
  494. ((lang == "C") || (lang == "CXX") || (lang == "Fortran"));
  495. bool const lang_has_assembly = lang_has_preprocessor;
  496. bool const lang_can_export_cmds = lang_has_preprocessor;
  497. // Construct the compile rules.
  498. {
  499. std::string compileRuleVar = "CMAKE_";
  500. compileRuleVar += lang;
  501. compileRuleVar += "_COMPILE_OBJECT";
  502. std::string compileRule =
  503. this->Makefile->GetRequiredDefinition(compileRuleVar);
  504. std::vector<std::string> compileCommands;
  505. cmSystemTools::ExpandListArgument(compileRule, compileCommands);
  506. if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") &&
  507. lang_can_export_cmds && compileCommands.size() == 1) {
  508. std::string compileCommand = compileCommands[0];
  509. this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
  510. std::string workingDirectory = this->LocalGenerator->Convert(
  511. this->LocalGenerator->GetCurrentBinaryDirectory(),
  512. cmLocalGenerator::FULL);
  513. compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
  514. this->GetFlags(lang));
  515. std::string langDefines = std::string("$(") + lang + "_DEFINES)";
  516. compileCommand.replace(compileCommand.find(langDefines),
  517. langDefines.size(), this->GetDefines(lang));
  518. std::string langIncludes = std::string("$(") + lang + "_INCLUDES)";
  519. compileCommand.replace(compileCommand.find(langIncludes),
  520. langIncludes.size(), this->GetIncludes(lang));
  521. this->GlobalGenerator->AddCXXCompileCommand(
  522. source.GetFullPath(), workingDirectory, compileCommand);
  523. }
  524. // Maybe insert an include-what-you-use runner.
  525. if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) {
  526. std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
  527. const char* iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
  528. std::string const tidy_prop = lang + "_CLANG_TIDY";
  529. const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
  530. if ((iwyu && *iwyu) || (tidy && *tidy)) {
  531. std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu";
  532. if (iwyu && *iwyu) {
  533. run_iwyu += " --iwyu=";
  534. run_iwyu += this->LocalGenerator->EscapeForShell(iwyu);
  535. }
  536. if (tidy && *tidy) {
  537. run_iwyu += " --tidy=";
  538. run_iwyu += this->LocalGenerator->EscapeForShell(tidy);
  539. run_iwyu += " --source=";
  540. run_iwyu += sourceFile;
  541. }
  542. run_iwyu += " -- ";
  543. compileCommands.front().insert(0, run_iwyu);
  544. }
  545. }
  546. // Maybe insert a compiler launcher like ccache or distcc
  547. if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) {
  548. std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
  549. const char* clauncher =
  550. this->GeneratorTarget->GetProperty(clauncher_prop);
  551. if (clauncher && *clauncher) {
  552. std::vector<std::string> launcher_cmd;
  553. cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
  554. for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
  555. e = launcher_cmd.end();
  556. i != e; ++i) {
  557. *i = this->LocalGenerator->EscapeForShell(*i);
  558. }
  559. std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
  560. compileCommands.front().insert(0, run_launcher);
  561. }
  562. }
  563. // Expand placeholders in the commands.
  564. for (std::vector<std::string>::iterator i = compileCommands.begin();
  565. i != compileCommands.end(); ++i) {
  566. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  567. }
  568. // Change the command working directory to the local build tree.
  569. this->LocalGenerator->CreateCDCommand(
  570. compileCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
  571. cmLocalGenerator::HOME_OUTPUT);
  572. commands.insert(commands.end(), compileCommands.begin(),
  573. compileCommands.end());
  574. }
  575. // Check for extra outputs created by the compilation.
  576. std::vector<std::string> outputs(1, relativeObj);
  577. if (const char* extra_outputs_str = source.GetProperty("OBJECT_OUTPUTS")) {
  578. // Register these as extra files to clean.
  579. cmSystemTools::ExpandListArgument(extra_outputs_str, outputs);
  580. this->CleanFiles.insert(this->CleanFiles.end(), outputs.begin() + 1,
  581. outputs.end());
  582. }
  583. // Write the rule.
  584. this->WriteMakeRule(*this->BuildFileStream, 0, outputs, depends, commands);
  585. bool do_preprocess_rules = lang_has_preprocessor &&
  586. this->LocalGenerator->GetCreatePreprocessedSourceRules();
  587. bool do_assembly_rules =
  588. lang_has_assembly && this->LocalGenerator->GetCreateAssemblySourceRules();
  589. if (do_preprocess_rules || do_assembly_rules) {
  590. std::vector<std::string> force_depends;
  591. force_depends.push_back("cmake_force");
  592. std::string::size_type dot_pos = relativeObj.rfind('.');
  593. std::string relativeObjBase = relativeObj.substr(0, dot_pos);
  594. dot_pos = obj.rfind('.');
  595. std::string objBase = obj.substr(0, dot_pos);
  596. if (do_preprocess_rules) {
  597. commands.clear();
  598. std::string relativeObjI = relativeObjBase + ".i";
  599. std::string objI = objBase + ".i";
  600. std::string preprocessEcho = "Preprocessing ";
  601. preprocessEcho += lang;
  602. preprocessEcho += " source to ";
  603. preprocessEcho += objI;
  604. this->LocalGenerator->AppendEcho(
  605. commands, preprocessEcho.c_str(),
  606. cmLocalUnixMakefileGenerator3::EchoBuild);
  607. std::string preprocessRuleVar = "CMAKE_";
  608. preprocessRuleVar += lang;
  609. preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
  610. if (const char* preprocessRule =
  611. this->Makefile->GetDefinition(preprocessRuleVar)) {
  612. std::vector<std::string> preprocessCommands;
  613. cmSystemTools::ExpandListArgument(preprocessRule, preprocessCommands);
  614. std::string shellObjI =
  615. this->Convert(objI, cmLocalGenerator::NONE, cmLocalGenerator::SHELL);
  616. vars.PreprocessedSource = shellObjI.c_str();
  617. // Expand placeholders in the commands.
  618. for (std::vector<std::string>::iterator i = preprocessCommands.begin();
  619. i != preprocessCommands.end(); ++i) {
  620. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  621. }
  622. this->LocalGenerator->CreateCDCommand(
  623. preprocessCommands,
  624. this->LocalGenerator->GetCurrentBinaryDirectory(),
  625. cmLocalGenerator::HOME_OUTPUT);
  626. commands.insert(commands.end(), preprocessCommands.begin(),
  627. preprocessCommands.end());
  628. } else {
  629. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  630. cmd += preprocessRuleVar;
  631. commands.push_back(cmd);
  632. }
  633. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  634. relativeObjI, force_depends,
  635. commands, false);
  636. }
  637. if (do_assembly_rules) {
  638. commands.clear();
  639. std::string relativeObjS = relativeObjBase + ".s";
  640. std::string objS = objBase + ".s";
  641. std::string assemblyEcho = "Compiling ";
  642. assemblyEcho += lang;
  643. assemblyEcho += " source to assembly ";
  644. assemblyEcho += objS;
  645. this->LocalGenerator->AppendEcho(
  646. commands, assemblyEcho.c_str(),
  647. cmLocalUnixMakefileGenerator3::EchoBuild);
  648. std::string assemblyRuleVar = "CMAKE_";
  649. assemblyRuleVar += lang;
  650. assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
  651. if (const char* assemblyRule =
  652. this->Makefile->GetDefinition(assemblyRuleVar)) {
  653. std::vector<std::string> assemblyCommands;
  654. cmSystemTools::ExpandListArgument(assemblyRule, assemblyCommands);
  655. std::string shellObjS =
  656. this->Convert(objS, cmLocalGenerator::NONE, cmLocalGenerator::SHELL);
  657. vars.AssemblySource = shellObjS.c_str();
  658. // Expand placeholders in the commands.
  659. for (std::vector<std::string>::iterator i = assemblyCommands.begin();
  660. i != assemblyCommands.end(); ++i) {
  661. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  662. }
  663. this->LocalGenerator->CreateCDCommand(
  664. assemblyCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
  665. cmLocalGenerator::HOME_OUTPUT);
  666. commands.insert(commands.end(), assemblyCommands.begin(),
  667. assemblyCommands.end());
  668. } else {
  669. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  670. cmd += assemblyRuleVar;
  671. commands.push_back(cmd);
  672. }
  673. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  674. relativeObjS, force_depends,
  675. commands, false);
  676. }
  677. }
  678. // If the language needs provides-requires mode, create the
  679. // corresponding targets.
  680. std::string objectRequires = relativeObj;
  681. objectRequires += ".requires";
  682. std::vector<std::string> p_depends;
  683. // always provide an empty requires target
  684. this->LocalGenerator->WriteMakeRule(
  685. *this->BuildFileStream, 0, objectRequires, p_depends, no_commands, true);
  686. // write a build rule to recursively build what this obj provides
  687. std::string objectProvides = relativeObj;
  688. objectProvides += ".provides";
  689. std::string temp = relativeObj;
  690. temp += ".provides.build";
  691. std::vector<std::string> r_commands;
  692. std::string tgtMakefileName =
  693. this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
  694. tgtMakefileName += "/build.make";
  695. r_commands.push_back(
  696. this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(), temp));
  697. p_depends.clear();
  698. p_depends.push_back(objectRequires);
  699. this->LocalGenerator->WriteMakeRule(
  700. *this->BuildFileStream, 0, objectProvides, p_depends, r_commands, true);
  701. // write the provides.build rule dependency on the obj file
  702. p_depends.clear();
  703. p_depends.push_back(relativeObj);
  704. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, temp,
  705. p_depends, no_commands, false);
  706. }
  707. void cmMakefileTargetGenerator::WriteTargetRequiresRules()
  708. {
  709. std::vector<std::string> depends;
  710. std::vector<std::string> no_commands;
  711. // Construct the name of the dependency generation target.
  712. std::string depTarget =
  713. this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
  714. depTarget += "/requires";
  715. // This target drives dependency generation for all object files.
  716. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  717. std::string objTarget;
  718. for (std::vector<std::string>::const_iterator obj = this->Objects.begin();
  719. obj != this->Objects.end(); ++obj) {
  720. objTarget = relPath;
  721. objTarget += *obj;
  722. objTarget += ".requires";
  723. depends.push_back(objTarget);
  724. }
  725. // Write the rule.
  726. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, depTarget,
  727. depends, no_commands, true);
  728. }
  729. void cmMakefileTargetGenerator::WriteTargetCleanRules()
  730. {
  731. std::vector<std::string> depends;
  732. std::vector<std::string> commands;
  733. // Construct the clean target name.
  734. std::string cleanTarget =
  735. this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
  736. cleanTarget += "/clean";
  737. // Construct the clean command.
  738. this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
  739. this->GeneratorTarget);
  740. this->LocalGenerator->CreateCDCommand(
  741. commands, this->LocalGenerator->GetCurrentBinaryDirectory(),
  742. cmLocalGenerator::HOME_OUTPUT);
  743. // Write the rule.
  744. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, cleanTarget,
  745. depends, commands, true);
  746. }
  747. bool cmMakefileTargetGenerator::WriteMakeRule(
  748. std::ostream& os, const char* comment,
  749. const std::vector<std::string>& outputs,
  750. const std::vector<std::string>& depends,
  751. const std::vector<std::string>& commands, bool in_help)
  752. {
  753. bool symbolic = false;
  754. if (outputs.size() == 0) {
  755. return symbolic;
  756. }
  757. // Check whether we need to bother checking for a symbolic output.
  758. bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
  759. // Check whether the first output is marked as symbolic.
  760. if (need_symbolic) {
  761. if (cmSourceFile* sf = this->Makefile->GetSource(outputs[0])) {
  762. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  763. }
  764. }
  765. // We always attach the actual commands to the first output.
  766. this->LocalGenerator->WriteMakeRule(os, comment, outputs[0], depends,
  767. commands, symbolic, in_help);
  768. // For single outputs, we are done.
  769. if (outputs.size() == 1) {
  770. return symbolic;
  771. }
  772. // For multiple outputs, make the extra ones depend on the first one.
  773. std::vector<std::string> const output_depends(1, outputs[0]);
  774. for (std::vector<std::string>::const_iterator o = outputs.begin() + 1;
  775. o != outputs.end(); ++o) {
  776. // Touch the extra output so "make" knows that it was updated,
  777. // but only if the output was acually created.
  778. std::string const out = this->Convert(*o, cmLocalGenerator::HOME_OUTPUT,
  779. cmLocalGenerator::SHELL);
  780. std::vector<std::string> output_commands;
  781. bool o_symbolic = false;
  782. if (need_symbolic) {
  783. if (cmSourceFile* sf = this->Makefile->GetSource(*o)) {
  784. o_symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  785. }
  786. }
  787. symbolic = symbolic && o_symbolic;
  788. if (!o_symbolic) {
  789. output_commands.push_back("@$(CMAKE_COMMAND) -E touch_nocreate " + out);
  790. }
  791. this->LocalGenerator->WriteMakeRule(os, 0, *o, output_depends,
  792. output_commands, o_symbolic, in_help);
  793. if (!o_symbolic) {
  794. // At build time, remove the first output if this one does not exist
  795. // so that "make" will rerun the real commands that create this one.
  796. MultipleOutputPairsType::value_type p(*o, outputs[0]);
  797. this->MultipleOutputPairs.insert(p);
  798. }
  799. }
  800. return symbolic;
  801. }
  802. void cmMakefileTargetGenerator::WriteTargetDependRules()
  803. {
  804. // must write the targets depend info file
  805. std::string dir =
  806. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  807. this->InfoFileNameFull = dir;
  808. this->InfoFileNameFull += "/DependInfo.cmake";
  809. this->InfoFileNameFull =
  810. this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
  811. this->InfoFileStream =
  812. new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
  813. this->InfoFileStream->SetCopyIfDifferent(true);
  814. if (!*this->InfoFileStream) {
  815. return;
  816. }
  817. this->LocalGenerator->WriteDependLanguageInfo(*this->InfoFileStream,
  818. this->GeneratorTarget);
  819. // Store multiple output pairs in the depend info file.
  820. if (!this->MultipleOutputPairs.empty()) {
  821. /* clang-format off */
  822. *this->InfoFileStream
  823. << "\n"
  824. << "# Pairs of files generated by the same build rule.\n"
  825. << "set(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
  826. /* clang-format on */
  827. for (MultipleOutputPairsType::const_iterator pi =
  828. this->MultipleOutputPairs.begin();
  829. pi != this->MultipleOutputPairs.end(); ++pi) {
  830. *this->InfoFileStream
  831. << " " << cmOutputConverter::EscapeForCMake(pi->first) << " "
  832. << cmOutputConverter::EscapeForCMake(pi->second) << "\n";
  833. }
  834. *this->InfoFileStream << " )\n\n";
  835. }
  836. // Store list of targets linked directly or transitively.
  837. {
  838. /* clang-format off */
  839. *this->InfoFileStream
  840. << "\n"
  841. << "# Targets to which this target links.\n"
  842. << "set(CMAKE_TARGET_LINKED_INFO_FILES\n";
  843. /* clang-format on */
  844. std::vector<std::string> dirs = this->GetLinkedTargetDirectories();
  845. for (std::vector<std::string>::iterator i = dirs.begin(); i != dirs.end();
  846. ++i) {
  847. *this->InfoFileStream << " \"" << *i << "/DependInfo.cmake\"\n";
  848. }
  849. *this->InfoFileStream << " )\n";
  850. }
  851. /* clang-format off */
  852. *this->InfoFileStream
  853. << "\n"
  854. << "# Fortran module output directory.\n"
  855. << "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
  856. << this->GetFortranModuleDirectory() << "\")\n";
  857. /* clang-format on */
  858. // and now write the rule to use it
  859. std::vector<std::string> depends;
  860. std::vector<std::string> commands;
  861. // Construct the name of the dependency generation target.
  862. std::string depTarget =
  863. this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
  864. depTarget += "/depend";
  865. // Add a command to call CMake to scan dependencies. CMake will
  866. // touch the corresponding depends file after scanning dependencies.
  867. std::ostringstream depCmd;
  868. // TODO: Account for source file properties and directory-level
  869. // definitions when scanning for dependencies.
  870. #if !defined(_WIN32) || defined(__CYGWIN__)
  871. // This platform supports symlinks, so cmSystemTools will translate
  872. // paths. Make sure PWD is set to the original name of the home
  873. // output directory to help cmSystemTools to create the same
  874. // translation table for the dependency scanning process.
  875. depCmd << "cd " << (this->LocalGenerator->Convert(
  876. this->LocalGenerator->GetBinaryDirectory(),
  877. cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
  878. << " && ";
  879. #endif
  880. // Generate a call this signature:
  881. //
  882. // cmake -E cmake_depends <generator>
  883. // <home-src-dir> <start-src-dir>
  884. // <home-out-dir> <start-out-dir>
  885. // <dep-info> --color=$(COLOR)
  886. //
  887. // This gives the dependency scanner enough information to recreate
  888. // the state of our local generator sufficiently for its needs.
  889. depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
  890. << this->GlobalGenerator->GetName() << "\" "
  891. << this->Convert(this->LocalGenerator->GetSourceDirectory(),
  892. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  893. << " "
  894. << this->Convert(this->LocalGenerator->GetCurrentSourceDirectory(),
  895. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  896. << " "
  897. << this->Convert(this->LocalGenerator->GetBinaryDirectory(),
  898. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  899. << " "
  900. << this->Convert(this->LocalGenerator->GetCurrentBinaryDirectory(),
  901. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  902. << " "
  903. << this->Convert(this->InfoFileNameFull, cmLocalGenerator::FULL,
  904. cmLocalGenerator::SHELL);
  905. if (this->LocalGenerator->GetColorMakefile()) {
  906. depCmd << " --color=$(COLOR)";
  907. }
  908. commands.push_back(depCmd.str());
  909. // Make sure all custom command outputs in this target are built.
  910. if (this->CustomCommandDriver == OnDepends) {
  911. this->DriveCustomCommands(depends);
  912. }
  913. // Write the rule.
  914. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, depTarget,
  915. depends, commands, true);
  916. }
  917. void cmMakefileTargetGenerator::DriveCustomCommands(
  918. std::vector<std::string>& depends)
  919. {
  920. // Depend on all custom command outputs.
  921. std::vector<cmSourceFile*> sources;
  922. this->GeneratorTarget->GetSourceFiles(
  923. sources, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  924. for (std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  925. source != sources.end(); ++source) {
  926. if (cmCustomCommand* cc = (*source)->GetCustomCommand()) {
  927. cmCustomCommandGenerator ccg(*cc, this->ConfigName,
  928. this->LocalGenerator);
  929. const std::vector<std::string>& outputs = ccg.GetOutputs();
  930. depends.insert(depends.end(), outputs.begin(), outputs.end());
  931. }
  932. }
  933. }
  934. void cmMakefileTargetGenerator::WriteObjectDependRules(
  935. cmSourceFile const& source, std::vector<std::string>& depends)
  936. {
  937. // Create the list of dependencies known at cmake time. These are
  938. // shared between the object file and dependency scanning rule.
  939. depends.push_back(source.GetFullPath());
  940. if (const char* objectDeps = source.GetProperty("OBJECT_DEPENDS")) {
  941. cmSystemTools::ExpandListArgument(objectDeps, depends);
  942. }
  943. }
  944. void cmMakefileTargetGenerator::GenerateCustomRuleFile(
  945. cmCustomCommandGenerator const& ccg)
  946. {
  947. // Collect the commands.
  948. std::vector<std::string> commands;
  949. std::string comment = this->LocalGenerator->ConstructComment(ccg);
  950. if (!comment.empty()) {
  951. // add in a progress call if needed
  952. this->NumberOfProgressActions++;
  953. if (!this->NoRuleMessages) {
  954. cmLocalUnixMakefileGenerator3::EchoProgress progress;
  955. this->MakeEchoProgress(progress);
  956. this->LocalGenerator->AppendEcho(
  957. commands, comment.c_str(), cmLocalUnixMakefileGenerator3::EchoGenerate,
  958. &progress);
  959. }
  960. }
  961. // Now append the actual user-specified commands.
  962. std::ostringstream content;
  963. this->LocalGenerator->AppendCustomCommand(
  964. commands, ccg, this->GeneratorTarget, false, cmLocalGenerator::HOME_OUTPUT,
  965. &content);
  966. // Collect the dependencies.
  967. std::vector<std::string> depends;
  968. this->LocalGenerator->AppendCustomDepend(depends, ccg);
  969. // Write the rule.
  970. const std::vector<std::string>& outputs = ccg.GetOutputs();
  971. bool symbolic =
  972. this->WriteMakeRule(*this->BuildFileStream, 0, outputs, depends, commands);
  973. // If the rule has changed make sure the output is rebuilt.
  974. if (!symbolic) {
  975. this->GlobalGenerator->AddRuleHash(ccg.GetOutputs(), content.str());
  976. }
  977. // Setup implicit dependency scanning.
  978. for (cmCustomCommand::ImplicitDependsList::const_iterator idi =
  979. ccg.GetCC().GetImplicitDepends().begin();
  980. idi != ccg.GetCC().GetImplicitDepends().end(); ++idi) {
  981. std::string objFullPath =
  982. this->Convert(outputs[0], cmLocalGenerator::FULL);
  983. std::string srcFullPath =
  984. this->Convert(idi->second, cmLocalGenerator::FULL);
  985. this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, idi->first,
  986. objFullPath.c_str(),
  987. srcFullPath.c_str());
  988. }
  989. }
  990. void cmMakefileTargetGenerator::MakeEchoProgress(
  991. cmLocalUnixMakefileGenerator3::EchoProgress& progress) const
  992. {
  993. progress.Dir = this->LocalGenerator->GetBinaryDirectory();
  994. progress.Dir += cmake::GetCMakeFilesDirectory();
  995. std::ostringstream progressArg;
  996. progressArg << "$(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
  997. progress.Arg = progressArg.str();
  998. }
  999. void cmMakefileTargetGenerator::WriteObjectsVariable(
  1000. std::string& variableName, std::string& variableNameExternal,
  1001. bool useWatcomQuote)
  1002. {
  1003. // Write a make variable assignment that lists all objects for the
  1004. // target.
  1005. variableName = this->LocalGenerator->CreateMakeVariable(
  1006. this->GeneratorTarget->GetName(), "_OBJECTS");
  1007. *this->BuildFileStream << "# Object files for target "
  1008. << this->GeneratorTarget->GetName() << "\n"
  1009. << variableName << " =";
  1010. std::string object;
  1011. const char* lineContinue =
  1012. this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
  1013. if (!lineContinue) {
  1014. lineContinue = "\\";
  1015. }
  1016. for (std::vector<std::string>::const_iterator i = this->Objects.begin();
  1017. i != this->Objects.end(); ++i) {
  1018. *this->BuildFileStream << " " << lineContinue << "\n";
  1019. *this->BuildFileStream << this->LocalGenerator->ConvertToQuotedOutputPath(
  1020. i->c_str(), useWatcomQuote);
  1021. }
  1022. *this->BuildFileStream << "\n";
  1023. // Write a make variable assignment that lists all external objects
  1024. // for the target.
  1025. variableNameExternal = this->LocalGenerator->CreateMakeVariable(
  1026. this->GeneratorTarget->GetName(), "_EXTERNAL_OBJECTS");
  1027. /* clang-format off */
  1028. *this->BuildFileStream
  1029. << "\n"
  1030. << "# External object files for target "
  1031. << this->GeneratorTarget->GetName() << "\n"
  1032. << variableNameExternal << " =";
  1033. /* clang-format on */
  1034. for (std::vector<std::string>::const_iterator i =
  1035. this->ExternalObjects.begin();
  1036. i != this->ExternalObjects.end(); ++i) {
  1037. object = this->Convert(*i, cmLocalGenerator::START_OUTPUT);
  1038. *this->BuildFileStream << " " << lineContinue << "\n"
  1039. << this->Makefile->GetSafeDefinition(
  1040. "CMAKE_OBJECT_NAME");
  1041. *this->BuildFileStream << this->LocalGenerator->ConvertToQuotedOutputPath(
  1042. i->c_str(), useWatcomQuote);
  1043. }
  1044. *this->BuildFileStream << "\n"
  1045. << "\n";
  1046. }
  1047. void cmMakefileTargetGenerator::WriteObjectsString(std::string& buildObjs)
  1048. {
  1049. std::vector<std::string> objStrings;
  1050. this->WriteObjectsStrings(objStrings);
  1051. buildObjs = objStrings[0];
  1052. }
  1053. class cmMakefileTargetGeneratorObjectStrings
  1054. {
  1055. public:
  1056. cmMakefileTargetGeneratorObjectStrings(std::vector<std::string>& strings,
  1057. cmLocalUnixMakefileGenerator3* lg,
  1058. std::string::size_type limit)
  1059. : Strings(strings)
  1060. , LocalGenerator(lg)
  1061. , LengthLimit(limit)
  1062. {
  1063. this->Space = "";
  1064. }
  1065. void Feed(std::string const& obj)
  1066. {
  1067. // Construct the name of the next object.
  1068. this->NextObject = this->LocalGenerator->Convert(
  1069. obj, cmLocalGenerator::START_OUTPUT, cmLocalGenerator::RESPONSE);
  1070. // Roll over to next string if the limit will be exceeded.
  1071. if (this->LengthLimit != std::string::npos &&
  1072. (this->CurrentString.length() + 1 + this->NextObject.length() >
  1073. this->LengthLimit)) {
  1074. this->Strings.push_back(this->CurrentString);
  1075. this->CurrentString = "";
  1076. this->Space = "";
  1077. }
  1078. // Separate from previous object.
  1079. this->CurrentString += this->Space;
  1080. this->Space = " ";
  1081. // Append this object.
  1082. this->CurrentString += this->NextObject;
  1083. }
  1084. void Done() { this->Strings.push_back(this->CurrentString); }
  1085. private:
  1086. std::vector<std::string>& Strings;
  1087. cmLocalUnixMakefileGenerator3* LocalGenerator;
  1088. std::string::size_type LengthLimit;
  1089. std::string CurrentString;
  1090. std::string NextObject;
  1091. const char* Space;
  1092. };
  1093. void cmMakefileTargetGenerator::WriteObjectsStrings(
  1094. std::vector<std::string>& objStrings, std::string::size_type limit)
  1095. {
  1096. cmMakefileTargetGeneratorObjectStrings helper(objStrings,
  1097. this->LocalGenerator, limit);
  1098. for (std::vector<std::string>::const_iterator i = this->Objects.begin();
  1099. i != this->Objects.end(); ++i) {
  1100. helper.Feed(*i);
  1101. }
  1102. for (std::vector<std::string>::const_iterator i =
  1103. this->ExternalObjects.begin();
  1104. i != this->ExternalObjects.end(); ++i) {
  1105. helper.Feed(*i);
  1106. }
  1107. helper.Done();
  1108. }
  1109. void cmMakefileTargetGenerator::WriteTargetDriverRule(
  1110. const std::string& main_output, bool relink)
  1111. {
  1112. // Compute the name of the driver target.
  1113. std::string dir =
  1114. this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
  1115. std::string buildTargetRuleName = dir;
  1116. buildTargetRuleName += relink ? "/preinstall" : "/build";
  1117. buildTargetRuleName =
  1118. this->Convert(buildTargetRuleName, cmLocalGenerator::HOME_OUTPUT,
  1119. cmLocalGenerator::UNCHANGED);
  1120. // Build the list of target outputs to drive.
  1121. std::vector<std::string> depends;
  1122. depends.push_back(main_output);
  1123. const char* comment = 0;
  1124. if (relink) {
  1125. // Setup the comment for the preinstall driver.
  1126. comment = "Rule to relink during preinstall.";
  1127. } else {
  1128. // Setup the comment for the main build driver.
  1129. comment = "Rule to build all files generated by this target.";
  1130. // Make sure all custom command outputs in this target are built.
  1131. if (this->CustomCommandDriver == OnBuild) {
  1132. this->DriveCustomCommands(depends);
  1133. }
  1134. // Make sure the extra files are built.
  1135. depends.insert(depends.end(), this->ExtraFiles.begin(),
  1136. this->ExtraFiles.end());
  1137. }
  1138. // Write the driver rule.
  1139. std::vector<std::string> no_commands;
  1140. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
  1141. buildTargetRuleName, depends,
  1142. no_commands, true);
  1143. }
  1144. void cmMakefileTargetGenerator::AppendTargetDepends(
  1145. std::vector<std::string>& depends)
  1146. {
  1147. // Static libraries never depend on anything for linking.
  1148. if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY) {
  1149. return;
  1150. }
  1151. // Loop over all library dependencies.
  1152. const char* cfg = this->LocalGenerator->GetConfigName().c_str();
  1153. if (cmComputeLinkInformation* cli =
  1154. this->GeneratorTarget->GetLinkInformation(cfg)) {
  1155. std::vector<std::string> const& libDeps = cli->GetDepends();
  1156. depends.insert(depends.end(), libDeps.begin(), libDeps.end());
  1157. }
  1158. }
  1159. void cmMakefileTargetGenerator::AppendObjectDepends(
  1160. std::vector<std::string>& depends)
  1161. {
  1162. // Add dependencies on the compiled object files.
  1163. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  1164. std::string objTarget;
  1165. for (std::vector<std::string>::const_iterator obj = this->Objects.begin();
  1166. obj != this->Objects.end(); ++obj) {
  1167. objTarget = relPath;
  1168. objTarget += *obj;
  1169. depends.push_back(objTarget);
  1170. }
  1171. // Add dependencies on the external object files.
  1172. depends.insert(depends.end(), this->ExternalObjects.begin(),
  1173. this->ExternalObjects.end());
  1174. // Add a dependency on the rule file itself.
  1175. this->LocalGenerator->AppendRuleDepend(depends,
  1176. this->BuildFileNameFull.c_str());
  1177. }
  1178. void cmMakefileTargetGenerator::AppendLinkDepends(
  1179. std::vector<std::string>& depends)
  1180. {
  1181. this->AppendObjectDepends(depends);
  1182. // Add dependencies on targets that must be built first.
  1183. this->AppendTargetDepends(depends);
  1184. // Add a dependency on the link definitions file, if any.
  1185. if (this->ModuleDefinitionFile) {
  1186. depends.push_back(this->ModuleDefinitionFile->GetFullPath());
  1187. }
  1188. // Add a dependency on user-specified manifest files, if any.
  1189. std::vector<cmSourceFile const*> manifest_srcs;
  1190. this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
  1191. for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
  1192. mi != manifest_srcs.end(); ++mi) {
  1193. depends.push_back((*mi)->GetFullPath());
  1194. }
  1195. // Add user-specified dependencies.
  1196. if (const char* linkDepends =
  1197. this->GeneratorTarget->GetProperty("LINK_DEPENDS")) {
  1198. cmSystemTools::ExpandListArgument(linkDepends, depends);
  1199. }
  1200. }
  1201. std::string cmMakefileTargetGenerator::GetLinkRule(
  1202. const std::string& linkRuleVar)
  1203. {
  1204. std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
  1205. if (this->GeneratorTarget->HasImplibGNUtoMS()) {
  1206. std::string ruleVar = "CMAKE_";
  1207. ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
  1208. ruleVar += "_GNUtoMS_RULE";
  1209. if (const char* rule = this->Makefile->GetDefinition(ruleVar)) {
  1210. linkRule += rule;
  1211. }
  1212. }
  1213. return linkRule;
  1214. }
  1215. void cmMakefileTargetGenerator::CloseFileStreams()
  1216. {
  1217. delete this->BuildFileStream;
  1218. delete this->InfoFileStream;
  1219. delete this->FlagFileStream;
  1220. }
  1221. void cmMakefileTargetGenerator::RemoveForbiddenFlags(
  1222. const char* flagVar, const std::string& linkLang, std::string& linkFlags)
  1223. {
  1224. // check for language flags that are not allowed at link time, and
  1225. // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
  1226. // which fails, there may be more]
  1227. std::string removeFlags = "CMAKE_";
  1228. removeFlags += linkLang;
  1229. removeFlags += flagVar;
  1230. std::string removeflags = this->Makefile->GetSafeDefinition(removeFlags);
  1231. std::vector<std::string> removeList;
  1232. cmSystemTools::ExpandListArgument(removeflags, removeList);
  1233. for (std::vector<std::string>::iterator i = removeList.begin();
  1234. i != removeList.end(); ++i) {
  1235. std::string tmp;
  1236. std::string::size_type lastPosition = 0;
  1237. for (;;) {
  1238. std::string::size_type position = linkFlags.find(*i, lastPosition);
  1239. if (position == std::string::npos) {
  1240. tmp += linkFlags.substr(lastPosition);
  1241. break;
  1242. } else {
  1243. std::string::size_type prefixLength = position - lastPosition;
  1244. tmp += linkFlags.substr(lastPosition, prefixLength);
  1245. lastPosition = position + i->length();
  1246. bool validFlagStart =
  1247. position == 0 || isspace(linkFlags[position - 1]);
  1248. bool validFlagEnd =
  1249. lastPosition == linkFlags.size() || isspace(linkFlags[lastPosition]);
  1250. if (!validFlagStart || !validFlagEnd) {
  1251. tmp += *i;
  1252. }
  1253. }
  1254. }
  1255. linkFlags = tmp;
  1256. }
  1257. }
  1258. void cmMakefileTargetGenerator::CreateLinkScript(
  1259. const char* name, std::vector<std::string> const& link_commands,
  1260. std::vector<std::string>& makefile_commands,
  1261. std::vector<std::string>& makefile_depends)
  1262. {
  1263. // Create the link script file.
  1264. std::string linkScriptName = this->TargetBuildDirectoryFull;
  1265. linkScriptName += "/";
  1266. linkScriptName += name;
  1267. cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
  1268. linkScriptStream.SetCopyIfDifferent(true);
  1269. for (std::vector<std::string>::const_iterator cmd = link_commands.begin();
  1270. cmd != link_commands.end(); ++cmd) {
  1271. // Do not write out empty commands or commands beginning in the
  1272. // shell no-op ":".
  1273. if (!cmd->empty() && (*cmd)[0] != ':') {
  1274. linkScriptStream << *cmd << "\n";
  1275. }
  1276. }
  1277. // Create the makefile command to invoke the link script.
  1278. std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
  1279. link_command += this->Convert(linkScriptName, cmLocalGenerator::START_OUTPUT,
  1280. cmLocalGenerator::SHELL);
  1281. link_command += " --verbose=$(VERBOSE)";
  1282. makefile_commands.push_back(link_command);
  1283. makefile_depends.push_back(linkScriptName);
  1284. }
  1285. std::string cmMakefileTargetGenerator::CreateResponseFile(
  1286. const char* name, std::string const& options,
  1287. std::vector<std::string>& makefile_depends)
  1288. {
  1289. // Create the response file.
  1290. std::string responseFileNameFull = this->TargetBuildDirectoryFull;
  1291. responseFileNameFull += "/";
  1292. responseFileNameFull += name;
  1293. cmGeneratedFileStream responseStream(responseFileNameFull.c_str());
  1294. responseStream.SetCopyIfDifferent(true);
  1295. responseStream << options << "\n";
  1296. // Add a dependency so the target will rebuild when the set of
  1297. // objects changes.
  1298. makefile_depends.push_back(responseFileNameFull);
  1299. // Construct the name to be used on the command line.
  1300. std::string responseFileName = this->TargetBuildDirectory;
  1301. responseFileName += "/";
  1302. responseFileName += name;
  1303. return responseFileName;
  1304. }
  1305. void cmMakefileTargetGenerator::CreateLinkLibs(
  1306. std::string& linkLibs, bool relink, bool useResponseFile,
  1307. std::vector<std::string>& makefile_depends, bool useWatcomQuote)
  1308. {
  1309. std::string frameworkPath;
  1310. std::string linkPath;
  1311. this->LocalGenerator->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
  1312. *this->GeneratorTarget, relink,
  1313. useResponseFile, useWatcomQuote);
  1314. linkLibs = frameworkPath + linkPath + linkLibs;
  1315. if (useResponseFile && linkLibs.find_first_not_of(' ') != linkLibs.npos) {
  1316. // Lookup the response file reference flag.
  1317. std::string responseFlagVar = "CMAKE_";
  1318. responseFlagVar +=
  1319. this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
  1320. responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
  1321. const char* responseFlag = this->Makefile->GetDefinition(responseFlagVar);
  1322. if (!responseFlag) {
  1323. responseFlag = "@";
  1324. }
  1325. // Create this response file.
  1326. std::string link_rsp =
  1327. this->CreateResponseFile("linklibs.rsp", linkLibs, makefile_depends);
  1328. // Reference the response file.
  1329. linkLibs = responseFlag;
  1330. linkLibs +=
  1331. this->Convert(link_rsp, cmLocalGenerator::NONE, cmLocalGenerator::SHELL);
  1332. }
  1333. }
  1334. void cmMakefileTargetGenerator::CreateObjectLists(
  1335. bool useLinkScript, bool useArchiveRules, bool useResponseFile,
  1336. std::string& buildObjs, std::vector<std::string>& makefile_depends,
  1337. bool useWatcomQuote)
  1338. {
  1339. std::string variableName;
  1340. std::string variableNameExternal;
  1341. this->WriteObjectsVariable(variableName, variableNameExternal,
  1342. useWatcomQuote);
  1343. if (useResponseFile) {
  1344. // MSVC response files cannot exceed 128K.
  1345. std::string::size_type const responseFileLimit = 131000;
  1346. // Construct the individual object list strings.
  1347. std::vector<std::string> object_strings;
  1348. this->WriteObjectsStrings(object_strings, responseFileLimit);
  1349. // Lookup the response file reference flag.
  1350. std::string responseFlagVar = "CMAKE_";
  1351. responseFlagVar +=
  1352. this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
  1353. responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
  1354. const char* responseFlag = this->Makefile->GetDefinition(responseFlagVar);
  1355. if (!responseFlag) {
  1356. responseFlag = "@";
  1357. }
  1358. // Write a response file for each string.
  1359. const char* sep = "";
  1360. for (unsigned int i = 0; i < object_strings.size(); ++i) {
  1361. // Number the response files.
  1362. char rsp[32];
  1363. sprintf(rsp, "objects%u.rsp", i + 1);
  1364. // Create this response file.
  1365. std::string objects_rsp =
  1366. this->CreateResponseFile(rsp, object_strings[i], makefile_depends);
  1367. // Separate from previous response file references.
  1368. buildObjs += sep;
  1369. sep = " ";
  1370. // Reference the response file.
  1371. buildObjs += responseFlag;
  1372. buildObjs += this->Convert(objects_rsp, cmLocalGenerator::NONE,
  1373. cmLocalGenerator::SHELL);
  1374. }
  1375. } else if (useLinkScript) {
  1376. if (!useArchiveRules) {
  1377. this->WriteObjectsString(buildObjs);
  1378. }
  1379. } else {
  1380. buildObjs = "$(";
  1381. buildObjs += variableName;
  1382. buildObjs += ") $(";
  1383. buildObjs += variableNameExternal;
  1384. buildObjs += ")";
  1385. }
  1386. }
  1387. void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
  1388. const std::string& lang)
  1389. {
  1390. std::string responseVar = "CMAKE_";
  1391. responseVar += lang;
  1392. responseVar += "_USE_RESPONSE_FILE_FOR_INCLUDES";
  1393. bool useResponseFile = this->Makefile->IsOn(responseVar);
  1394. std::vector<std::string> includes;
  1395. const std::string& config =
  1396. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1397. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  1398. lang, config);
  1399. std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
  1400. includes, this->GeneratorTarget, lang, false, useResponseFile, config);
  1401. if (includeFlags.empty()) {
  1402. return;
  1403. }
  1404. if (useResponseFile) {
  1405. std::string name = "includes_";
  1406. name += lang;
  1407. name += ".rsp";
  1408. std::string arg = "@" +
  1409. this->CreateResponseFile(name.c_str(), includeFlags,
  1410. this->FlagFileDepends[lang]);
  1411. this->LocalGenerator->AppendFlags(flags, arg);
  1412. } else {
  1413. this->LocalGenerator->AppendFlags(flags, includeFlags);
  1414. }
  1415. }