cmMakefileTargetGenerator.cxx 63 KB

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