cmLocalUnixMakefileGenerator3.cxx 59 KB

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