cmMakefileTargetGenerator.cxx 63 KB

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