cmMakefileTargetGenerator.cxx 60 KB

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