cmLocalUnixMakefileGenerator3.cxx 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmLocalUnixMakefileGenerator3.h"
  14. #include "cmDepends.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmGlobalUnixMakefileGenerator3.h"
  17. #include "cmMakefile.h"
  18. #include "cmMakefileTargetGenerator.h"
  19. #include "cmSourceFile.h"
  20. #include "cmake.h"
  21. // Include dependency scanners for supported languages. Only the
  22. // C/C++ scanner is needed for bootstrapping CMake.
  23. #include "cmDependsC.h"
  24. #ifdef CMAKE_BUILD_WITH_CMAKE
  25. # include "cmDependsFortran.h"
  26. # include "cmDependsJava.h"
  27. #endif
  28. #include <memory> // auto_ptr
  29. #include <queue>
  30. //----------------------------------------------------------------------------
  31. cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
  32. {
  33. this->SilentNoColon = false;
  34. this->WindowsShell = false;
  35. this->IncludeDirective = "include";
  36. this->MakefileVariableSize = 0;
  37. this->IgnoreLibPrefix = false;
  38. this->PassMakeflags = false;
  39. this->EchoNeedsQuote = true;
  40. this->DefineWindowsNULL = false;
  41. this->UnixCD = true;
  42. this->ForceVerboseMakefiles=false;
  43. }
  44. //----------------------------------------------------------------------------
  45. cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
  46. {
  47. }
  48. //----------------------------------------------------------------------------
  49. void cmLocalUnixMakefileGenerator3::Configure()
  50. {
  51. // Include the rule file for each object.
  52. this->HomeRelativeOutputPath =
  53. cmSystemTools::RelativePath(this->Makefile->GetHomeOutputDirectory(),
  54. this->Makefile->GetStartOutputDirectory());
  55. if (this->HomeRelativeOutputPath.size())
  56. {
  57. this->HomeRelativeOutputPath += "/";
  58. }
  59. this->cmLocalGenerator::Configure();
  60. }
  61. //----------------------------------------------------------------------------
  62. void cmLocalUnixMakefileGenerator3::Generate()
  63. {
  64. // Setup our configuration variables for this directory.
  65. this->ConfigureOutputPaths();
  66. // Generate the rule files for each target.
  67. cmTargets& targets = this->Makefile->GetTargets();
  68. std::string empty;
  69. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  70. {
  71. cmMakefileTargetGenerator *tg =
  72. cmMakefileTargetGenerator::New(this, t->first, &(t->second));
  73. if (tg)
  74. {
  75. this->TargetGenerators.push_back(tg);
  76. t->second.TraceVSDependencies(empty, this->Makefile);
  77. tg->WriteRuleFiles();
  78. }
  79. }
  80. // write the local Makefile
  81. this->WriteLocalMakefile();
  82. // Write the cmake file with information for this directory.
  83. this->WriteDirectoryInformationFile();
  84. // delete the makefile target generator objects
  85. for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
  86. this->TargetGenerators.begin();
  87. mtgIter != this->TargetGenerators.end(); ++mtgIter)
  88. {
  89. delete *mtgIter;
  90. }
  91. this->TargetGenerators.clear();
  92. }
  93. //----------------------------------------------------------------------------
  94. void cmLocalUnixMakefileGenerator3::ConfigureOutputPaths()
  95. {
  96. // Format the library and executable output paths.
  97. if(const char* libOut = this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  98. {
  99. this->LibraryOutputPath = libOut;
  100. this->FormatOutputPath(this->LibraryOutputPath, "LIBRARY");
  101. }
  102. if(const char* exeOut = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  103. {
  104. this->ExecutableOutputPath = exeOut;
  105. this->FormatOutputPath(this->ExecutableOutputPath, "EXECUTABLE");
  106. }
  107. // Store the configuration name that will be generated.
  108. if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
  109. {
  110. // Use the build type given by the user.
  111. this->ConfigurationName = config;
  112. }
  113. else
  114. {
  115. // No configuration type given.
  116. this->ConfigurationName = "";
  117. }
  118. }
  119. //----------------------------------------------------------------------------
  120. void cmLocalUnixMakefileGenerator3::FormatOutputPath(std::string& path,
  121. const char* name)
  122. {
  123. if(!path.empty())
  124. {
  125. // Convert the output path to a full path in case it is
  126. // specified as a relative path. Treat a relative path as
  127. // relative to the current output directory for this makefile.
  128. path =
  129. cmSystemTools::CollapseFullPath(path.c_str(),
  130. this->Makefile->GetStartOutputDirectory());
  131. // Add a trailing slash for easy appending later.
  132. if(path.empty() || path[path.size()-1] != '/')
  133. {
  134. path += "/";
  135. }
  136. // Make sure the output path exists on disk.
  137. if(!cmSystemTools::MakeDirectory(path.c_str()))
  138. {
  139. cmSystemTools::Error("Error failed to create ",
  140. name, "_OUTPUT_PATH directory:", path.c_str());
  141. }
  142. // Add this as a link directory automatically.
  143. this->Makefile->AddLinkDirectory(path.c_str());
  144. }
  145. }
  146. //----------------------------------------------------------------------------
  147. void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
  148. {
  149. // generate the includes
  150. std::string ruleFileName = "Makefile";
  151. // Open the rule file. This should be copy-if-different because the
  152. // rules may depend on this file itself.
  153. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
  154. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  155. if(!ruleFileStream)
  156. {
  157. return;
  158. }
  159. // always write the top makefile
  160. if (this->Parent)
  161. {
  162. ruleFileStream.SetCopyIfDifferent(true);
  163. }
  164. // write the all rules
  165. this->WriteLocalAllRules(ruleFileStream);
  166. // only write local targets unless at the top Keep track of targets already
  167. // listed.
  168. std::set<cmStdString> emittedTargets;
  169. if (this->Parent)
  170. {
  171. // write our targets, and while doing it collect up the object
  172. // file rules
  173. this->WriteLocalMakefileTargets(ruleFileStream,emittedTargets);
  174. }
  175. else
  176. {
  177. cmGlobalUnixMakefileGenerator3 *gg =
  178. static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
  179. gg->WriteConvenienceRules(ruleFileStream,emittedTargets);
  180. }
  181. std::vector<std::string> depends;
  182. std::vector<std::string> commands;
  183. // now write out the object rules
  184. // for each object file name
  185. for (std::map<cmStdString,std::vector<cmTarget *> >::iterator lo =
  186. this->LocalObjectFiles.begin();
  187. lo != this->LocalObjectFiles.end(); ++lo)
  188. {
  189. commands.clear();
  190. // for each target using the object file
  191. for (std::vector<cmTarget *>::iterator to =
  192. lo->second.begin(); to != lo->second.end(); ++to)
  193. {
  194. std::string tgtMakefileName = this->GetRelativeTargetDirectory(**to);
  195. std::string targetName = tgtMakefileName;
  196. tgtMakefileName += "/build.make";
  197. targetName += "/";
  198. targetName += lo->first.c_str();
  199. commands.push_back(this->GetRecursiveMakeCall
  200. (tgtMakefileName.c_str(),targetName.c_str()));
  201. this->CreateCDCommand(commands,
  202. this->Makefile->GetHomeOutputDirectory(),
  203. this->Makefile->GetStartOutputDirectory());
  204. }
  205. this->WriteMakeRule(ruleFileStream,
  206. "target for object file",
  207. lo->first.c_str(), depends, commands, false);
  208. }
  209. // add a help target as long as there isn;t a real target named help
  210. if(emittedTargets.insert("help").second)
  211. {
  212. cmGlobalUnixMakefileGenerator3 *gg =
  213. static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
  214. gg->WriteHelpRule(ruleFileStream,this);
  215. }
  216. this->WriteSpecialTargetsBottom(ruleFileStream);
  217. }
  218. void cmLocalUnixMakefileGenerator3
  219. ::WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  220. std::set<cmStdString> &emitted)
  221. {
  222. std::vector<std::string> depends;
  223. std::vector<std::string> commands;
  224. // for each target we just provide a rule to cd up to the top and do a make
  225. // on the target
  226. cmTargets& targets = this->Makefile->GetTargets();
  227. std::string localName;
  228. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  229. {
  230. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  231. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  232. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  233. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  234. (t->second.GetType() == cmTarget::UTILITY))
  235. {
  236. emitted.insert(t->second.GetName());
  237. // for subdirs add a rule to build this specific target by name.
  238. localName = this->GetRelativeTargetDirectory(t->second);
  239. localName += "/rule";
  240. commands.clear();
  241. depends.clear();
  242. // Build the target for this pass.
  243. commands.push_back(this->GetRecursiveMakeCall
  244. ("CMakeFiles/Makefile2",localName.c_str()));
  245. this->CreateCDCommand(commands,
  246. this->Makefile->GetHomeOutputDirectory(),
  247. this->Makefile->GetStartOutputDirectory());
  248. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  249. localName.c_str(), depends, commands, true);
  250. // Add a target with the canonical name (no prefix, suffix or path).
  251. if(localName != t->second.GetName())
  252. {
  253. commands.clear();
  254. depends.push_back(localName);
  255. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  256. t->second.GetName(), depends, commands, true);
  257. }
  258. }
  259. }
  260. }
  261. //----------------------------------------------------------------------------
  262. void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
  263. {
  264. std::string infoFileName = this->Makefile->GetStartOutputDirectory();
  265. infoFileName += "/CMakeFiles/CMakeDirectoryInformation.cmake";
  266. // Open the output file.
  267. cmGeneratedFileStream infoFileStream(infoFileName.c_str());
  268. if(!infoFileStream)
  269. {
  270. return;
  271. }
  272. // Write the do not edit header.
  273. this->WriteDisclaimer(infoFileStream);
  274. // Tell the dependency scanner to use unix paths if necessary.
  275. if(cmSystemTools::GetForceUnixPaths())
  276. {
  277. infoFileStream
  278. << "# Force unix paths in dependencies.\n"
  279. << "SET(CMAKE_FORCE_UNIX_PATHS 1)\n"
  280. << "\n";
  281. }
  282. // Store the include search path for this directory.
  283. infoFileStream
  284. << "# The C and CXX include file search paths:\n";
  285. infoFileStream
  286. << "SET(CMAKE_C_INCLUDE_PATH\n";
  287. std::vector<std::string> includeDirs;
  288. this->GetIncludeDirectories(includeDirs);
  289. for(std::vector<std::string>::iterator i = includeDirs.begin();
  290. i != includeDirs.end(); ++i)
  291. {
  292. // Note: This path conversion must match that used for
  293. // CMAKE_GENERATED_FILES so that the file names match.
  294. infoFileStream
  295. << " \"" << this->Convert(i->c_str(),HOME_OUTPUT).c_str() << "\"\n";
  296. }
  297. infoFileStream
  298. << " )\n";
  299. infoFileStream
  300. << "SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n";
  301. // Store the include regular expressions for this directory.
  302. infoFileStream
  303. << "\n"
  304. << "# The C and CXX include file regular expressions for this directory.\n";
  305. infoFileStream
  306. << "SET(CMAKE_C_INCLUDE_REGEX_SCAN ";
  307. this->WriteCMakeArgument(infoFileStream,
  308. this->Makefile->GetIncludeRegularExpression());
  309. infoFileStream
  310. << ")\n";
  311. infoFileStream
  312. << "SET(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
  313. this->WriteCMakeArgument(infoFileStream,
  314. this->Makefile->GetComplainRegularExpression());
  315. infoFileStream
  316. << ")\n";
  317. infoFileStream
  318. << "SET(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
  319. infoFileStream
  320. << "SET(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
  321. // Store the set of available generated files.
  322. infoFileStream
  323. << "\n"
  324. << "# The set of files generated by rules in this directory:\n";
  325. infoFileStream
  326. << "SET(CMAKE_GENERATED_FILES\n";
  327. for(std::vector<cmSourceFile*>::const_iterator
  328. i = this->Makefile->GetSourceFiles().begin();
  329. i != this->Makefile->GetSourceFiles().end(); ++i)
  330. {
  331. cmSourceFile* src = *i;
  332. if(src->GetPropertyAsBool("GENERATED"))
  333. {
  334. // Note: This path conversion must match that used for
  335. // CMAKE_C_INCLUDE_PATH so that the file names match.
  336. infoFileStream
  337. << " \""
  338. << this->Convert(src->GetFullPath().c_str(), HOME_OUTPUT)
  339. << "\"\n";
  340. }
  341. }
  342. infoFileStream
  343. << ")\n";
  344. }
  345. //----------------------------------------------------------------------------
  346. std::string
  347. cmLocalUnixMakefileGenerator3
  348. ::ConvertToFullPath(const std::string& localPath)
  349. {
  350. std::string dir = this->Makefile->GetStartOutputDirectory();
  351. dir += "/";
  352. dir += localPath;
  353. return dir;
  354. }
  355. const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
  356. {
  357. return this->HomeRelativeOutputPath;
  358. }
  359. //----------------------------------------------------------------------------
  360. void
  361. cmLocalUnixMakefileGenerator3
  362. ::WriteMakeRule(std::ostream& os,
  363. const char* comment,
  364. const char* target,
  365. const std::vector<std::string>& depends,
  366. const std::vector<std::string>& commands,
  367. bool symbolic)
  368. {
  369. // Make sure there is a target.
  370. if(!target || !*target)
  371. {
  372. cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
  373. comment);
  374. return;
  375. }
  376. std::string replace;
  377. // Write the comment describing the rule in the makefile.
  378. if(comment)
  379. {
  380. replace = comment;
  381. std::string::size_type lpos = 0;
  382. std::string::size_type rpos;
  383. while((rpos = replace.find('\n', lpos)) != std::string::npos)
  384. {
  385. os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
  386. lpos = rpos+1;
  387. }
  388. os << "# " << replace.substr(lpos) << "\n";
  389. }
  390. // Construct the left hand side of the rule.
  391. replace = target;
  392. std::string tgt = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  393. tgt = this->ConvertToMakeTarget(tgt.c_str());
  394. const char* space = "";
  395. if(tgt.size() == 1)
  396. {
  397. // Add a space before the ":" to avoid drive letter confusion on
  398. // Windows.
  399. space = " ";
  400. }
  401. // Mark the rule as symbolic if requested.
  402. if(symbolic)
  403. {
  404. if(const char* sym =
  405. this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE"))
  406. {
  407. os << tgt.c_str() << space << ": " << sym << "\n";
  408. }
  409. }
  410. // Write the rule.
  411. if(depends.empty())
  412. {
  413. // No dependencies. The commands will always run.
  414. os << tgt.c_str() << space << ":\n";
  415. }
  416. else
  417. {
  418. // Split dependencies into multiple rule lines. This allows for
  419. // very long dependency lists even on older make implementations.
  420. for(std::vector<std::string>::const_iterator dep = depends.begin();
  421. dep != depends.end(); ++dep)
  422. {
  423. replace = *dep;
  424. replace = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
  425. replace = this->ConvertToMakeTarget(replace.c_str());
  426. os << tgt.c_str() << space << ": " << replace.c_str() << "\n";
  427. }
  428. }
  429. // Write the list of commands.
  430. for(std::vector<std::string>::const_iterator i = commands.begin();
  431. i != commands.end(); ++i)
  432. {
  433. replace = *i;
  434. os << "\t" << replace.c_str() << "\n";
  435. }
  436. os << "\n";
  437. }
  438. //----------------------------------------------------------------------------
  439. void
  440. cmLocalUnixMakefileGenerator3
  441. ::WriteMakeVariables(std::ostream& makefileStream)
  442. {
  443. this->WriteDivider(makefileStream);
  444. makefileStream
  445. << "# Set environment variables for the build.\n"
  446. << "\n";
  447. if(this->DefineWindowsNULL)
  448. {
  449. makefileStream
  450. << "!IF \"$(OS)\" == \"Windows_NT\"\n"
  451. << "NULL=\n"
  452. << "!ELSE\n"
  453. << "NULL=nul\n"
  454. << "!ENDIF\n";
  455. }
  456. if(this->WindowsShell)
  457. {
  458. makefileStream
  459. << "SHELL = cmd.exe\n"
  460. << "\n";
  461. }
  462. else
  463. {
  464. makefileStream
  465. << "# The shell in which to execute make rules.\n"
  466. << "SHELL = /bin/sh\n"
  467. << "\n";
  468. }
  469. std::string cmakecommand =
  470. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  471. makefileStream
  472. << "# The CMake executable.\n"
  473. << "CMAKE_COMMAND = "
  474. << this->Convert(cmakecommand.c_str(), FULL, SHELL).c_str()
  475. << "\n"
  476. << "\n";
  477. makefileStream
  478. << "# The command to remove a file.\n"
  479. << "RM = "
  480. << this->Convert(cmakecommand.c_str(),FULL,SHELL).c_str()
  481. << " -E remove -f\n"
  482. << "\n";
  483. if(this->Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
  484. {
  485. makefileStream
  486. << "# The program to use to edit the cache.\n"
  487. << "CMAKE_EDIT_COMMAND = "
  488. << (this->ConvertToOutputForExisting(
  489. this->Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))) << "\n"
  490. << "\n";
  491. }
  492. makefileStream
  493. << "# The top-level source directory on which CMake was run.\n"
  494. << "CMAKE_SOURCE_DIR = "
  495. << this->Convert(this->Makefile->GetHomeDirectory(), FULL, SHELL)
  496. << "\n"
  497. << "\n";
  498. makefileStream
  499. << "# The top-level build directory on which CMake was run.\n"
  500. << "CMAKE_BINARY_DIR = "
  501. << this->Convert(this->Makefile->GetHomeOutputDirectory(), FULL, SHELL)
  502. << "\n"
  503. << "\n";
  504. }
  505. //----------------------------------------------------------------------------
  506. void
  507. cmLocalUnixMakefileGenerator3
  508. ::WriteSpecialTargetsTop(std::ostream& makefileStream)
  509. {
  510. this->WriteDivider(makefileStream);
  511. makefileStream
  512. << "# Special targets provided by cmake.\n"
  513. << "\n";
  514. // Write special target to silence make output. This must be after
  515. // the default target in case VERBOSE is set (which changes the
  516. // name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
  517. // "VERBOSE=1" to be added as a make variable which will change the
  518. // name of this special target. This gives a make-time choice to
  519. // the user.
  520. std::vector<std::string> commands;
  521. std::vector<std::string> no_depends;
  522. commands.clear();
  523. if((this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")) || (this->ForceVerboseMakefiles))
  524. {
  525. makefileStream
  526. << "# Produce verbose output by default.\n"
  527. << "VERBOSE = 1\n"
  528. << "\n";
  529. }
  530. if(this->SilentNoColon)
  531. {
  532. makefileStream << "$(VERBOSE).SILENT\n";
  533. }
  534. else
  535. {
  536. this->WriteMakeRule(makefileStream,
  537. "Suppress display of executed commands.",
  538. "$(VERBOSE).SILENT",
  539. no_depends,
  540. commands, false);
  541. }
  542. // Special target to cleanup operation of make tool.
  543. std::vector<std::string> depends;
  544. this->WriteMakeRule(makefileStream,
  545. "Disable implicit rules so canoncical targets will work.",
  546. ".SUFFIXES",
  547. depends,
  548. commands, false);
  549. // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
  550. depends.push_back(".hpux_make_needs_suffix_list");
  551. this->WriteMakeRule(makefileStream, 0,
  552. ".SUFFIXES", depends, commands, false);
  553. }
  554. //----------------------------------------------------------------------------
  555. void
  556. cmLocalUnixMakefileGenerator3
  557. ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
  558. {
  559. this->WriteDivider(makefileStream);
  560. makefileStream
  561. << "# Special targets to cleanup operation of make.\n"
  562. << "\n";
  563. // Write special "cmake_check_build_system" target to run cmake with
  564. // the --check-build-system flag.
  565. {
  566. // Build command to run CMake to check if anything needs regenerating.
  567. std::string cmakefileName = "CMakeFiles/Makefile.cmake";
  568. std::string runRule =
  569. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  570. runRule += " --check-build-system ";
  571. runRule += this->Convert(cmakefileName.c_str(),NONE,SHELL);
  572. runRule += " 0";
  573. std::vector<std::string> no_depends;
  574. std::vector<std::string> commands;
  575. commands.push_back(runRule);
  576. if(this->Parent)
  577. {
  578. this->CreateCDCommand(commands,
  579. this->Makefile->GetHomeOutputDirectory(),
  580. this->Makefile->GetStartOutputDirectory());
  581. }
  582. this->WriteMakeRule(makefileStream,
  583. "Special rule to run CMake to check the build system "
  584. "integrity.\n"
  585. "No rule that depends on this can have "
  586. "commands that come from listfiles\n"
  587. "because they might be regenerated.",
  588. "cmake_check_build_system",
  589. no_depends,
  590. commands, true);
  591. }
  592. std::vector<std::string> no_commands;
  593. }
  594. //----------------------------------------------------------------------------
  595. void
  596. cmLocalUnixMakefileGenerator3
  597. ::WriteConvenienceRule(std::ostream& ruleFileStream,
  598. const char* realTarget,
  599. const char* helpTarget)
  600. {
  601. // A rule is only needed if the names are different.
  602. if(strcmp(realTarget, helpTarget) != 0)
  603. {
  604. // The helper target depends on the real target.
  605. std::vector<std::string> depends;
  606. depends.push_back(realTarget);
  607. // There are no commands.
  608. std::vector<std::string> no_commands;
  609. // Write the rule.
  610. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  611. helpTarget, depends, no_commands, true);
  612. }
  613. }
  614. //----------------------------------------------------------------------------
  615. std::string
  616. cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
  617. {
  618. std::string dir = this->HomeRelativeOutputPath;
  619. dir += this->GetTargetDirectory(target);
  620. return this->Convert(dir.c_str(),NONE,MAKEFILE);
  621. }
  622. //----------------------------------------------------------------------------
  623. void
  624. cmLocalUnixMakefileGenerator3
  625. ::AppendRuleDepend(std::vector<std::string>& depends,
  626. const char* ruleFileName)
  627. {
  628. // Add a dependency on the rule file itself unless an option to skip
  629. // it is specifically enabled by the user or project.
  630. const char* nodep = this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
  631. if(!nodep || cmSystemTools::IsOff(nodep))
  632. {
  633. depends.push_back(ruleFileName);
  634. }
  635. }
  636. //----------------------------------------------------------------------------
  637. void
  638. cmLocalUnixMakefileGenerator3
  639. ::AppendCustomDepends(std::vector<std::string>& depends,
  640. const std::vector<cmCustomCommand>& ccs)
  641. {
  642. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  643. i != ccs.end(); ++i)
  644. {
  645. this->AppendCustomDepend(depends, *i);
  646. }
  647. }
  648. //----------------------------------------------------------------------------
  649. void
  650. cmLocalUnixMakefileGenerator3
  651. ::AppendCustomDepend(std::vector<std::string>& depends,
  652. const cmCustomCommand& cc)
  653. {
  654. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  655. d != cc.GetDepends().end(); ++d)
  656. {
  657. // Lookup the real name of the dependency in case it is a CMake target.
  658. std::string dep = this->GetRealDependency(d->c_str(),
  659. this->ConfigurationName.c_str());
  660. depends.push_back(dep);
  661. }
  662. }
  663. //----------------------------------------------------------------------------
  664. void
  665. cmLocalUnixMakefileGenerator3
  666. ::AppendCustomCommands(std::vector<std::string>& commands,
  667. const std::vector<cmCustomCommand>& ccs)
  668. {
  669. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  670. i != ccs.end(); ++i)
  671. {
  672. this->AppendCustomCommand(commands, *i);
  673. }
  674. }
  675. //----------------------------------------------------------------------------
  676. void
  677. cmLocalUnixMakefileGenerator3
  678. ::AppendCustomCommand(std::vector<std::string>& commands,
  679. const cmCustomCommand& cc)
  680. {
  681. std::vector<std::string> commands1;
  682. // Add each command line to the set of commands.
  683. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
  684. cl != cc.GetCommandLines().end(); ++cl)
  685. {
  686. // Build the command line in a single string.
  687. const cmCustomCommandLine& commandLine = *cl;
  688. std::string cmd = commandLine[0];
  689. if (cmd.size())
  690. {
  691. cmSystemTools::ReplaceString(cmd, "/./", "/");
  692. cmd = this->Convert(cmd.c_str(),START_OUTPUT);
  693. if(cmd.find("/") == cmd.npos &&
  694. commandLine[0].find("/") != cmd.npos)
  695. {
  696. // Add a leading "./" for executables in the current directory.
  697. cmd = "./" + cmd;
  698. }
  699. cmd = this->Convert(cmd.c_str(),NONE,SHELL);
  700. for(unsigned int j=1; j < commandLine.size(); ++j)
  701. {
  702. cmd += " ";
  703. bool forceOn = cmSystemTools::GetForceUnixPaths();
  704. if(forceOn && this->WindowsShell)
  705. {
  706. cmSystemTools::SetForceUnixPaths(false);
  707. }
  708. cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
  709. if(forceOn && this->WindowsShell)
  710. {
  711. cmSystemTools::SetForceUnixPaths(true);
  712. }
  713. }
  714. commands1.push_back(cmd);
  715. }
  716. }
  717. // push back the custom commands
  718. const char* dir = this->Makefile->GetStartOutputDirectory();
  719. // if the command specified a working directory use it.
  720. if(cc.GetWorkingDirectory())
  721. {
  722. dir = cc.GetWorkingDirectory();
  723. }
  724. this->CreateCDCommand(commands1, dir,
  725. this->Makefile->GetHomeOutputDirectory());
  726. commands.insert(commands.end(), commands1.begin(), commands1.end());
  727. }
  728. //----------------------------------------------------------------------------
  729. void
  730. cmLocalUnixMakefileGenerator3
  731. ::AppendCleanCommand(std::vector<std::string>& commands,
  732. const std::vector<std::string>& files,
  733. cmTarget& target, const char* filename)
  734. {
  735. if(!files.empty())
  736. {
  737. std::string cleanfile = this->Makefile->GetCurrentOutputDirectory();
  738. cleanfile += "/";
  739. cleanfile += this->GetTargetDirectory(target);
  740. cleanfile += "/cmake_clean";
  741. if(filename)
  742. {
  743. cleanfile += "_";
  744. cleanfile += filename;
  745. }
  746. cleanfile += ".cmake";
  747. std::string cleanfilePath = this->Convert(cleanfile.c_str(), FULL);
  748. std::ofstream fout(cleanfilePath.c_str());
  749. if(!fout)
  750. {
  751. cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
  752. }
  753. fout << "FILE(REMOVE\n";
  754. std::string remove = "$(CMAKE_COMMAND) -P ";
  755. remove += this->Convert(cleanfile.c_str(), START_OUTPUT, SHELL);
  756. for(std::vector<std::string>::const_iterator f = files.begin();
  757. f != files.end(); ++f)
  758. {
  759. fout << "\"" << this->Convert(f->c_str(),START_OUTPUT,UNCHANGED)
  760. << "\"\n";
  761. }
  762. fout << ")\n";
  763. commands.push_back(remove);
  764. }
  765. }
  766. //----------------------------------------------------------------------------
  767. void
  768. cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
  769. const char* text,
  770. EchoColor color)
  771. {
  772. // Choose the color for the text.
  773. std::string color_name;
  774. #ifdef CMAKE_BUILD_WITH_CMAKE
  775. if(this->GlobalGenerator->GetToolSupportsColor() &&
  776. this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE"))
  777. {
  778. // See cmake::ExecuteEchoColor in cmake.cxx for these options.
  779. // This color set is readable on both black and white backgrounds.
  780. switch(color)
  781. {
  782. case EchoNormal:
  783. break;
  784. case EchoDepend:
  785. color_name = "--magenta --bold ";
  786. break;
  787. case EchoBuild:
  788. color_name = "--green ";
  789. break;
  790. case EchoLink:
  791. color_name = "--red --bold ";
  792. break;
  793. case EchoGenerate:
  794. color_name = "--blue --bold ";
  795. break;
  796. case EchoGlobal:
  797. color_name = "--cyan ";
  798. break;
  799. }
  800. }
  801. #endif
  802. // Echo one line at a time.
  803. std::string line;
  804. line.reserve(200);
  805. for(const char* c = text;; ++c)
  806. {
  807. if(*c == '\n' || *c == '\0')
  808. {
  809. // Avoid writing a blank last line on end-of-string.
  810. if(*c != '\0' || !line.empty())
  811. {
  812. // Add a command to echo this line.
  813. std::string cmd;
  814. if(color_name.empty())
  815. {
  816. // Use the native echo command.
  817. cmd = "@echo ";
  818. if(this->EchoNeedsQuote)
  819. {
  820. cmd += "\"";
  821. }
  822. cmd += line;
  823. if(this->EchoNeedsQuote)
  824. {
  825. cmd += "\"";
  826. }
  827. }
  828. else
  829. {
  830. // Use cmake to echo the text in color.
  831. cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
  832. cmd += color_name;
  833. cmd += "\"";
  834. cmd += line;
  835. cmd += "\"";
  836. }
  837. commands.push_back(cmd);
  838. }
  839. // Reset the line to emtpy.
  840. line = "";
  841. // Terminate on end-of-string.
  842. if(*c == '\0')
  843. {
  844. return;
  845. }
  846. }
  847. else if(*c != '\r')
  848. {
  849. // Append this character to the current line.
  850. line += *c;
  851. }
  852. }
  853. }
  854. //----------------------------------------------------------------------------
  855. // take a tgt path and convert it into a make target, it could be full, or relative
  856. std::string
  857. cmLocalUnixMakefileGenerator3
  858. ::ConvertToMakeTarget(const char* tgt)
  859. {
  860. // Make targets should not have a leading './' for a file in the
  861. // directory containing the makefile.
  862. std::string ret = tgt;
  863. if(ret.size() > 2 && (ret[0] == '.') &&
  864. ( (ret[1] == '/') || ret[1] == '\\'))
  865. {
  866. std::string upath = ret;
  867. cmSystemTools::ConvertToUnixSlashes(upath);
  868. if(upath.find(2, '/') == upath.npos)
  869. {
  870. ret = ret.substr(2, ret.size()-2);
  871. }
  872. }
  873. return ret;
  874. }
  875. //----------------------------------------------------------------------------
  876. std::string&
  877. cmLocalUnixMakefileGenerator3::CreateSafeUniqueObjectFileName(const char* sin)
  878. {
  879. // Look for an existing mapped name for this object file.
  880. std::map<cmStdString,cmStdString>::iterator it =
  881. this->UniqueObjectNamesMap.find(sin);
  882. // If no entry exists create one.
  883. if(it == this->UniqueObjectNamesMap.end())
  884. {
  885. // Start with the original name.
  886. std::string ssin = sin;
  887. // Avoid full paths by removing leading slashes.
  888. std::string::size_type pos = 0;
  889. for(;pos < ssin.size() && ssin[pos] == '/'; ++pos);
  890. ssin = ssin.substr(pos);
  891. // Avoid full paths by removing colons.
  892. cmSystemTools::ReplaceString(ssin, ":", "_");
  893. // Avoid relative paths that go up the tree.
  894. cmSystemTools::ReplaceString(ssin, "../", "__/");
  895. // Avoid spaces.
  896. cmSystemTools::ReplaceString(ssin, " ", "_");
  897. // Mangle the name if necessary.
  898. if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
  899. {
  900. bool done;
  901. int cc = 0;
  902. char rpstr[100];
  903. sprintf(rpstr, "_p_");
  904. cmSystemTools::ReplaceString(ssin, "+", rpstr);
  905. std::string sssin = sin;
  906. do
  907. {
  908. done = true;
  909. for ( it = this->UniqueObjectNamesMap.begin();
  910. it != this->UniqueObjectNamesMap.end();
  911. ++ it )
  912. {
  913. if ( it->second == ssin )
  914. {
  915. done = false;
  916. }
  917. }
  918. if ( done )
  919. {
  920. break;
  921. }
  922. sssin = ssin;
  923. cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
  924. sprintf(rpstr, "_p%d_", cc++);
  925. }
  926. while ( !done );
  927. }
  928. // Insert the newly mapped object file name.
  929. std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
  930. it = this->UniqueObjectNamesMap.insert(e).first;
  931. }
  932. // Return the map entry.
  933. return it->second;
  934. }
  935. //----------------------------------------------------------------------------
  936. std::string
  937. cmLocalUnixMakefileGenerator3
  938. ::CreateMakeVariable(const char* sin, const char* s2in)
  939. {
  940. std::string s = sin;
  941. std::string s2 = s2in;
  942. std::string unmodified = s;
  943. unmodified += s2;
  944. // if there is no restriction on the length of make variables
  945. // and there are no "." charactors in the string, then return the
  946. // unmodified combination.
  947. if((!this->MakefileVariableSize && unmodified.find('.') == s.npos)
  948. && (!this->MakefileVariableSize && unmodified.find('-') == s.npos))
  949. {
  950. return unmodified;
  951. }
  952. // see if the variable has been defined before and return
  953. // the modified version of the variable
  954. std::map<cmStdString, cmStdString>::iterator i = this->MakeVariableMap.find(unmodified);
  955. if(i != this->MakeVariableMap.end())
  956. {
  957. return i->second;
  958. }
  959. // start with the unmodified variable
  960. std::string ret = unmodified;
  961. // if this there is no value for this->MakefileVariableSize then
  962. // the string must have bad characters in it
  963. if(!this->MakefileVariableSize)
  964. {
  965. cmSystemTools::ReplaceString(ret, ".", "_");
  966. cmSystemTools::ReplaceString(ret, "-", "__");
  967. int ni = 0;
  968. char buffer[5];
  969. // make sure the _ version is not already used, if
  970. // it is used then add number to the end of the variable
  971. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  972. {
  973. ++ni;
  974. sprintf(buffer, "%04d", ni);
  975. ret = unmodified + buffer;
  976. }
  977. this->ShortMakeVariableMap[ret] = "1";
  978. this->MakeVariableMap[unmodified] = ret;
  979. return ret;
  980. }
  981. // if the string is greater the 32 chars it is an invalid vairable name
  982. // for borland make
  983. if(static_cast<int>(ret.size()) > this->MakefileVariableSize)
  984. {
  985. int keep = this->MakefileVariableSize - 8;
  986. int size = keep + 3;
  987. std::string str1 = s;
  988. std::string str2 = s2;
  989. // we must shorten the combined string by 4 charactors
  990. // keep no more than 24 charactors from the second string
  991. if(static_cast<int>(str2.size()) > keep)
  992. {
  993. str2 = str2.substr(0, keep);
  994. }
  995. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  996. {
  997. str1 = str1.substr(0, size - str2.size());
  998. }
  999. char buffer[5];
  1000. int ni = 0;
  1001. sprintf(buffer, "%04d", ni);
  1002. ret = str1 + str2 + buffer;
  1003. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  1004. {
  1005. ++ni;
  1006. sprintf(buffer, "%04d", ni);
  1007. ret = str1 + str2 + buffer;
  1008. }
  1009. if(ni == 1000)
  1010. {
  1011. cmSystemTools::Error("Borland makefile variable length too long");
  1012. return unmodified;
  1013. }
  1014. // once an unused variable is found
  1015. this->ShortMakeVariableMap[ret] = "1";
  1016. }
  1017. // always make an entry into the unmodified to variable map
  1018. this->MakeVariableMap[unmodified] = ret;
  1019. return ret;
  1020. }
  1021. //----------------------------------------------------------------------------
  1022. bool
  1023. cmLocalUnixMakefileGenerator3
  1024. ::ScanDependencies(std::vector<std::string> const& args)
  1025. {
  1026. // Format of arguments is:
  1027. // $(CMAKE_COMMAND), cmake_depends, GeneratorName, home_output_dir, start_output_dir, info file
  1028. // The caller has ensured that all required arguments exist.
  1029. // The info file for this target
  1030. std::string const& infoFile = args[5];
  1031. // Read the directory information file.
  1032. cmake cm;
  1033. cmGlobalGenerator gg;
  1034. gg.SetCMakeInstance(&cm);
  1035. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1036. lg->SetGlobalGenerator(&gg);
  1037. cmMakefile* mf = lg->GetMakefile();
  1038. mf->SetHomeOutputDirectory(args[3].c_str());
  1039. mf->SetStartOutputDirectory(args[4].c_str());
  1040. lg->SetupPathConversions();
  1041. bool haveDirectoryInfo = false;
  1042. std::string dirInfoFile = args[4];
  1043. dirInfoFile += "/CMakeFiles/CMakeDirectoryInformation.cmake";
  1044. if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
  1045. !cmSystemTools::GetErrorOccuredFlag())
  1046. {
  1047. haveDirectoryInfo = true;
  1048. }
  1049. // read in the target info file
  1050. if(!mf->ReadListFile(0, infoFile.c_str()) ||
  1051. cmSystemTools::GetErrorOccuredFlag())
  1052. {
  1053. cmSystemTools::Error("Target DependInfo.cmake file not found");
  1054. }
  1055. // Test whether we need to force Unix paths.
  1056. if(haveDirectoryInfo)
  1057. {
  1058. if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
  1059. {
  1060. if(!cmSystemTools::IsOff(force))
  1061. {
  1062. cmSystemTools::SetForceUnixPaths(true);
  1063. }
  1064. }
  1065. }
  1066. else
  1067. {
  1068. cmSystemTools::Error("Directory Information file not found");
  1069. }
  1070. // create the file stream for the depends file
  1071. std::string dir = cmSystemTools::GetFilenamePath(infoFile);
  1072. // Open the rule file. This should be copy-if-different because the
  1073. // rules may depend on this file itself.
  1074. std::string ruleFileNameFull = dir;
  1075. ruleFileNameFull += "/depend.make";
  1076. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  1077. ruleFileStream.SetCopyIfDifferent(true);
  1078. if(!ruleFileStream)
  1079. {
  1080. return false;
  1081. }
  1082. std::string internalRuleFileNameFull = dir;
  1083. internalRuleFileNameFull += "/depend.internal";
  1084. cmGeneratedFileStream internalRuleFileStream(internalRuleFileNameFull.c_str());
  1085. internalRuleFileStream.SetCopyIfDifferent(true);
  1086. if(!internalRuleFileStream)
  1087. {
  1088. return false;
  1089. }
  1090. this->WriteDisclaimer(ruleFileStream);
  1091. this->WriteDisclaimer(internalRuleFileStream);
  1092. // Get the set of generated files.
  1093. std::vector<std::string> generatedFilesVec;
  1094. if(haveDirectoryInfo)
  1095. {
  1096. if(const char* generated = mf->GetDefinition("CMAKE_GENERATED_FILES"))
  1097. {
  1098. cmSystemTools::ExpandListArgument(generated, generatedFilesVec);
  1099. }
  1100. }
  1101. // Sort for efficient lookup.
  1102. std::set<cmStdString> generatedFiles;
  1103. for(std::vector<std::string>::iterator gfi = generatedFilesVec.begin();
  1104. gfi != generatedFilesVec.end(); ++gfi)
  1105. {
  1106. generatedFiles.insert(*gfi);
  1107. }
  1108. // for each language we need to scan, scan it
  1109. const char *langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
  1110. std::vector<std::string> langs;
  1111. cmSystemTools::ExpandListArgument(langStr, langs);
  1112. for (std::vector<std::string>::iterator li =
  1113. langs.begin(); li != langs.end(); ++li)
  1114. {
  1115. // construct the checker
  1116. std::string lang = li->c_str();
  1117. // Get the set of include directories.
  1118. std::vector<std::string> includes;
  1119. if(haveDirectoryInfo)
  1120. {
  1121. std::string includePathVar = "CMAKE_";
  1122. includePathVar += lang;
  1123. includePathVar += "_INCLUDE_PATH";
  1124. if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
  1125. {
  1126. cmSystemTools::ExpandListArgument(includePath, includes);
  1127. }
  1128. }
  1129. // Get the include file regular expression.
  1130. std::string includeRegexScan = "^.*$";
  1131. std::string includeRegexComplain = "^$";
  1132. if(haveDirectoryInfo)
  1133. {
  1134. std::string scanRegexVar = "CMAKE_";
  1135. scanRegexVar += lang;
  1136. scanRegexVar += "_INCLUDE_REGEX_SCAN";
  1137. if(const char* scanRegex = mf->GetDefinition(scanRegexVar.c_str()))
  1138. {
  1139. includeRegexScan = scanRegex;
  1140. }
  1141. std::string complainRegexVar = "CMAKE_";
  1142. complainRegexVar += lang;
  1143. complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
  1144. if(const char* complainRegex = mf->GetDefinition(complainRegexVar.c_str()))
  1145. {
  1146. includeRegexComplain = complainRegex;
  1147. }
  1148. }
  1149. // Create the scanner for this language
  1150. cmDepends *scanner = 0;
  1151. if(lang == "C" || lang == "CXX" || lang == "RC")
  1152. {
  1153. std::string includeCacheFileName = dir;
  1154. includeCacheFileName += "/includecache.";
  1155. includeCacheFileName += lang;
  1156. // TODO: Handle RC (resource files) dependencies correctly.
  1157. scanner = new cmDependsC(includes,
  1158. includeRegexScan.c_str(),
  1159. includeRegexComplain.c_str(),
  1160. generatedFiles, includeCacheFileName);
  1161. }
  1162. #ifdef CMAKE_BUILD_WITH_CMAKE
  1163. else if(lang == "Fortran")
  1164. {
  1165. scanner = new cmDependsFortran(includes);
  1166. }
  1167. else if(lang == "Java")
  1168. {
  1169. scanner = new cmDependsJava();
  1170. }
  1171. #endif
  1172. if (scanner)
  1173. {
  1174. scanner->SetFileComparison(this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1175. // for each file we need to scan
  1176. std::string srcLang = "CMAKE_DEPENDS_CHECK_";
  1177. srcLang += lang;
  1178. const char *srcStr = mf->GetSafeDefinition(srcLang.c_str());
  1179. std::vector<std::string> srcs;
  1180. cmSystemTools::ExpandListArgument(srcStr, srcs);
  1181. for (std::vector<std::string>::iterator si =
  1182. srcs.begin(); si != srcs.end(); ++si)
  1183. {
  1184. std::string &src = *si;
  1185. ++si;
  1186. // make sure the object file is relative to home output
  1187. std::string obj = *si;
  1188. obj = lg->Convert(obj.c_str(),HOME_OUTPUT,MAKEFILE);
  1189. scanner->Write(src.c_str(),obj.c_str(),ruleFileStream, internalRuleFileStream);
  1190. }
  1191. // free the scanner for this language
  1192. delete scanner;
  1193. }
  1194. }
  1195. // dependencies were generated, so touch the mark file
  1196. ruleFileNameFull += ".mark";
  1197. std::ofstream fmark(ruleFileNameFull.c_str());
  1198. fmark << "Dependencies updated>" << std::endl;
  1199. return true;
  1200. }
  1201. //----------------------------------------------------------------------------
  1202. void cmLocalUnixMakefileGenerator3
  1203. ::WriteLocalAllRules(std::ostream& ruleFileStream)
  1204. {
  1205. this->WriteDisclaimer(ruleFileStream);
  1206. this->WriteMakeVariables(ruleFileStream);
  1207. // Write the main entry point target. This must be the VERY first
  1208. // target so that make with no arguments will run it.
  1209. {
  1210. // Just depend on the all target to drive the build.
  1211. std::vector<std::string> depends;
  1212. std::vector<std::string> no_commands;
  1213. depends.push_back("all");
  1214. // Write the rule.
  1215. this->WriteMakeRule(ruleFileStream,
  1216. "Default target executed when no arguments are "
  1217. "given to make.",
  1218. "default_target",
  1219. depends,
  1220. no_commands, true);
  1221. }
  1222. // Write all global targets
  1223. cmTargets* targets = &(this->Makefile->GetTargets());
  1224. cmTargets::iterator glIt;
  1225. for ( glIt = targets->begin(); glIt != targets->end(); ++ glIt )
  1226. {
  1227. if ( glIt->second.GetType() == cmTarget::GLOBAL_TARGET )
  1228. {
  1229. std::string targetString = "Special rule for the target " + glIt->first;
  1230. std::vector<std::string> commands;
  1231. std::vector<std::string> depends;
  1232. const char* text = glIt->second.GetProperty("EchoString");
  1233. if ( !text )
  1234. {
  1235. text = "Running external command ...";
  1236. }
  1237. std::set<cmStdString>::const_iterator dit;
  1238. for ( dit = glIt->second.GetUtilities().begin();
  1239. dit != glIt->second.GetUtilities().end();
  1240. ++ dit )
  1241. {
  1242. depends.push_back(dit->c_str());
  1243. }
  1244. this->AppendEcho(commands, text,
  1245. cmLocalUnixMakefileGenerator3::EchoGlobal);
  1246. // Utility targets store their rules in pre- and post-build commands.
  1247. this->AppendCustomDepends(depends,
  1248. glIt->second.GetPreBuildCommands());
  1249. this->AppendCustomDepends(depends,
  1250. glIt->second.GetPostBuildCommands());
  1251. this->AppendCustomCommands(commands,
  1252. glIt->second.GetPreBuildCommands());
  1253. this->AppendCustomCommands(commands,
  1254. glIt->second.GetPostBuildCommands());
  1255. this->WriteMakeRule(ruleFileStream, targetString.c_str(),
  1256. glIt->first.c_str(), depends, commands, true);
  1257. }
  1258. }
  1259. this->WriteSpecialTargetsTop(ruleFileStream);
  1260. std::vector<std::string> depends;
  1261. std::vector<std::string> commands;
  1262. // Write the all rule.
  1263. std::string dir = this->Makefile->GetStartOutputDirectory();
  1264. dir += "/all";
  1265. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1266. depends.push_back("cmake_check_build_system");
  1267. commands.push_back
  1268. (this->GetRecursiveMakeCall("CMakeFiles/Makefile2",dir.c_str()));
  1269. this->CreateCDCommand(commands,
  1270. this->Makefile->GetHomeOutputDirectory(),
  1271. this->Makefile->GetStartOutputDirectory());
  1272. this->WriteMakeRule(ruleFileStream, "The main all target", "all",
  1273. depends, commands, true);
  1274. // Write the clean rule.
  1275. dir = this->Makefile->GetStartOutputDirectory();
  1276. dir += "/clean";
  1277. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1278. commands.clear();
  1279. depends.clear();
  1280. commands.push_back
  1281. (this->GetRecursiveMakeCall("CMakeFiles/Makefile2",dir.c_str()));
  1282. this->CreateCDCommand(commands,
  1283. this->Makefile->GetHomeOutputDirectory(),
  1284. this->Makefile->GetStartOutputDirectory());
  1285. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
  1286. depends, commands, true);
  1287. commands.clear();
  1288. depends.clear();
  1289. depends.push_back("clean");
  1290. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
  1291. depends, commands, true);
  1292. // Write the preinstall rule.
  1293. dir = this->Makefile->GetStartOutputDirectory();
  1294. dir += "/preinstall";
  1295. dir = this->Convert(dir.c_str(), HOME_OUTPUT,MAKEFILE);
  1296. commands.clear();
  1297. depends.clear();
  1298. const char* noall =
  1299. this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  1300. if(!noall || cmSystemTools::IsOff(noall))
  1301. {
  1302. // Drive the build before installing.
  1303. depends.push_back("all");
  1304. }
  1305. else
  1306. {
  1307. // At least make sure the build system is up to date.
  1308. depends.push_back("cmake_check_build_system");
  1309. }
  1310. commands.push_back
  1311. (this->GetRecursiveMakeCall("CMakeFiles/Makefile2", dir.c_str()));
  1312. this->CreateCDCommand(commands,
  1313. this->Makefile->GetHomeOutputDirectory(),
  1314. this->Makefile->GetStartOutputDirectory());
  1315. this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
  1316. "preinstall", depends, commands, true);
  1317. // write the depend rule, really a recompute depends rule
  1318. depends.clear();
  1319. commands.clear();
  1320. std::string cmakefileName = "CMakeFiles/Makefile.cmake";
  1321. this->Convert(cmakefileName.c_str(),HOME_OUTPUT,
  1322. cmLocalGenerator::MAKEFILE);
  1323. std::string runRule =
  1324. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  1325. runRule += " --check-build-system ";
  1326. runRule += this->Convert(cmakefileName.c_str(),cmLocalGenerator::NONE,
  1327. cmLocalGenerator::SHELL);
  1328. runRule += " 1";
  1329. commands.push_back(runRule);
  1330. this->WriteMakeRule(ruleFileStream, "clear depends",
  1331. "depend",
  1332. depends, commands, true);
  1333. }
  1334. //----------------------------------------------------------------------------
  1335. void cmLocalUnixMakefileGenerator3::CheckDependencies(cmMakefile* mf,
  1336. bool verbose,
  1337. bool clear)
  1338. {
  1339. // Get the list of target files to check
  1340. const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
  1341. if(!infoDef)
  1342. {
  1343. return;
  1344. }
  1345. std::vector<std::string> files;
  1346. cmSystemTools::ExpandListArgument(infoDef, files);
  1347. // For each info file run the check
  1348. cmDependsC checker;
  1349. checker.SetVerbose(verbose);
  1350. checker.SetFileComparison(this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1351. for(std::vector<std::string>::iterator l = files.begin();
  1352. l != files.end(); ++l)
  1353. {
  1354. // either clear or check the files
  1355. std::string dir = cmSystemTools::GetFilenamePath(l->c_str());
  1356. std::string internalDependFile = dir + "/depend.internal";
  1357. std::string dependFile = dir + "/depend.make";
  1358. if (clear)
  1359. {
  1360. checker.Clear(internalDependFile.c_str());
  1361. checker.Clear(dependFile.c_str());
  1362. }
  1363. else
  1364. {
  1365. checker.Check(dependFile.c_str(), internalDependFile.c_str());
  1366. }
  1367. }
  1368. }
  1369. void cmLocalUnixMakefileGenerator3
  1370. ::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
  1371. {
  1372. // now write all the language stuff
  1373. // Set the set of files to check for dependency integrity.
  1374. std::set<cmStdString> checkSetLangs;
  1375. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  1376. checkSet = this->GetIntegrityCheckSet()[target.GetName()];
  1377. for(std::map<cmStdString,
  1378. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  1379. l = checkSet.begin(); l != checkSet.end(); ++l)
  1380. {
  1381. checkSetLangs.insert(l->first);
  1382. }
  1383. // list the languages
  1384. cmakefileStream
  1385. << "# The set of files whose dependency integrity should be checked:\n";
  1386. cmakefileStream
  1387. << "SET(CMAKE_DEPENDS_LANGUAGES\n";
  1388. for(std::set<cmStdString>::iterator
  1389. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1390. {
  1391. cmakefileStream << " \"" << l->c_str() << "\"\n";
  1392. }
  1393. cmakefileStream << " )\n";
  1394. // now list the files for each language
  1395. for(std::set<cmStdString>::iterator
  1396. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1397. {
  1398. cmakefileStream
  1399. << "SET(CMAKE_DEPENDS_CHECK_" << l->c_str() << "\n";
  1400. // get the check set for this local gen and language
  1401. cmLocalUnixMakefileGenerator3::IntegrityCheckSet iCheckSet =
  1402. checkSet[*l];
  1403. // for each file
  1404. for(cmLocalUnixMakefileGenerator3::IntegrityCheckSet::const_iterator
  1405. csIter = iCheckSet.begin();
  1406. csIter != iCheckSet.end(); ++csIter)
  1407. {
  1408. cmakefileStream << " \"" << (*csIter)->GetFullPath() << "\"\n";
  1409. // Get the full path name of the object file.
  1410. std::string obj = this->Makefile->GetStartOutputDirectory();
  1411. obj += "/";
  1412. obj += this->GetObjectFileName(target, **csIter);
  1413. cmakefileStream << " \"" <<
  1414. this->Convert(obj.c_str(),
  1415. cmLocalGenerator::FULL).c_str() << "\"\n";
  1416. }
  1417. cmakefileStream << " )\n";
  1418. }
  1419. }
  1420. //----------------------------------------------------------------------------
  1421. std::string
  1422. cmLocalUnixMakefileGenerator3
  1423. ::GetObjectFileName(cmTarget& target,
  1424. const cmSourceFile& source,
  1425. std::string* nameWithoutTargetDir)
  1426. {
  1427. // If the source file is located below the current binary directory
  1428. // then use that relative path for the object file name.
  1429. std::string objectName = this->Convert(source.GetFullPath().c_str(),
  1430. START_OUTPUT);
  1431. if(cmSystemTools::FileIsFullPath(objectName.c_str()) ||
  1432. objectName.empty() || objectName[0] == '.')
  1433. {
  1434. // If the source file is located below the current source
  1435. // directory then use that relative path for the object file name.
  1436. // Otherwise just use the relative path from the current binary
  1437. // directory.
  1438. std::string relFromSource = this->Convert(source.GetFullPath().c_str(),
  1439. START);
  1440. if(!cmSystemTools::FileIsFullPath(relFromSource.c_str()) &&
  1441. !relFromSource.empty() && relFromSource[0] != '.')
  1442. {
  1443. objectName = relFromSource;
  1444. }
  1445. }
  1446. // Replace the original source file extension with the object file
  1447. // extension.
  1448. std::string::size_type dot_pos = objectName.rfind(".");
  1449. if(dot_pos != std::string::npos)
  1450. {
  1451. objectName = objectName.substr(0, dot_pos);
  1452. }
  1453. if ( source.GetPropertyAsBool("KEEP_EXTENSION") )
  1454. {
  1455. if ( !source.GetSourceExtension().empty() )
  1456. {
  1457. objectName += "." + source.GetSourceExtension();
  1458. }
  1459. }
  1460. else
  1461. {
  1462. objectName +=
  1463. this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
  1464. source.GetSourceExtension().c_str());
  1465. }
  1466. // Convert to a safe name.
  1467. objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
  1468. // Prepend the target directory.
  1469. std::string obj;
  1470. const char* fileTargetDirectory = source.GetProperty("MACOSX_PACKAGE_LOCATION");
  1471. if ( fileTargetDirectory )
  1472. {
  1473. std::string targetName;
  1474. std::string targetNameReal;
  1475. target.GetExecutableNames(targetName, targetNameReal,
  1476. this->ConfigurationName.c_str());
  1477. if ( target.GetPropertyAsBool("MACOSX_BUNDLE") )
  1478. {
  1479. // Construct the full path version of the names.
  1480. obj = this->ExecutableOutputPath;
  1481. if(obj.empty())
  1482. {
  1483. obj = this->Makefile->GetStartOutputDirectory();
  1484. obj += "/";
  1485. }
  1486. obj += targetName + ".app/Contents/";
  1487. obj += fileTargetDirectory;
  1488. }
  1489. else
  1490. {
  1491. // Framework not handled yet
  1492. abort();
  1493. }
  1494. obj = cmSystemTools::RelativePath(this->Makefile->GetHomeOutputDirectory(), obj.c_str());
  1495. }
  1496. else
  1497. {
  1498. obj = this->GetTargetDirectory(target);
  1499. }
  1500. obj += "/";
  1501. obj += objectName;
  1502. if(nameWithoutTargetDir)
  1503. {
  1504. *nameWithoutTargetDir = objectName;
  1505. }
  1506. return obj;
  1507. }
  1508. //----------------------------------------------------------------------------
  1509. void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
  1510. {
  1511. os
  1512. << "# CMAKE generated file: DO NOT EDIT!\n"
  1513. << "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
  1514. << " Generator, CMake Version "
  1515. << cmMakefile::GetMajorVersion() << "."
  1516. << cmMakefile::GetMinorVersion() << "\n\n";
  1517. }
  1518. //----------------------------------------------------------------------------
  1519. std::string
  1520. cmLocalUnixMakefileGenerator3
  1521. ::GetRecursiveMakeCall(const char *makefile, const char* tgt)
  1522. {
  1523. // Call make on the given file.
  1524. std::string cmd;
  1525. cmd += "$(MAKE) -f ";
  1526. cmd += makefile;
  1527. cmd += " ";
  1528. // Passg down verbosity level.
  1529. if(this->GetMakeSilentFlag().size())
  1530. {
  1531. cmd += this->GetMakeSilentFlag();
  1532. cmd += " ";
  1533. }
  1534. // Most unix makes will pass the command line flags to make down to
  1535. // sub-invoked makes via an environment variable. However, some
  1536. // makes do not support that, so you have to pass the flags
  1537. // explicitly.
  1538. if(this->GetPassMakeflags())
  1539. {
  1540. cmd += "-$(MAKEFLAGS) ";
  1541. }
  1542. // Add the target.
  1543. if (tgt && tgt[0] != '\0')
  1544. {
  1545. std::string tgt2 = this->Convert(tgt,HOME_OUTPUT,MAKEFILE);
  1546. tgt2 = this->ConvertToMakeTarget(tgt2.c_str());
  1547. cmd += tgt2;
  1548. }
  1549. return cmd;
  1550. }
  1551. //----------------------------------------------------------------------------
  1552. void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
  1553. {
  1554. os
  1555. << "#======================================"
  1556. << "=======================================\n";
  1557. }
  1558. //----------------------------------------------------------------------------
  1559. void
  1560. cmLocalUnixMakefileGenerator3
  1561. ::WriteCMakeArgument(std::ostream& os, const char* s)
  1562. {
  1563. // Write the given string to the stream with escaping to get it back
  1564. // into CMake through the lexical scanner.
  1565. os << "\"";
  1566. for(const char* c = s; *c; ++c)
  1567. {
  1568. if(*c == '\\')
  1569. {
  1570. os << "\\\\";
  1571. }
  1572. else if(*c == '"')
  1573. {
  1574. os << "\\\"";
  1575. }
  1576. else
  1577. {
  1578. os << *c;
  1579. }
  1580. }
  1581. os << "\"";
  1582. }
  1583. //----------------------------------------------------------------------------
  1584. std::string
  1585. cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
  1586. {
  1587. // Split the path into its components.
  1588. std::vector<std::string> components;
  1589. cmSystemTools::SplitPath(p, components);
  1590. // Return an empty path if there are no components.
  1591. if(components.empty())
  1592. {
  1593. return "\"\"";
  1594. }
  1595. // Choose a slash direction and fix root component.
  1596. const char* slash = "/";
  1597. #if defined(_WIN32) && !defined(__CYGWIN__)
  1598. if(!cmSystemTools::GetForceUnixPaths())
  1599. {
  1600. slash = "\\";
  1601. for(std::string::iterator i = components[0].begin();
  1602. i != components[0].end(); ++i)
  1603. {
  1604. if(*i == '/')
  1605. {
  1606. *i = '\\';
  1607. }
  1608. }
  1609. }
  1610. #endif
  1611. // Begin the quoted result with the root component.
  1612. std::string result = "\"";
  1613. result += components[0];
  1614. // Now add the rest of the components separated by the proper slash
  1615. // direction for this platform.
  1616. bool first = true;
  1617. for(unsigned int i=1; i < components.size(); ++i)
  1618. {
  1619. // Only the last component can be empty to avoid double slashes.
  1620. if(components[i].length() > 0 || (i == (components.size()-1)))
  1621. {
  1622. if(!first)
  1623. {
  1624. result += slash;
  1625. }
  1626. result += components[i];
  1627. first = false;
  1628. }
  1629. }
  1630. // Close the quoted result.
  1631. result += "\"";
  1632. return result;
  1633. }
  1634. //----------------------------------------------------------------------------
  1635. std::string
  1636. cmLocalUnixMakefileGenerator3::GetTargetDirectory(cmTarget& target)
  1637. {
  1638. std::string dir = "CMakeFiles/";
  1639. dir += target.GetName();
  1640. dir += ".dir";
  1641. return dir;
  1642. }
  1643. void cmLocalUnixMakefileGenerator3
  1644. ::CreateCDCommand(std::vector<std::string>& commands, const char *tgtDir,
  1645. const char *retDir)
  1646. {
  1647. // do we need to cd?
  1648. if (!strcmp(tgtDir,retDir))
  1649. {
  1650. return;
  1651. }
  1652. if(!this->UnixCD)
  1653. {
  1654. // On Windows we must perform each step separately and then change
  1655. // back because the shell keeps the working directory between
  1656. // commands.
  1657. std::string cmd = "cd ";
  1658. cmd += this->ConvertToOutputForExisting(tgtDir);
  1659. commands.insert(commands.begin(),cmd);
  1660. // Change back to the starting directory. Any trailing slash must be
  1661. // removed to avoid problems with Borland Make.
  1662. std::string back = retDir;
  1663. if(back.size() && back[back.size()-1] == '/')
  1664. {
  1665. back = back.substr(0, back.size()-1);
  1666. }
  1667. cmd = "cd ";
  1668. cmd += this->ConvertToOutputForExisting(back.c_str());
  1669. commands.push_back(cmd);
  1670. }
  1671. else
  1672. {
  1673. // On UNIX we must construct a single shell command to change
  1674. // directory and build because make resets the directory between
  1675. // each command.
  1676. std::vector<std::string>::iterator i = commands.begin();
  1677. for (; i != commands.end(); ++i)
  1678. {
  1679. std::string cmd = "cd ";
  1680. cmd += this->ConvertToOutputForExisting(tgtDir);
  1681. cmd += " && ";
  1682. cmd += *i;
  1683. *i = cmd;
  1684. }
  1685. }
  1686. }
  1687. //----------------------------------------------------------------------------
  1688. const char*
  1689. cmLocalUnixMakefileGenerator3
  1690. ::GetSourceFileLanguage(const cmSourceFile& source)
  1691. {
  1692. const char* lang = source.GetProperty("LANGUAGE");
  1693. if ( lang )
  1694. {
  1695. return lang;
  1696. }
  1697. // Identify the language of the source file.
  1698. return (this->GlobalGenerator
  1699. ->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
  1700. }