cmLocalUnixMakefileGenerator3.cxx 60 KB

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