cmMakefileTargetGenerator.cxx 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  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(cmOutputConverter::START_OUTPUT, 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->LocalGenerator);
  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->GeneratorTarget->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->GetGeneratorTarget()->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. // generate the build rule file
  378. this->WriteObjectBuildFile(obj, lang, source, depends);
  379. // The object file should be checked for dependency integrity.
  380. std::string objFullPath = this->Makefile->GetCurrentBinaryDirectory();
  381. objFullPath += "/";
  382. objFullPath += obj;
  383. objFullPath =
  384. this->Convert(objFullPath, cmLocalGenerator::FULL);
  385. std::string srcFullPath =
  386. this->Convert(source.GetFullPath(), cmLocalGenerator::FULL);
  387. this->LocalGenerator->
  388. AddImplicitDepends(*this->Target, lang,
  389. objFullPath.c_str(),
  390. srcFullPath.c_str());
  391. }
  392. //----------------------------------------------------------------------------
  393. void
  394. cmMakefileTargetGenerator
  395. ::WriteObjectBuildFile(std::string &obj,
  396. const std::string& lang,
  397. cmSourceFile const& source,
  398. std::vector<std::string>& depends)
  399. {
  400. this->LocalGenerator->AppendRuleDepend(depends,
  401. this->FlagFileNameFull.c_str());
  402. this->LocalGenerator->AppendRuleDepends(depends,
  403. this->FlagFileDepends[lang]);
  404. // generate the depend scanning rule
  405. this->WriteObjectDependRules(source, depends);
  406. std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
  407. relativeObj += obj;
  408. // Write the build rule.
  409. // Build the set of compiler flags.
  410. std::string flags;
  411. // Add language-specific flags.
  412. std::string langFlags = "$(";
  413. langFlags += lang;
  414. langFlags += "_FLAGS)";
  415. this->LocalGenerator->AppendFlags(flags, langFlags);
  416. std::string configUpper =
  417. cmSystemTools::UpperCase(this->LocalGenerator->GetConfigName());
  418. // Add Fortran format flags.
  419. if(lang == "Fortran")
  420. {
  421. this->AppendFortranFormatFlags(flags, source);
  422. }
  423. // Add flags from source file properties.
  424. if (source.GetProperty("COMPILE_FLAGS"))
  425. {
  426. this->LocalGenerator->AppendFlags
  427. (flags, source.GetProperty("COMPILE_FLAGS"));
  428. *this->FlagFileStream << "# Custom flags: "
  429. << relativeObj << "_FLAGS = "
  430. << source.GetProperty("COMPILE_FLAGS")
  431. << "\n"
  432. << "\n";
  433. }
  434. // Add language-specific defines.
  435. std::set<std::string> defines;
  436. // Add source-sepcific preprocessor definitions.
  437. if(const char* compile_defs = source.GetProperty("COMPILE_DEFINITIONS"))
  438. {
  439. this->LocalGenerator->AppendDefines(defines, compile_defs);
  440. *this->FlagFileStream << "# Custom defines: "
  441. << relativeObj << "_DEFINES = "
  442. << compile_defs << "\n"
  443. << "\n";
  444. }
  445. std::string defPropName = "COMPILE_DEFINITIONS_";
  446. defPropName += configUpper;
  447. if(const char* config_compile_defs =
  448. source.GetProperty(defPropName))
  449. {
  450. this->LocalGenerator->AppendDefines(defines, config_compile_defs);
  451. *this->FlagFileStream
  452. << "# Custom defines: "
  453. << relativeObj << "_DEFINES_" << configUpper
  454. << " = " << config_compile_defs << "\n"
  455. << "\n";
  456. }
  457. // Get the output paths for source and object files.
  458. std::string sourceFile = this->Convert(source.GetFullPath(),
  459. cmLocalGenerator::NONE,
  460. cmLocalGenerator::SHELL);
  461. // Construct the build message.
  462. std::vector<std::string> no_commands;
  463. std::vector<std::string> commands;
  464. // add in a progress call if needed
  465. this->NumberOfProgressActions++;
  466. if(!this->NoRuleMessages)
  467. {
  468. cmLocalUnixMakefileGenerator3::EchoProgress progress;
  469. this->MakeEchoProgress(progress);
  470. std::string buildEcho = "Building ";
  471. buildEcho += lang;
  472. buildEcho += " object ";
  473. buildEcho += relativeObj;
  474. this->LocalGenerator->AppendEcho
  475. (commands, buildEcho.c_str(), cmLocalUnixMakefileGenerator3::EchoBuild,
  476. &progress);
  477. }
  478. std::string targetOutPathReal;
  479. std::string targetOutPathPDB;
  480. std::string targetOutPathCompilePDB;
  481. {
  482. std::string targetFullPathReal;
  483. std::string targetFullPathPDB;
  484. std::string targetFullPathCompilePDB;
  485. if(this->Target->GetType() == cmTarget::EXECUTABLE ||
  486. this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
  487. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  488. this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  489. {
  490. targetFullPathReal =
  491. this->GeneratorTarget->GetFullPath(this->ConfigName, false, true);
  492. targetFullPathPDB =
  493. this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
  494. targetFullPathPDB += "/";
  495. targetFullPathPDB += this->GeneratorTarget->GetPDBName(this->ConfigName);
  496. }
  497. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  498. {
  499. targetFullPathCompilePDB =
  500. this->GeneratorTarget->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::vector<std::string> dirs = this->GetLinkedTargetDirectories();
  952. for (std::vector<std::string>::iterator i = dirs.begin();
  953. i != dirs.end(); ++i)
  954. {
  955. *this->InfoFileStream << " \"" << *i << "/DependInfo.cmake\"\n";
  956. }
  957. *this->InfoFileStream
  958. << " )\n";
  959. }
  960. *this->InfoFileStream
  961. << "\n"
  962. << "# Fortran module output directory.\n"
  963. << "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
  964. << this->GetFortranModuleDirectory() << "\")\n";
  965. // and now write the rule to use it
  966. std::vector<std::string> depends;
  967. std::vector<std::string> commands;
  968. // Construct the name of the dependency generation target.
  969. std::string depTarget =
  970. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  971. depTarget += "/depend";
  972. // Add a command to call CMake to scan dependencies. CMake will
  973. // touch the corresponding depends file after scanning dependencies.
  974. std::ostringstream depCmd;
  975. // TODO: Account for source file properties and directory-level
  976. // definitions when scanning for dependencies.
  977. #if !defined(_WIN32) || defined(__CYGWIN__)
  978. // This platform supports symlinks, so cmSystemTools will translate
  979. // paths. Make sure PWD is set to the original name of the home
  980. // output directory to help cmSystemTools to create the same
  981. // translation table for the dependency scanning process.
  982. depCmd << "cd "
  983. << (this->LocalGenerator->Convert(
  984. this->Makefile->GetHomeOutputDirectory(),
  985. cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
  986. << " && ";
  987. #endif
  988. // Generate a call this signature:
  989. //
  990. // cmake -E cmake_depends <generator>
  991. // <home-src-dir> <start-src-dir>
  992. // <home-out-dir> <start-out-dir>
  993. // <dep-info> --color=$(COLOR)
  994. //
  995. // This gives the dependency scanner enough information to recreate
  996. // the state of our local generator sufficiently for its needs.
  997. depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
  998. << this->GlobalGenerator->GetName() << "\" "
  999. << this->Convert(this->Makefile->GetHomeDirectory(),
  1000. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1001. << " "
  1002. << this->Convert(this->Makefile->GetCurrentSourceDirectory(),
  1003. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1004. << " "
  1005. << this->Convert(this->Makefile->GetHomeOutputDirectory(),
  1006. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1007. << " "
  1008. << this->Convert(this->Makefile->GetCurrentBinaryDirectory(),
  1009. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1010. << " "
  1011. << this->Convert(this->InfoFileNameFull,
  1012. cmLocalGenerator::FULL, cmLocalGenerator::SHELL);
  1013. if(this->LocalGenerator->GetColorMakefile())
  1014. {
  1015. depCmd << " --color=$(COLOR)";
  1016. }
  1017. commands.push_back(depCmd.str());
  1018. // Make sure all custom command outputs in this target are built.
  1019. if(this->CustomCommandDriver == OnDepends)
  1020. {
  1021. this->DriveCustomCommands(depends);
  1022. }
  1023. // Write the rule.
  1024. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  1025. depTarget,
  1026. depends, commands, true);
  1027. }
  1028. //----------------------------------------------------------------------------
  1029. void
  1030. cmMakefileTargetGenerator
  1031. ::DriveCustomCommands(std::vector<std::string>& depends)
  1032. {
  1033. // Depend on all custom command outputs.
  1034. std::vector<cmSourceFile*> sources;
  1035. this->GeneratorTarget->GetSourceFiles(sources,
  1036. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  1037. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1038. source != sources.end(); ++source)
  1039. {
  1040. if(cmCustomCommand* cc = (*source)->GetCustomCommand())
  1041. {
  1042. cmCustomCommandGenerator ccg(*cc, this->ConfigName,
  1043. this->LocalGenerator);
  1044. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1045. depends.insert(depends.end(), outputs.begin(), outputs.end());
  1046. }
  1047. }
  1048. }
  1049. //----------------------------------------------------------------------------
  1050. void cmMakefileTargetGenerator
  1051. ::WriteObjectDependRules(cmSourceFile const& source,
  1052. std::vector<std::string>& depends)
  1053. {
  1054. // Create the list of dependencies known at cmake time. These are
  1055. // shared between the object file and dependency scanning rule.
  1056. depends.push_back(source.GetFullPath());
  1057. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  1058. {
  1059. cmSystemTools::ExpandListArgument(objectDeps, depends);
  1060. }
  1061. }
  1062. //----------------------------------------------------------------------------
  1063. void cmMakefileTargetGenerator
  1064. ::GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg)
  1065. {
  1066. // Collect the commands.
  1067. std::vector<std::string> commands;
  1068. std::string comment = this->LocalGenerator->ConstructComment(ccg);
  1069. if(!comment.empty())
  1070. {
  1071. // add in a progress call if needed
  1072. this->NumberOfProgressActions++;
  1073. if(!this->NoRuleMessages)
  1074. {
  1075. cmLocalUnixMakefileGenerator3::EchoProgress progress;
  1076. this->MakeEchoProgress(progress);
  1077. this->LocalGenerator
  1078. ->AppendEcho(commands, comment.c_str(),
  1079. cmLocalUnixMakefileGenerator3::EchoGenerate,
  1080. &progress);
  1081. }
  1082. }
  1083. // Now append the actual user-specified commands.
  1084. std::ostringstream content;
  1085. this->LocalGenerator->AppendCustomCommand(commands, ccg, this->Target, false,
  1086. cmLocalGenerator::HOME_OUTPUT,
  1087. &content);
  1088. // Collect the dependencies.
  1089. std::vector<std::string> depends;
  1090. this->LocalGenerator->AppendCustomDepend(depends, ccg);
  1091. // Write the rule.
  1092. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1093. bool symbolic = this->WriteMakeRule(*this->BuildFileStream, 0,
  1094. outputs, depends, commands);
  1095. // If the rule has changed make sure the output is rebuilt.
  1096. if(!symbolic)
  1097. {
  1098. this->GlobalGenerator->AddRuleHash(ccg.GetOutputs(), content.str());
  1099. }
  1100. // Setup implicit dependency scanning.
  1101. for(cmCustomCommand::ImplicitDependsList::const_iterator
  1102. idi = ccg.GetCC().GetImplicitDepends().begin();
  1103. idi != ccg.GetCC().GetImplicitDepends().end(); ++idi)
  1104. {
  1105. std::string objFullPath =
  1106. this->Convert(outputs[0], cmLocalGenerator::FULL);
  1107. std::string srcFullPath =
  1108. this->Convert(idi->second, cmLocalGenerator::FULL);
  1109. this->LocalGenerator->
  1110. AddImplicitDepends(*this->Target, idi->first,
  1111. objFullPath.c_str(),
  1112. srcFullPath.c_str());
  1113. }
  1114. }
  1115. //----------------------------------------------------------------------------
  1116. void
  1117. cmMakefileTargetGenerator
  1118. ::MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress& progress) const
  1119. {
  1120. progress.Dir = this->Makefile->GetHomeOutputDirectory();
  1121. progress.Dir += cmake::GetCMakeFilesDirectory();
  1122. std::ostringstream progressArg;
  1123. progressArg << "$(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
  1124. progress.Arg = progressArg.str();
  1125. }
  1126. //----------------------------------------------------------------------------
  1127. void
  1128. cmMakefileTargetGenerator
  1129. ::WriteObjectsVariable(std::string& variableName,
  1130. std::string& variableNameExternal,
  1131. bool useWatcomQuote)
  1132. {
  1133. // Write a make variable assignment that lists all objects for the
  1134. // target.
  1135. variableName =
  1136. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  1137. "_OBJECTS");
  1138. *this->BuildFileStream
  1139. << "# Object files for target " << this->Target->GetName() << "\n"
  1140. << variableName << " =";
  1141. std::string object;
  1142. const char* lineContinue =
  1143. this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
  1144. if(!lineContinue)
  1145. {
  1146. lineContinue = "\\";
  1147. }
  1148. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  1149. i != this->Objects.end(); ++i)
  1150. {
  1151. *this->BuildFileStream << " " << lineContinue << "\n";
  1152. *this->BuildFileStream <<
  1153. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str(),
  1154. useWatcomQuote);
  1155. }
  1156. *this->BuildFileStream << "\n";
  1157. // Write a make variable assignment that lists all external objects
  1158. // for the target.
  1159. variableNameExternal =
  1160. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  1161. "_EXTERNAL_OBJECTS");
  1162. *this->BuildFileStream
  1163. << "\n"
  1164. << "# External object files for target "
  1165. << this->Target->GetName() << "\n"
  1166. << variableNameExternal << " =";
  1167. for(std::vector<std::string>::const_iterator i =
  1168. this->ExternalObjects.begin();
  1169. i != this->ExternalObjects.end(); ++i)
  1170. {
  1171. object = this->Convert(*i,cmLocalGenerator::START_OUTPUT);
  1172. *this->BuildFileStream
  1173. << " " << lineContinue << "\n"
  1174. << this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
  1175. *this->BuildFileStream <<
  1176. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str(),
  1177. useWatcomQuote);
  1178. }
  1179. *this->BuildFileStream << "\n" << "\n";
  1180. }
  1181. //----------------------------------------------------------------------------
  1182. void
  1183. cmMakefileTargetGenerator
  1184. ::WriteObjectsString(std::string& buildObjs)
  1185. {
  1186. std::vector<std::string> objStrings;
  1187. this->WriteObjectsStrings(objStrings);
  1188. buildObjs = objStrings[0];
  1189. }
  1190. //----------------------------------------------------------------------------
  1191. class cmMakefileTargetGeneratorObjectStrings
  1192. {
  1193. public:
  1194. cmMakefileTargetGeneratorObjectStrings(std::vector<std::string>& strings,
  1195. cmLocalUnixMakefileGenerator3* lg,
  1196. std::string::size_type limit):
  1197. Strings(strings), LocalGenerator(lg), LengthLimit(limit)
  1198. {
  1199. this->Space = "";
  1200. }
  1201. void Feed(std::string const& obj)
  1202. {
  1203. // Construct the name of the next object.
  1204. this->NextObject =
  1205. this->LocalGenerator->Convert(obj,
  1206. cmLocalGenerator::START_OUTPUT,
  1207. cmLocalGenerator::RESPONSE);
  1208. // Roll over to next string if the limit will be exceeded.
  1209. if(this->LengthLimit != std::string::npos &&
  1210. (this->CurrentString.length() + 1 + this->NextObject.length()
  1211. > this->LengthLimit))
  1212. {
  1213. this->Strings.push_back(this->CurrentString);
  1214. this->CurrentString = "";
  1215. this->Space = "";
  1216. }
  1217. // Separate from previous object.
  1218. this->CurrentString += this->Space;
  1219. this->Space = " ";
  1220. // Append this object.
  1221. this->CurrentString += this->NextObject;
  1222. }
  1223. void Done()
  1224. {
  1225. this->Strings.push_back(this->CurrentString);
  1226. }
  1227. private:
  1228. std::vector<std::string>& Strings;
  1229. cmLocalUnixMakefileGenerator3* LocalGenerator;
  1230. std::string::size_type LengthLimit;
  1231. std::string CurrentString;
  1232. std::string NextObject;
  1233. const char* Space;
  1234. };
  1235. //----------------------------------------------------------------------------
  1236. void
  1237. cmMakefileTargetGenerator
  1238. ::WriteObjectsStrings(std::vector<std::string>& objStrings,
  1239. std::string::size_type limit)
  1240. {
  1241. cmMakefileTargetGeneratorObjectStrings
  1242. helper(objStrings, this->LocalGenerator, limit);
  1243. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  1244. i != this->Objects.end(); ++i)
  1245. {
  1246. helper.Feed(*i);
  1247. }
  1248. for(std::vector<std::string>::const_iterator i =
  1249. this->ExternalObjects.begin();
  1250. i != this->ExternalObjects.end(); ++i)
  1251. {
  1252. helper.Feed(*i);
  1253. }
  1254. helper.Done();
  1255. }
  1256. //----------------------------------------------------------------------------
  1257. void cmMakefileTargetGenerator::WriteTargetDriverRule(
  1258. const std::string& main_output,
  1259. bool relink)
  1260. {
  1261. // Compute the name of the driver target.
  1262. std::string dir =
  1263. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  1264. std::string buildTargetRuleName = dir;
  1265. buildTargetRuleName += relink?"/preinstall":"/build";
  1266. buildTargetRuleName = this->Convert(buildTargetRuleName,
  1267. cmLocalGenerator::HOME_OUTPUT,
  1268. cmLocalGenerator::UNCHANGED);
  1269. // Build the list of target outputs to drive.
  1270. std::vector<std::string> depends;
  1271. depends.push_back(main_output);
  1272. const char* comment = 0;
  1273. if(relink)
  1274. {
  1275. // Setup the comment for the preinstall driver.
  1276. comment = "Rule to relink during preinstall.";
  1277. }
  1278. else
  1279. {
  1280. // Setup the comment for the main build driver.
  1281. comment = "Rule to build all files generated by this target.";
  1282. // Make sure all custom command outputs in this target are built.
  1283. if(this->CustomCommandDriver == OnBuild)
  1284. {
  1285. this->DriveCustomCommands(depends);
  1286. }
  1287. // Make sure the extra files are built.
  1288. depends.insert(depends.end(),
  1289. this->ExtraFiles.begin(), this->ExtraFiles.end());
  1290. }
  1291. // Write the driver rule.
  1292. std::vector<std::string> no_commands;
  1293. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
  1294. buildTargetRuleName,
  1295. depends, no_commands, true);
  1296. }
  1297. //----------------------------------------------------------------------------
  1298. void cmMakefileTargetGenerator
  1299. ::AppendTargetDepends(std::vector<std::string>& depends)
  1300. {
  1301. // Static libraries never depend on anything for linking.
  1302. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
  1303. {
  1304. return;
  1305. }
  1306. // Loop over all library dependencies.
  1307. const char* cfg = this->LocalGenerator->GetConfigName().c_str();
  1308. if(cmComputeLinkInformation* cli =
  1309. this->GeneratorTarget->GetLinkInformation(cfg))
  1310. {
  1311. std::vector<std::string> const& libDeps = cli->GetDepends();
  1312. depends.insert(depends.end(), libDeps.begin(), libDeps.end());
  1313. }
  1314. }
  1315. //----------------------------------------------------------------------------
  1316. void cmMakefileTargetGenerator
  1317. ::AppendObjectDepends(std::vector<std::string>& depends)
  1318. {
  1319. // Add dependencies on the compiled object files.
  1320. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  1321. std::string objTarget;
  1322. for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
  1323. obj != this->Objects.end(); ++obj)
  1324. {
  1325. objTarget = relPath;
  1326. objTarget += *obj;
  1327. depends.push_back(objTarget);
  1328. }
  1329. // Add dependencies on the external object files.
  1330. depends.insert(depends.end(),
  1331. this->ExternalObjects.begin(), this->ExternalObjects.end());
  1332. // Add a dependency on the rule file itself.
  1333. this->LocalGenerator->AppendRuleDepend(depends,
  1334. this->BuildFileNameFull.c_str());
  1335. }
  1336. //----------------------------------------------------------------------------
  1337. void cmMakefileTargetGenerator
  1338. ::AppendLinkDepends(std::vector<std::string>& depends)
  1339. {
  1340. this->AppendObjectDepends(depends);
  1341. // Add dependencies on targets that must be built first.
  1342. this->AppendTargetDepends(depends);
  1343. // Add a dependency on the link definitions file, if any.
  1344. if(!this->ModuleDefinitionFile.empty())
  1345. {
  1346. depends.push_back(this->ModuleDefinitionFile);
  1347. }
  1348. // Add a dependency on user-specified manifest files, if any.
  1349. std::vector<cmSourceFile const*> manifest_srcs;
  1350. this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
  1351. for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
  1352. mi != manifest_srcs.end(); ++mi)
  1353. {
  1354. depends.push_back((*mi)->GetFullPath());
  1355. }
  1356. // Add user-specified dependencies.
  1357. if(const char* linkDepends =
  1358. this->Target->GetProperty("LINK_DEPENDS"))
  1359. {
  1360. cmSystemTools::ExpandListArgument(linkDepends, depends);
  1361. }
  1362. }
  1363. //----------------------------------------------------------------------------
  1364. std::string cmMakefileTargetGenerator::GetLinkRule(
  1365. const std::string& linkRuleVar)
  1366. {
  1367. std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
  1368. if(this->Target->HasImplibGNUtoMS())
  1369. {
  1370. std::string ruleVar = "CMAKE_";
  1371. ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
  1372. ruleVar += "_GNUtoMS_RULE";
  1373. if(const char* rule = this->Makefile->GetDefinition(ruleVar))
  1374. {
  1375. linkRule += rule;
  1376. }
  1377. }
  1378. return linkRule;
  1379. }
  1380. //----------------------------------------------------------------------------
  1381. void cmMakefileTargetGenerator
  1382. ::CloseFileStreams()
  1383. {
  1384. delete this->BuildFileStream;
  1385. delete this->InfoFileStream;
  1386. delete this->FlagFileStream;
  1387. }
  1388. void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
  1389. const std::string& linkLang,
  1390. std::string& linkFlags)
  1391. {
  1392. // check for language flags that are not allowed at link time, and
  1393. // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
  1394. // which fails, there may be more]
  1395. std::string removeFlags = "CMAKE_";
  1396. removeFlags += linkLang;
  1397. removeFlags += flagVar;
  1398. std::string removeflags =
  1399. this->Makefile->GetSafeDefinition(removeFlags);
  1400. std::vector<std::string> removeList;
  1401. cmSystemTools::ExpandListArgument(removeflags, removeList);
  1402. for(std::vector<std::string>::iterator i = removeList.begin();
  1403. i != removeList.end(); ++i)
  1404. {
  1405. std::string tmp;
  1406. std::string::size_type lastPosition = 0;
  1407. for(;;)
  1408. {
  1409. std::string::size_type position = linkFlags.find(*i, lastPosition);
  1410. if(position == std::string::npos)
  1411. {
  1412. tmp += linkFlags.substr(lastPosition);
  1413. break;
  1414. }
  1415. else
  1416. {
  1417. std::string::size_type prefixLength = position - lastPosition;
  1418. tmp += linkFlags.substr(lastPosition, prefixLength);
  1419. lastPosition = position + i->length();
  1420. bool validFlagStart = position == 0 ||
  1421. isspace(linkFlags[position - 1]);
  1422. bool validFlagEnd = lastPosition == linkFlags.size() ||
  1423. isspace(linkFlags[lastPosition]);
  1424. if(!validFlagStart || !validFlagEnd)
  1425. {
  1426. tmp += *i;
  1427. }
  1428. }
  1429. }
  1430. linkFlags = tmp;
  1431. }
  1432. }
  1433. //----------------------------------------------------------------------------
  1434. void
  1435. cmMakefileTargetGenerator
  1436. ::CreateLinkScript(const char* name,
  1437. std::vector<std::string> const& link_commands,
  1438. std::vector<std::string>& makefile_commands,
  1439. std::vector<std::string>& makefile_depends)
  1440. {
  1441. // Create the link script file.
  1442. std::string linkScriptName = this->TargetBuildDirectoryFull;
  1443. linkScriptName += "/";
  1444. linkScriptName += name;
  1445. cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
  1446. linkScriptStream.SetCopyIfDifferent(true);
  1447. for(std::vector<std::string>::const_iterator cmd = link_commands.begin();
  1448. cmd != link_commands.end(); ++cmd)
  1449. {
  1450. // Do not write out empty commands or commands beginning in the
  1451. // shell no-op ":".
  1452. if(!cmd->empty() && (*cmd)[0] != ':')
  1453. {
  1454. linkScriptStream << *cmd << "\n";
  1455. }
  1456. }
  1457. // Create the makefile command to invoke the link script.
  1458. std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
  1459. link_command += this->Convert(linkScriptName,
  1460. cmLocalGenerator::START_OUTPUT,
  1461. cmLocalGenerator::SHELL);
  1462. link_command += " --verbose=$(VERBOSE)";
  1463. makefile_commands.push_back(link_command);
  1464. makefile_depends.push_back(linkScriptName);
  1465. }
  1466. //----------------------------------------------------------------------------
  1467. std::string
  1468. cmMakefileTargetGenerator
  1469. ::CreateResponseFile(const char* name, std::string const& options,
  1470. std::vector<std::string>& makefile_depends)
  1471. {
  1472. // Create the response file.
  1473. std::string responseFileNameFull = this->TargetBuildDirectoryFull;
  1474. responseFileNameFull += "/";
  1475. responseFileNameFull += name;
  1476. cmGeneratedFileStream responseStream(responseFileNameFull.c_str());
  1477. responseStream.SetCopyIfDifferent(true);
  1478. responseStream << options << "\n";
  1479. // Add a dependency so the target will rebuild when the set of
  1480. // objects changes.
  1481. makefile_depends.push_back(responseFileNameFull);
  1482. // Construct the name to be used on the command line.
  1483. std::string responseFileName = this->TargetBuildDirectory;
  1484. responseFileName += "/";
  1485. responseFileName += name;
  1486. return responseFileName;
  1487. }
  1488. //----------------------------------------------------------------------------
  1489. void
  1490. cmMakefileTargetGenerator
  1491. ::CreateLinkLibs(std::string& linkLibs, bool relink,
  1492. bool useResponseFile,
  1493. std::vector<std::string>& makefile_depends,
  1494. bool useWatcomQuote)
  1495. {
  1496. std::string frameworkPath;
  1497. std::string linkPath;
  1498. this->LocalGenerator
  1499. ->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
  1500. *this->GeneratorTarget, relink,
  1501. useResponseFile,
  1502. useWatcomQuote);
  1503. linkLibs = frameworkPath + linkPath + linkLibs;
  1504. if(useResponseFile && linkLibs.find_first_not_of(" ") != linkLibs.npos)
  1505. {
  1506. // Lookup the response file reference flag.
  1507. std::string responseFlagVar = "CMAKE_";
  1508. responseFlagVar += this->GeneratorTarget
  1509. ->GetLinkerLanguage(this->ConfigName);
  1510. responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
  1511. const char* responseFlag =
  1512. this->Makefile->GetDefinition(responseFlagVar);
  1513. if(!responseFlag)
  1514. {
  1515. responseFlag = "@";
  1516. }
  1517. // Create this response file.
  1518. std::string link_rsp =
  1519. this->CreateResponseFile("linklibs.rsp", linkLibs, makefile_depends);
  1520. // Reference the response file.
  1521. linkLibs = responseFlag;
  1522. linkLibs += this->Convert(link_rsp,
  1523. cmLocalGenerator::NONE,
  1524. cmLocalGenerator::SHELL);
  1525. }
  1526. }
  1527. //----------------------------------------------------------------------------
  1528. void
  1529. cmMakefileTargetGenerator
  1530. ::CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  1531. bool useResponseFile, std::string& buildObjs,
  1532. std::vector<std::string>& makefile_depends,
  1533. bool useWatcomQuote)
  1534. {
  1535. std::string variableName;
  1536. std::string variableNameExternal;
  1537. this->WriteObjectsVariable(variableName, variableNameExternal,
  1538. useWatcomQuote);
  1539. if(useResponseFile)
  1540. {
  1541. // MSVC response files cannot exceed 128K.
  1542. std::string::size_type const responseFileLimit = 131000;
  1543. // Construct the individual object list strings.
  1544. std::vector<std::string> object_strings;
  1545. this->WriteObjectsStrings(object_strings, responseFileLimit);
  1546. // Lookup the response file reference flag.
  1547. std::string responseFlagVar = "CMAKE_";
  1548. responseFlagVar += this->GeneratorTarget
  1549. ->GetLinkerLanguage(this->ConfigName);
  1550. responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
  1551. const char* responseFlag =
  1552. this->Makefile->GetDefinition(responseFlagVar);
  1553. if(!responseFlag)
  1554. {
  1555. responseFlag = "@";
  1556. }
  1557. // Write a response file for each string.
  1558. const char* sep = "";
  1559. for(unsigned int i = 0; i < object_strings.size(); ++i)
  1560. {
  1561. // Number the response files.
  1562. char rsp[32];
  1563. sprintf(rsp, "objects%u.rsp", i+1);
  1564. // Create this response file.
  1565. std::string objects_rsp =
  1566. this->CreateResponseFile(rsp, object_strings[i], makefile_depends);
  1567. // Separate from previous response file references.
  1568. buildObjs += sep;
  1569. sep = " ";
  1570. // Reference the response file.
  1571. buildObjs += responseFlag;
  1572. buildObjs += this->Convert(objects_rsp,
  1573. cmLocalGenerator::NONE,
  1574. cmLocalGenerator::SHELL);
  1575. }
  1576. }
  1577. else if(useLinkScript)
  1578. {
  1579. if(!useArchiveRules)
  1580. {
  1581. this->WriteObjectsString(buildObjs);
  1582. }
  1583. }
  1584. else
  1585. {
  1586. buildObjs = "$(";
  1587. buildObjs += variableName;
  1588. buildObjs += ") $(";
  1589. buildObjs += variableNameExternal;
  1590. buildObjs += ")";
  1591. }
  1592. }
  1593. //----------------------------------------------------------------------------
  1594. void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
  1595. const std::string& lang)
  1596. {
  1597. std::string responseVar = "CMAKE_";
  1598. responseVar += lang;
  1599. responseVar += "_USE_RESPONSE_FILE_FOR_INCLUDES";
  1600. bool useResponseFile = this->Makefile->IsOn(responseVar);
  1601. std::vector<std::string> includes;
  1602. const std::string& config =
  1603. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1604. this->LocalGenerator->GetIncludeDirectories(includes,
  1605. this->GeneratorTarget,
  1606. lang, config);
  1607. std::string includeFlags =
  1608. this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget,
  1609. lang, false, useResponseFile,
  1610. config);
  1611. if(includeFlags.empty())
  1612. {
  1613. return;
  1614. }
  1615. if(useResponseFile)
  1616. {
  1617. std::string name = "includes_";
  1618. name += lang;
  1619. name += ".rsp";
  1620. std::string arg = "@" +
  1621. this->CreateResponseFile(name.c_str(), includeFlags,
  1622. this->FlagFileDepends[lang]);
  1623. this->LocalGenerator->AppendFlags(flags, arg);
  1624. }
  1625. else
  1626. {
  1627. this->LocalGenerator->AppendFlags(flags, includeFlags);
  1628. }
  1629. }