cmMakefileTargetGenerator.cxx 64 KB

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