cmMakefileTargetGenerator.cxx 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  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->LocalGenerator->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->LocalGenerator->GetCurrentBinaryDirectory(),
  581. cmLocalGenerator::FULL);
  582. compileCommand.replace(compileCommand.find(langFlags),
  583. langFlags.size(), this->GetFlags(lang));
  584. std::string langDefines = std::string("$(") + lang + "_DEFINES)";
  585. compileCommand.replace(compileCommand.find(langDefines),
  586. langDefines.size(), this->GetDefines(lang));
  587. std::string langIncludes = std::string("$(") + lang + "_INCLUDES)";
  588. compileCommand.replace(compileCommand.find(langIncludes),
  589. langIncludes.size(), this->GetIncludes(lang));
  590. this->GlobalGenerator->AddCXXCompileCommand(
  591. source.GetFullPath(), workingDirectory, compileCommand);
  592. }
  593. // Maybe insert an include-what-you-use runner.
  594. if (!compileCommands.empty() && (lang == "C" || lang == "CXX"))
  595. {
  596. std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
  597. const char *iwyu = this->Target->GetProperty(iwyu_prop);
  598. if (iwyu && *iwyu)
  599. {
  600. std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu --iwyu=";
  601. run_iwyu += this->LocalGenerator->EscapeForShell(iwyu);
  602. run_iwyu += " -- ";
  603. compileCommands.front().insert(0, run_iwyu);
  604. }
  605. }
  606. // Maybe insert a compiler launcher like ccache or distcc
  607. if (!compileCommands.empty() && (lang == "C" || lang == "CXX"))
  608. {
  609. std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
  610. const char *clauncher = this->Target->GetProperty(clauncher_prop);
  611. if (clauncher && *clauncher)
  612. {
  613. std::vector<std::string> launcher_cmd;
  614. cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
  615. for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
  616. e = launcher_cmd.end(); i != e; ++i)
  617. {
  618. *i = this->LocalGenerator->EscapeForShell(*i);
  619. }
  620. std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
  621. compileCommands.front().insert(0, run_launcher);
  622. }
  623. }
  624. // Expand placeholders in the commands.
  625. for(std::vector<std::string>::iterator i = compileCommands.begin();
  626. i != compileCommands.end(); ++i)
  627. {
  628. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  629. }
  630. // Change the command working directory to the local build tree.
  631. this->LocalGenerator->CreateCDCommand
  632. (compileCommands,
  633. this->LocalGenerator->GetCurrentBinaryDirectory(),
  634. cmLocalGenerator::HOME_OUTPUT);
  635. commands.insert(commands.end(),
  636. compileCommands.begin(), compileCommands.end());
  637. }
  638. // Check for extra outputs created by the compilation.
  639. std::vector<std::string> outputs(1, relativeObj);
  640. if(const char* extra_outputs_str =
  641. source.GetProperty("OBJECT_OUTPUTS"))
  642. {
  643. // Register these as extra files to clean.
  644. cmSystemTools::ExpandListArgument(extra_outputs_str, outputs);
  645. this->CleanFiles.insert(this->CleanFiles.end(),
  646. outputs.begin() + 1, outputs.end());
  647. }
  648. // Write the rule.
  649. this->WriteMakeRule(*this->BuildFileStream, 0, outputs,
  650. depends, commands);
  651. bool do_preprocess_rules = lang_has_preprocessor &&
  652. this->LocalGenerator->GetCreatePreprocessedSourceRules();
  653. bool do_assembly_rules = lang_has_assembly &&
  654. this->LocalGenerator->GetCreateAssemblySourceRules();
  655. if(do_preprocess_rules || do_assembly_rules)
  656. {
  657. std::vector<std::string> force_depends;
  658. force_depends.push_back("cmake_force");
  659. std::string::size_type dot_pos = relativeObj.rfind(".");
  660. std::string relativeObjBase = relativeObj.substr(0, dot_pos);
  661. dot_pos = obj.rfind(".");
  662. std::string objBase = obj.substr(0, dot_pos);
  663. if(do_preprocess_rules)
  664. {
  665. commands.clear();
  666. std::string relativeObjI = relativeObjBase + ".i";
  667. std::string objI = objBase + ".i";
  668. std::string preprocessEcho = "Preprocessing ";
  669. preprocessEcho += lang;
  670. preprocessEcho += " source to ";
  671. preprocessEcho += objI;
  672. this->LocalGenerator->AppendEcho(
  673. commands, preprocessEcho.c_str(),
  674. cmLocalUnixMakefileGenerator3::EchoBuild
  675. );
  676. std::string preprocessRuleVar = "CMAKE_";
  677. preprocessRuleVar += lang;
  678. preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
  679. if(const char* preprocessRule =
  680. this->Makefile->GetDefinition(preprocessRuleVar))
  681. {
  682. std::vector<std::string> preprocessCommands;
  683. cmSystemTools::ExpandListArgument(preprocessRule, preprocessCommands);
  684. std::string shellObjI =
  685. this->Convert(objI,
  686. cmLocalGenerator::NONE,
  687. cmLocalGenerator::SHELL);
  688. vars.PreprocessedSource = shellObjI.c_str();
  689. // Expand placeholders in the commands.
  690. for(std::vector<std::string>::iterator i = preprocessCommands.begin();
  691. i != preprocessCommands.end(); ++i)
  692. {
  693. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  694. }
  695. this->LocalGenerator->CreateCDCommand
  696. (preprocessCommands,
  697. this->LocalGenerator->GetCurrentBinaryDirectory(),
  698. cmLocalGenerator::HOME_OUTPUT);
  699. commands.insert(commands.end(),
  700. preprocessCommands.begin(),
  701. preprocessCommands.end());
  702. }
  703. else
  704. {
  705. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  706. cmd += preprocessRuleVar;
  707. commands.push_back(cmd);
  708. }
  709. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  710. relativeObjI,
  711. force_depends, commands, false);
  712. }
  713. if(do_assembly_rules)
  714. {
  715. commands.clear();
  716. std::string relativeObjS = relativeObjBase + ".s";
  717. std::string objS = objBase + ".s";
  718. std::string assemblyEcho = "Compiling ";
  719. assemblyEcho += lang;
  720. assemblyEcho += " source to assembly ";
  721. assemblyEcho += objS;
  722. this->LocalGenerator->AppendEcho(
  723. commands, assemblyEcho.c_str(),
  724. cmLocalUnixMakefileGenerator3::EchoBuild
  725. );
  726. std::string assemblyRuleVar = "CMAKE_";
  727. assemblyRuleVar += lang;
  728. assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
  729. if(const char* assemblyRule =
  730. this->Makefile->GetDefinition(assemblyRuleVar))
  731. {
  732. std::vector<std::string> assemblyCommands;
  733. cmSystemTools::ExpandListArgument(assemblyRule, assemblyCommands);
  734. std::string shellObjS =
  735. this->Convert(objS,
  736. cmLocalGenerator::NONE,
  737. cmLocalGenerator::SHELL);
  738. vars.AssemblySource = shellObjS.c_str();
  739. // Expand placeholders in the commands.
  740. for(std::vector<std::string>::iterator i = assemblyCommands.begin();
  741. i != assemblyCommands.end(); ++i)
  742. {
  743. this->LocalGenerator->ExpandRuleVariables(*i, vars);
  744. }
  745. this->LocalGenerator->CreateCDCommand
  746. (assemblyCommands,
  747. this->LocalGenerator->GetCurrentBinaryDirectory(),
  748. cmLocalGenerator::HOME_OUTPUT);
  749. commands.insert(commands.end(),
  750. assemblyCommands.begin(),
  751. assemblyCommands.end());
  752. }
  753. else
  754. {
  755. std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
  756. cmd += assemblyRuleVar;
  757. commands.push_back(cmd);
  758. }
  759. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  760. relativeObjS,
  761. force_depends, commands, false);
  762. }
  763. }
  764. // If the language needs provides-requires mode, create the
  765. // corresponding targets.
  766. std::string objectRequires = relativeObj;
  767. objectRequires += ".requires";
  768. std::vector<std::string> p_depends;
  769. // always provide an empty requires target
  770. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  771. objectRequires, p_depends,
  772. no_commands, true);
  773. // write a build rule to recursively build what this obj provides
  774. std::string objectProvides = relativeObj;
  775. objectProvides += ".provides";
  776. std::string temp = relativeObj;
  777. temp += ".provides.build";
  778. std::vector<std::string> r_commands;
  779. std::string tgtMakefileName =
  780. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  781. tgtMakefileName += "/build.make";
  782. r_commands.push_back
  783. (this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(),
  784. temp));
  785. p_depends.clear();
  786. p_depends.push_back(objectRequires);
  787. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  788. objectProvides, p_depends,
  789. r_commands, true);
  790. // write the provides.build rule dependency on the obj file
  791. p_depends.clear();
  792. p_depends.push_back(relativeObj);
  793. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  794. temp, p_depends, no_commands,
  795. false);
  796. }
  797. //----------------------------------------------------------------------------
  798. void cmMakefileTargetGenerator::WriteTargetRequiresRules()
  799. {
  800. std::vector<std::string> depends;
  801. std::vector<std::string> no_commands;
  802. // Construct the name of the dependency generation target.
  803. std::string depTarget =
  804. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  805. depTarget += "/requires";
  806. // This target drives dependency generation for all object files.
  807. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  808. std::string objTarget;
  809. for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
  810. obj != this->Objects.end(); ++obj)
  811. {
  812. objTarget = relPath;
  813. objTarget += *obj;
  814. objTarget += ".requires";
  815. depends.push_back(objTarget);
  816. }
  817. // Write the rule.
  818. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  819. depTarget,
  820. depends, no_commands, true);
  821. }
  822. //----------------------------------------------------------------------------
  823. void cmMakefileTargetGenerator::WriteTargetCleanRules()
  824. {
  825. std::vector<std::string> depends;
  826. std::vector<std::string> commands;
  827. // Construct the clean target name.
  828. std::string cleanTarget =
  829. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  830. cleanTarget += "/clean";
  831. // Construct the clean command.
  832. this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
  833. *this->Target);
  834. this->LocalGenerator->CreateCDCommand
  835. (commands,
  836. this->LocalGenerator->GetCurrentBinaryDirectory(),
  837. cmLocalGenerator::HOME_OUTPUT);
  838. // Write the rule.
  839. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  840. cleanTarget,
  841. depends, commands, true);
  842. }
  843. //----------------------------------------------------------------------------
  844. bool cmMakefileTargetGenerator::WriteMakeRule(
  845. std::ostream& os,
  846. const char* comment,
  847. const std::vector<std::string>& outputs,
  848. const std::vector<std::string>& depends,
  849. const std::vector<std::string>& commands,
  850. bool in_help)
  851. {
  852. bool symbolic = false;
  853. if (outputs.size() == 0)
  854. {
  855. return symbolic;
  856. }
  857. // Check whether we need to bother checking for a symbolic output.
  858. bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
  859. // Check whether the first output is marked as symbolic.
  860. if(need_symbolic)
  861. {
  862. if(cmSourceFile* sf = this->Makefile->GetSource(outputs[0]))
  863. {
  864. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  865. }
  866. }
  867. // We always attach the actual commands to the first output.
  868. this->LocalGenerator->WriteMakeRule(os, comment, outputs[0], depends,
  869. commands, symbolic, in_help);
  870. // For single outputs, we are done.
  871. if (outputs.size() == 1)
  872. {
  873. return symbolic;
  874. }
  875. // For multiple outputs, make the extra ones depend on the first one.
  876. std::vector<std::string> const output_depends(1, outputs[0]);
  877. for (std::vector<std::string>::const_iterator o = outputs.begin()+1;
  878. o != outputs.end(); ++o)
  879. {
  880. // Touch the extra output so "make" knows that it was updated,
  881. // but only if the output was acually created.
  882. std::string const out = this->Convert(*o, cmLocalGenerator::HOME_OUTPUT,
  883. cmLocalGenerator::SHELL);
  884. std::vector<std::string> output_commands;
  885. bool o_symbolic = false;
  886. if(need_symbolic)
  887. {
  888. if(cmSourceFile* sf = this->Makefile->GetSource(*o))
  889. {
  890. o_symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  891. }
  892. }
  893. symbolic = symbolic && o_symbolic;
  894. if (!o_symbolic)
  895. {
  896. output_commands.push_back("@$(CMAKE_COMMAND) -E touch_nocreate " + out);
  897. }
  898. this->LocalGenerator->WriteMakeRule(os, 0, *o, output_depends,
  899. output_commands, o_symbolic, in_help);
  900. if (!o_symbolic)
  901. {
  902. // At build time, remove the first output if this one does not exist
  903. // so that "make" will rerun the real commands that create this one.
  904. MultipleOutputPairsType::value_type p(*o, outputs[0]);
  905. this->MultipleOutputPairs.insert(p);
  906. }
  907. }
  908. return symbolic;
  909. }
  910. //----------------------------------------------------------------------------
  911. void cmMakefileTargetGenerator::WriteTargetDependRules()
  912. {
  913. // must write the targets depend info file
  914. std::string dir = this->LocalGenerator->GetTargetDirectory(*this->Target);
  915. this->InfoFileNameFull = dir;
  916. this->InfoFileNameFull += "/DependInfo.cmake";
  917. this->InfoFileNameFull =
  918. this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
  919. this->InfoFileStream =
  920. new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
  921. this->InfoFileStream->SetCopyIfDifferent(true);
  922. if(!*this->InfoFileStream)
  923. {
  924. return;
  925. }
  926. this->LocalGenerator->
  927. WriteDependLanguageInfo(*this->InfoFileStream,*this->Target);
  928. // Store multiple output pairs in the depend info file.
  929. if(!this->MultipleOutputPairs.empty())
  930. {
  931. *this->InfoFileStream
  932. << "\n"
  933. << "# Pairs of files generated by the same build rule.\n"
  934. << "set(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
  935. for(MultipleOutputPairsType::const_iterator pi =
  936. this->MultipleOutputPairs.begin();
  937. pi != this->MultipleOutputPairs.end(); ++pi)
  938. {
  939. *this->InfoFileStream
  940. << " " << cmOutputConverter::EscapeForCMake(pi->first)
  941. << " " << cmOutputConverter::EscapeForCMake(pi->second)
  942. << "\n";
  943. }
  944. *this->InfoFileStream << " )\n\n";
  945. }
  946. // Store list of targets linked directly or transitively.
  947. {
  948. *this->InfoFileStream
  949. << "\n"
  950. << "# Targets to which this target links.\n"
  951. << "set(CMAKE_TARGET_LINKED_INFO_FILES\n";
  952. std::vector<std::string> dirs = this->GetLinkedTargetDirectories();
  953. for (std::vector<std::string>::iterator i = dirs.begin();
  954. i != dirs.end(); ++i)
  955. {
  956. *this->InfoFileStream << " \"" << *i << "/DependInfo.cmake\"\n";
  957. }
  958. *this->InfoFileStream
  959. << " )\n";
  960. }
  961. *this->InfoFileStream
  962. << "\n"
  963. << "# Fortran module output directory.\n"
  964. << "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
  965. << this->GetFortranModuleDirectory() << "\")\n";
  966. // and now write the rule to use it
  967. std::vector<std::string> depends;
  968. std::vector<std::string> commands;
  969. // Construct the name of the dependency generation target.
  970. std::string depTarget =
  971. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  972. depTarget += "/depend";
  973. // Add a command to call CMake to scan dependencies. CMake will
  974. // touch the corresponding depends file after scanning dependencies.
  975. std::ostringstream depCmd;
  976. // TODO: Account for source file properties and directory-level
  977. // definitions when scanning for dependencies.
  978. #if !defined(_WIN32) || defined(__CYGWIN__)
  979. // This platform supports symlinks, so cmSystemTools will translate
  980. // paths. Make sure PWD is set to the original name of the home
  981. // output directory to help cmSystemTools to create the same
  982. // translation table for the dependency scanning process.
  983. depCmd << "cd "
  984. << (this->LocalGenerator->Convert(
  985. this->LocalGenerator->GetBinaryDirectory(),
  986. cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
  987. << " && ";
  988. #endif
  989. // Generate a call this signature:
  990. //
  991. // cmake -E cmake_depends <generator>
  992. // <home-src-dir> <start-src-dir>
  993. // <home-out-dir> <start-out-dir>
  994. // <dep-info> --color=$(COLOR)
  995. //
  996. // This gives the dependency scanner enough information to recreate
  997. // the state of our local generator sufficiently for its needs.
  998. depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
  999. << this->GlobalGenerator->GetName() << "\" "
  1000. << this->Convert(this->LocalGenerator->GetSourceDirectory(),
  1001. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1002. << " "
  1003. << this->Convert(this->LocalGenerator->GetCurrentSourceDirectory(),
  1004. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1005. << " "
  1006. << this->Convert(this->LocalGenerator->GetBinaryDirectory(),
  1007. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1008. << " "
  1009. << this->Convert(this->LocalGenerator->GetCurrentBinaryDirectory(),
  1010. cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
  1011. << " "
  1012. << this->Convert(this->InfoFileNameFull,
  1013. cmLocalGenerator::FULL, cmLocalGenerator::SHELL);
  1014. if(this->LocalGenerator->GetColorMakefile())
  1015. {
  1016. depCmd << " --color=$(COLOR)";
  1017. }
  1018. commands.push_back(depCmd.str());
  1019. // Make sure all custom command outputs in this target are built.
  1020. if(this->CustomCommandDriver == OnDepends)
  1021. {
  1022. this->DriveCustomCommands(depends);
  1023. }
  1024. // Write the rule.
  1025. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  1026. depTarget,
  1027. depends, commands, true);
  1028. }
  1029. //----------------------------------------------------------------------------
  1030. void
  1031. cmMakefileTargetGenerator
  1032. ::DriveCustomCommands(std::vector<std::string>& depends)
  1033. {
  1034. // Depend on all custom command outputs.
  1035. std::vector<cmSourceFile*> sources;
  1036. this->GeneratorTarget->GetSourceFiles(sources,
  1037. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  1038. for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
  1039. source != sources.end(); ++source)
  1040. {
  1041. if(cmCustomCommand* cc = (*source)->GetCustomCommand())
  1042. {
  1043. cmCustomCommandGenerator ccg(*cc, this->ConfigName,
  1044. this->LocalGenerator);
  1045. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1046. depends.insert(depends.end(), outputs.begin(), outputs.end());
  1047. }
  1048. }
  1049. }
  1050. //----------------------------------------------------------------------------
  1051. void cmMakefileTargetGenerator
  1052. ::WriteObjectDependRules(cmSourceFile const& source,
  1053. std::vector<std::string>& depends)
  1054. {
  1055. // Create the list of dependencies known at cmake time. These are
  1056. // shared between the object file and dependency scanning rule.
  1057. depends.push_back(source.GetFullPath());
  1058. if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
  1059. {
  1060. cmSystemTools::ExpandListArgument(objectDeps, depends);
  1061. }
  1062. }
  1063. //----------------------------------------------------------------------------
  1064. void cmMakefileTargetGenerator
  1065. ::GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg)
  1066. {
  1067. // Collect the commands.
  1068. std::vector<std::string> commands;
  1069. std::string comment = this->LocalGenerator->ConstructComment(ccg);
  1070. if(!comment.empty())
  1071. {
  1072. // add in a progress call if needed
  1073. this->NumberOfProgressActions++;
  1074. if(!this->NoRuleMessages)
  1075. {
  1076. cmLocalUnixMakefileGenerator3::EchoProgress progress;
  1077. this->MakeEchoProgress(progress);
  1078. this->LocalGenerator
  1079. ->AppendEcho(commands, comment.c_str(),
  1080. cmLocalUnixMakefileGenerator3::EchoGenerate,
  1081. &progress);
  1082. }
  1083. }
  1084. // Now append the actual user-specified commands.
  1085. std::ostringstream content;
  1086. this->LocalGenerator->AppendCustomCommand(commands, ccg, this->Target, false,
  1087. cmLocalGenerator::HOME_OUTPUT,
  1088. &content);
  1089. // Collect the dependencies.
  1090. std::vector<std::string> depends;
  1091. this->LocalGenerator->AppendCustomDepend(depends, ccg);
  1092. // Write the rule.
  1093. const std::vector<std::string>& outputs = ccg.GetOutputs();
  1094. bool symbolic = this->WriteMakeRule(*this->BuildFileStream, 0,
  1095. outputs, depends, commands);
  1096. // If the rule has changed make sure the output is rebuilt.
  1097. if(!symbolic)
  1098. {
  1099. this->GlobalGenerator->AddRuleHash(ccg.GetOutputs(), content.str());
  1100. }
  1101. // Setup implicit dependency scanning.
  1102. for(cmCustomCommand::ImplicitDependsList::const_iterator
  1103. idi = ccg.GetCC().GetImplicitDepends().begin();
  1104. idi != ccg.GetCC().GetImplicitDepends().end(); ++idi)
  1105. {
  1106. std::string objFullPath =
  1107. this->Convert(outputs[0], cmLocalGenerator::FULL);
  1108. std::string srcFullPath =
  1109. this->Convert(idi->second, cmLocalGenerator::FULL);
  1110. this->LocalGenerator->
  1111. AddImplicitDepends(*this->Target, idi->first,
  1112. objFullPath.c_str(),
  1113. srcFullPath.c_str());
  1114. }
  1115. }
  1116. //----------------------------------------------------------------------------
  1117. void
  1118. cmMakefileTargetGenerator
  1119. ::MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress& progress) const
  1120. {
  1121. progress.Dir = this->LocalGenerator->GetBinaryDirectory();
  1122. progress.Dir += cmake::GetCMakeFilesDirectory();
  1123. std::ostringstream progressArg;
  1124. progressArg << "$(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
  1125. progress.Arg = progressArg.str();
  1126. }
  1127. //----------------------------------------------------------------------------
  1128. void
  1129. cmMakefileTargetGenerator
  1130. ::WriteObjectsVariable(std::string& variableName,
  1131. std::string& variableNameExternal,
  1132. bool useWatcomQuote)
  1133. {
  1134. // Write a make variable assignment that lists all objects for the
  1135. // target.
  1136. variableName =
  1137. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  1138. "_OBJECTS");
  1139. *this->BuildFileStream
  1140. << "# Object files for target " << this->Target->GetName() << "\n"
  1141. << variableName << " =";
  1142. std::string object;
  1143. const char* lineContinue =
  1144. this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
  1145. if(!lineContinue)
  1146. {
  1147. lineContinue = "\\";
  1148. }
  1149. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  1150. i != this->Objects.end(); ++i)
  1151. {
  1152. *this->BuildFileStream << " " << lineContinue << "\n";
  1153. *this->BuildFileStream <<
  1154. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str(),
  1155. useWatcomQuote);
  1156. }
  1157. *this->BuildFileStream << "\n";
  1158. // Write a make variable assignment that lists all external objects
  1159. // for the target.
  1160. variableNameExternal =
  1161. this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
  1162. "_EXTERNAL_OBJECTS");
  1163. *this->BuildFileStream
  1164. << "\n"
  1165. << "# External object files for target "
  1166. << this->Target->GetName() << "\n"
  1167. << variableNameExternal << " =";
  1168. for(std::vector<std::string>::const_iterator i =
  1169. this->ExternalObjects.begin();
  1170. i != this->ExternalObjects.end(); ++i)
  1171. {
  1172. object = this->Convert(*i,cmLocalGenerator::START_OUTPUT);
  1173. *this->BuildFileStream
  1174. << " " << lineContinue << "\n"
  1175. << this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
  1176. *this->BuildFileStream <<
  1177. this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str(),
  1178. useWatcomQuote);
  1179. }
  1180. *this->BuildFileStream << "\n" << "\n";
  1181. }
  1182. //----------------------------------------------------------------------------
  1183. void
  1184. cmMakefileTargetGenerator
  1185. ::WriteObjectsString(std::string& buildObjs)
  1186. {
  1187. std::vector<std::string> objStrings;
  1188. this->WriteObjectsStrings(objStrings);
  1189. buildObjs = objStrings[0];
  1190. }
  1191. //----------------------------------------------------------------------------
  1192. class cmMakefileTargetGeneratorObjectStrings
  1193. {
  1194. public:
  1195. cmMakefileTargetGeneratorObjectStrings(std::vector<std::string>& strings,
  1196. cmLocalUnixMakefileGenerator3* lg,
  1197. std::string::size_type limit):
  1198. Strings(strings), LocalGenerator(lg), LengthLimit(limit)
  1199. {
  1200. this->Space = "";
  1201. }
  1202. void Feed(std::string const& obj)
  1203. {
  1204. // Construct the name of the next object.
  1205. this->NextObject =
  1206. this->LocalGenerator->Convert(obj,
  1207. cmLocalGenerator::START_OUTPUT,
  1208. cmLocalGenerator::RESPONSE);
  1209. // Roll over to next string if the limit will be exceeded.
  1210. if(this->LengthLimit != std::string::npos &&
  1211. (this->CurrentString.length() + 1 + this->NextObject.length()
  1212. > this->LengthLimit))
  1213. {
  1214. this->Strings.push_back(this->CurrentString);
  1215. this->CurrentString = "";
  1216. this->Space = "";
  1217. }
  1218. // Separate from previous object.
  1219. this->CurrentString += this->Space;
  1220. this->Space = " ";
  1221. // Append this object.
  1222. this->CurrentString += this->NextObject;
  1223. }
  1224. void Done()
  1225. {
  1226. this->Strings.push_back(this->CurrentString);
  1227. }
  1228. private:
  1229. std::vector<std::string>& Strings;
  1230. cmLocalUnixMakefileGenerator3* LocalGenerator;
  1231. std::string::size_type LengthLimit;
  1232. std::string CurrentString;
  1233. std::string NextObject;
  1234. const char* Space;
  1235. };
  1236. //----------------------------------------------------------------------------
  1237. void
  1238. cmMakefileTargetGenerator
  1239. ::WriteObjectsStrings(std::vector<std::string>& objStrings,
  1240. std::string::size_type limit)
  1241. {
  1242. cmMakefileTargetGeneratorObjectStrings
  1243. helper(objStrings, this->LocalGenerator, limit);
  1244. for(std::vector<std::string>::const_iterator i = this->Objects.begin();
  1245. i != this->Objects.end(); ++i)
  1246. {
  1247. helper.Feed(*i);
  1248. }
  1249. for(std::vector<std::string>::const_iterator i =
  1250. this->ExternalObjects.begin();
  1251. i != this->ExternalObjects.end(); ++i)
  1252. {
  1253. helper.Feed(*i);
  1254. }
  1255. helper.Done();
  1256. }
  1257. //----------------------------------------------------------------------------
  1258. void cmMakefileTargetGenerator::WriteTargetDriverRule(
  1259. const std::string& main_output,
  1260. bool relink)
  1261. {
  1262. // Compute the name of the driver target.
  1263. std::string dir =
  1264. this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
  1265. std::string buildTargetRuleName = dir;
  1266. buildTargetRuleName += relink?"/preinstall":"/build";
  1267. buildTargetRuleName = this->Convert(buildTargetRuleName,
  1268. cmLocalGenerator::HOME_OUTPUT,
  1269. cmLocalGenerator::UNCHANGED);
  1270. // Build the list of target outputs to drive.
  1271. std::vector<std::string> depends;
  1272. depends.push_back(main_output);
  1273. const char* comment = 0;
  1274. if(relink)
  1275. {
  1276. // Setup the comment for the preinstall driver.
  1277. comment = "Rule to relink during preinstall.";
  1278. }
  1279. else
  1280. {
  1281. // Setup the comment for the main build driver.
  1282. comment = "Rule to build all files generated by this target.";
  1283. // Make sure all custom command outputs in this target are built.
  1284. if(this->CustomCommandDriver == OnBuild)
  1285. {
  1286. this->DriveCustomCommands(depends);
  1287. }
  1288. // Make sure the extra files are built.
  1289. depends.insert(depends.end(),
  1290. this->ExtraFiles.begin(), this->ExtraFiles.end());
  1291. }
  1292. // Write the driver rule.
  1293. std::vector<std::string> no_commands;
  1294. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
  1295. buildTargetRuleName,
  1296. depends, no_commands, true);
  1297. }
  1298. //----------------------------------------------------------------------------
  1299. void cmMakefileTargetGenerator
  1300. ::AppendTargetDepends(std::vector<std::string>& depends)
  1301. {
  1302. // Static libraries never depend on anything for linking.
  1303. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
  1304. {
  1305. return;
  1306. }
  1307. // Loop over all library dependencies.
  1308. const char* cfg = this->LocalGenerator->GetConfigName().c_str();
  1309. if(cmComputeLinkInformation* cli =
  1310. this->GeneratorTarget->GetLinkInformation(cfg))
  1311. {
  1312. std::vector<std::string> const& libDeps = cli->GetDepends();
  1313. depends.insert(depends.end(), libDeps.begin(), libDeps.end());
  1314. }
  1315. }
  1316. //----------------------------------------------------------------------------
  1317. void cmMakefileTargetGenerator
  1318. ::AppendObjectDepends(std::vector<std::string>& depends)
  1319. {
  1320. // Add dependencies on the compiled object files.
  1321. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  1322. std::string objTarget;
  1323. for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
  1324. obj != this->Objects.end(); ++obj)
  1325. {
  1326. objTarget = relPath;
  1327. objTarget += *obj;
  1328. depends.push_back(objTarget);
  1329. }
  1330. // Add dependencies on the external object files.
  1331. depends.insert(depends.end(),
  1332. this->ExternalObjects.begin(), this->ExternalObjects.end());
  1333. // Add a dependency on the rule file itself.
  1334. this->LocalGenerator->AppendRuleDepend(depends,
  1335. this->BuildFileNameFull.c_str());
  1336. }
  1337. //----------------------------------------------------------------------------
  1338. void cmMakefileTargetGenerator
  1339. ::AppendLinkDepends(std::vector<std::string>& depends)
  1340. {
  1341. this->AppendObjectDepends(depends);
  1342. // Add dependencies on targets that must be built first.
  1343. this->AppendTargetDepends(depends);
  1344. // Add a dependency on the link definitions file, if any.
  1345. if(!this->ModuleDefinitionFile.empty())
  1346. {
  1347. depends.push_back(this->ModuleDefinitionFile);
  1348. }
  1349. // Add a dependency on user-specified manifest files, if any.
  1350. std::vector<cmSourceFile const*> manifest_srcs;
  1351. this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
  1352. for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
  1353. mi != manifest_srcs.end(); ++mi)
  1354. {
  1355. depends.push_back((*mi)->GetFullPath());
  1356. }
  1357. // Add user-specified dependencies.
  1358. if(const char* linkDepends =
  1359. this->Target->GetProperty("LINK_DEPENDS"))
  1360. {
  1361. cmSystemTools::ExpandListArgument(linkDepends, depends);
  1362. }
  1363. }
  1364. //----------------------------------------------------------------------------
  1365. std::string cmMakefileTargetGenerator::GetLinkRule(
  1366. const std::string& linkRuleVar)
  1367. {
  1368. std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
  1369. if(this->Target->HasImplibGNUtoMS())
  1370. {
  1371. std::string ruleVar = "CMAKE_";
  1372. ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
  1373. ruleVar += "_GNUtoMS_RULE";
  1374. if(const char* rule = this->Makefile->GetDefinition(ruleVar))
  1375. {
  1376. linkRule += rule;
  1377. }
  1378. }
  1379. return linkRule;
  1380. }
  1381. //----------------------------------------------------------------------------
  1382. void cmMakefileTargetGenerator
  1383. ::CloseFileStreams()
  1384. {
  1385. delete this->BuildFileStream;
  1386. delete this->InfoFileStream;
  1387. delete this->FlagFileStream;
  1388. }
  1389. void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
  1390. const std::string& linkLang,
  1391. std::string& linkFlags)
  1392. {
  1393. // check for language flags that are not allowed at link time, and
  1394. // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
  1395. // which fails, there may be more]
  1396. std::string removeFlags = "CMAKE_";
  1397. removeFlags += linkLang;
  1398. removeFlags += flagVar;
  1399. std::string removeflags =
  1400. this->Makefile->GetSafeDefinition(removeFlags);
  1401. std::vector<std::string> removeList;
  1402. cmSystemTools::ExpandListArgument(removeflags, removeList);
  1403. for(std::vector<std::string>::iterator i = removeList.begin();
  1404. i != removeList.end(); ++i)
  1405. {
  1406. std::string tmp;
  1407. std::string::size_type lastPosition = 0;
  1408. for(;;)
  1409. {
  1410. std::string::size_type position = linkFlags.find(*i, lastPosition);
  1411. if(position == std::string::npos)
  1412. {
  1413. tmp += linkFlags.substr(lastPosition);
  1414. break;
  1415. }
  1416. else
  1417. {
  1418. std::string::size_type prefixLength = position - lastPosition;
  1419. tmp += linkFlags.substr(lastPosition, prefixLength);
  1420. lastPosition = position + i->length();
  1421. bool validFlagStart = position == 0 ||
  1422. isspace(linkFlags[position - 1]);
  1423. bool validFlagEnd = lastPosition == linkFlags.size() ||
  1424. isspace(linkFlags[lastPosition]);
  1425. if(!validFlagStart || !validFlagEnd)
  1426. {
  1427. tmp += *i;
  1428. }
  1429. }
  1430. }
  1431. linkFlags = tmp;
  1432. }
  1433. }
  1434. //----------------------------------------------------------------------------
  1435. void
  1436. cmMakefileTargetGenerator
  1437. ::CreateLinkScript(const char* name,
  1438. std::vector<std::string> const& link_commands,
  1439. std::vector<std::string>& makefile_commands,
  1440. std::vector<std::string>& makefile_depends)
  1441. {
  1442. // Create the link script file.
  1443. std::string linkScriptName = this->TargetBuildDirectoryFull;
  1444. linkScriptName += "/";
  1445. linkScriptName += name;
  1446. cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
  1447. linkScriptStream.SetCopyIfDifferent(true);
  1448. for(std::vector<std::string>::const_iterator cmd = link_commands.begin();
  1449. cmd != link_commands.end(); ++cmd)
  1450. {
  1451. // Do not write out empty commands or commands beginning in the
  1452. // shell no-op ":".
  1453. if(!cmd->empty() && (*cmd)[0] != ':')
  1454. {
  1455. linkScriptStream << *cmd << "\n";
  1456. }
  1457. }
  1458. // Create the makefile command to invoke the link script.
  1459. std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
  1460. link_command += this->Convert(linkScriptName,
  1461. cmLocalGenerator::START_OUTPUT,
  1462. cmLocalGenerator::SHELL);
  1463. link_command += " --verbose=$(VERBOSE)";
  1464. makefile_commands.push_back(link_command);
  1465. makefile_depends.push_back(linkScriptName);
  1466. }
  1467. //----------------------------------------------------------------------------
  1468. std::string
  1469. cmMakefileTargetGenerator
  1470. ::CreateResponseFile(const char* name, std::string const& options,
  1471. std::vector<std::string>& makefile_depends)
  1472. {
  1473. // Create the response file.
  1474. std::string responseFileNameFull = this->TargetBuildDirectoryFull;
  1475. responseFileNameFull += "/";
  1476. responseFileNameFull += name;
  1477. cmGeneratedFileStream responseStream(responseFileNameFull.c_str());
  1478. responseStream.SetCopyIfDifferent(true);
  1479. responseStream << options << "\n";
  1480. // Add a dependency so the target will rebuild when the set of
  1481. // objects changes.
  1482. makefile_depends.push_back(responseFileNameFull);
  1483. // Construct the name to be used on the command line.
  1484. std::string responseFileName = this->TargetBuildDirectory;
  1485. responseFileName += "/";
  1486. responseFileName += name;
  1487. return responseFileName;
  1488. }
  1489. //----------------------------------------------------------------------------
  1490. void
  1491. cmMakefileTargetGenerator
  1492. ::CreateLinkLibs(std::string& linkLibs, bool relink,
  1493. bool useResponseFile,
  1494. std::vector<std::string>& makefile_depends,
  1495. bool useWatcomQuote)
  1496. {
  1497. std::string frameworkPath;
  1498. std::string linkPath;
  1499. this->LocalGenerator
  1500. ->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
  1501. *this->GeneratorTarget, relink,
  1502. useResponseFile,
  1503. useWatcomQuote);
  1504. linkLibs = frameworkPath + linkPath + linkLibs;
  1505. if(useResponseFile && linkLibs.find_first_not_of(" ") != linkLibs.npos)
  1506. {
  1507. // Lookup the response file reference flag.
  1508. std::string responseFlagVar = "CMAKE_";
  1509. responseFlagVar += this->GeneratorTarget
  1510. ->GetLinkerLanguage(this->ConfigName);
  1511. responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
  1512. const char* responseFlag =
  1513. this->Makefile->GetDefinition(responseFlagVar);
  1514. if(!responseFlag)
  1515. {
  1516. responseFlag = "@";
  1517. }
  1518. // Create this response file.
  1519. std::string link_rsp =
  1520. this->CreateResponseFile("linklibs.rsp", linkLibs, makefile_depends);
  1521. // Reference the response file.
  1522. linkLibs = responseFlag;
  1523. linkLibs += this->Convert(link_rsp,
  1524. cmLocalGenerator::NONE,
  1525. cmLocalGenerator::SHELL);
  1526. }
  1527. }
  1528. //----------------------------------------------------------------------------
  1529. void
  1530. cmMakefileTargetGenerator
  1531. ::CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  1532. bool useResponseFile, std::string& buildObjs,
  1533. std::vector<std::string>& makefile_depends,
  1534. bool useWatcomQuote)
  1535. {
  1536. std::string variableName;
  1537. std::string variableNameExternal;
  1538. this->WriteObjectsVariable(variableName, variableNameExternal,
  1539. useWatcomQuote);
  1540. if(useResponseFile)
  1541. {
  1542. // MSVC response files cannot exceed 128K.
  1543. std::string::size_type const responseFileLimit = 131000;
  1544. // Construct the individual object list strings.
  1545. std::vector<std::string> object_strings;
  1546. this->WriteObjectsStrings(object_strings, responseFileLimit);
  1547. // Lookup the response file reference flag.
  1548. std::string responseFlagVar = "CMAKE_";
  1549. responseFlagVar += this->GeneratorTarget
  1550. ->GetLinkerLanguage(this->ConfigName);
  1551. responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
  1552. const char* responseFlag =
  1553. this->Makefile->GetDefinition(responseFlagVar);
  1554. if(!responseFlag)
  1555. {
  1556. responseFlag = "@";
  1557. }
  1558. // Write a response file for each string.
  1559. const char* sep = "";
  1560. for(unsigned int i = 0; i < object_strings.size(); ++i)
  1561. {
  1562. // Number the response files.
  1563. char rsp[32];
  1564. sprintf(rsp, "objects%u.rsp", i+1);
  1565. // Create this response file.
  1566. std::string objects_rsp =
  1567. this->CreateResponseFile(rsp, object_strings[i], makefile_depends);
  1568. // Separate from previous response file references.
  1569. buildObjs += sep;
  1570. sep = " ";
  1571. // Reference the response file.
  1572. buildObjs += responseFlag;
  1573. buildObjs += this->Convert(objects_rsp,
  1574. cmLocalGenerator::NONE,
  1575. cmLocalGenerator::SHELL);
  1576. }
  1577. }
  1578. else if(useLinkScript)
  1579. {
  1580. if(!useArchiveRules)
  1581. {
  1582. this->WriteObjectsString(buildObjs);
  1583. }
  1584. }
  1585. else
  1586. {
  1587. buildObjs = "$(";
  1588. buildObjs += variableName;
  1589. buildObjs += ") $(";
  1590. buildObjs += variableNameExternal;
  1591. buildObjs += ")";
  1592. }
  1593. }
  1594. //----------------------------------------------------------------------------
  1595. void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
  1596. const std::string& lang)
  1597. {
  1598. std::string responseVar = "CMAKE_";
  1599. responseVar += lang;
  1600. responseVar += "_USE_RESPONSE_FILE_FOR_INCLUDES";
  1601. bool useResponseFile = this->Makefile->IsOn(responseVar);
  1602. std::vector<std::string> includes;
  1603. const std::string& config =
  1604. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
  1605. this->LocalGenerator->GetIncludeDirectories(includes,
  1606. this->GeneratorTarget,
  1607. lang, config);
  1608. std::string includeFlags =
  1609. this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget,
  1610. lang, false, useResponseFile,
  1611. config);
  1612. if(includeFlags.empty())
  1613. {
  1614. return;
  1615. }
  1616. if(useResponseFile)
  1617. {
  1618. std::string name = "includes_";
  1619. name += lang;
  1620. name += ".rsp";
  1621. std::string arg = "@" +
  1622. this->CreateResponseFile(name.c_str(), includeFlags,
  1623. this->FlagFileDepends[lang]);
  1624. this->LocalGenerator->AppendFlags(flags, arg);
  1625. }
  1626. else
  1627. {
  1628. this->LocalGenerator->AppendFlags(flags, includeFlags);
  1629. }
  1630. }