cmLocalUnixMakefileGenerator3.cxx 58 KB

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