cmLocalUnixMakefileGenerator3.cxx 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  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, false);
  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. this->WriteMakeRule
  669. (makefileStream,
  670. "A target that is always out of date.",
  671. "cmake_force", no_depends, no_commands, true);
  672. // Variables for reference by other rules.
  673. this->WriteMakeVariables(makefileStream);
  674. }
  675. //----------------------------------------------------------------------------
  676. void cmLocalUnixMakefileGenerator3
  677. ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
  678. {
  679. this->WriteDivider(makefileStream);
  680. makefileStream
  681. << "# Special targets to cleanup operation of make.\n"
  682. << "\n";
  683. // Write special "cmake_check_build_system" target to run cmake with
  684. // the --check-build-system flag.
  685. {
  686. // Build command to run CMake to check if anything needs regenerating.
  687. std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
  688. cmakefileName += "Makefile.cmake";
  689. std::string runRule =
  690. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  691. runRule += " --check-build-system ";
  692. runRule += this->Convert(cmakefileName.c_str(),NONE,SHELL);
  693. runRule += " 0";
  694. std::vector<std::string> no_depends;
  695. std::vector<std::string> commands;
  696. commands.push_back(runRule);
  697. if(this->Parent)
  698. {
  699. this->CreateCDCommand(commands,
  700. this->Makefile->GetHomeOutputDirectory(),
  701. this->Makefile->GetStartOutputDirectory());
  702. }
  703. this->WriteMakeRule(makefileStream,
  704. "Special rule to run CMake to check the build system "
  705. "integrity.\n"
  706. "No rule that depends on this can have "
  707. "commands that come from listfiles\n"
  708. "because they might be regenerated.",
  709. "cmake_check_build_system",
  710. no_depends,
  711. commands, true);
  712. }
  713. }
  714. //----------------------------------------------------------------------------
  715. void
  716. cmLocalUnixMakefileGenerator3
  717. ::WriteConvenienceRule(std::ostream& ruleFileStream,
  718. const char* realTarget,
  719. const char* helpTarget)
  720. {
  721. // A rule is only needed if the names are different.
  722. if(strcmp(realTarget, helpTarget) != 0)
  723. {
  724. // The helper target depends on the real target.
  725. std::vector<std::string> depends;
  726. depends.push_back(realTarget);
  727. // There are no commands.
  728. std::vector<std::string> no_commands;
  729. // Write the rule.
  730. this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  731. helpTarget, depends, no_commands, true);
  732. }
  733. }
  734. //----------------------------------------------------------------------------
  735. std::string
  736. cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
  737. {
  738. std::string dir = this->HomeRelativeOutputPath;
  739. dir += this->GetTargetDirectory(target);
  740. return this->Convert(dir.c_str(),NONE,MAKEFILE);
  741. }
  742. //----------------------------------------------------------------------------
  743. void
  744. cmLocalUnixMakefileGenerator3
  745. ::AppendRuleDepend(std::vector<std::string>& depends,
  746. const char* ruleFileName)
  747. {
  748. // Add a dependency on the rule file itself unless an option to skip
  749. // it is specifically enabled by the user or project.
  750. const char* nodep =
  751. this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
  752. if(!nodep || cmSystemTools::IsOff(nodep))
  753. {
  754. depends.push_back(ruleFileName);
  755. }
  756. }
  757. //----------------------------------------------------------------------------
  758. void
  759. cmLocalUnixMakefileGenerator3
  760. ::AppendCustomDepends(std::vector<std::string>& depends,
  761. const std::vector<cmCustomCommand>& ccs)
  762. {
  763. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  764. i != ccs.end(); ++i)
  765. {
  766. this->AppendCustomDepend(depends, *i);
  767. }
  768. }
  769. //----------------------------------------------------------------------------
  770. void
  771. cmLocalUnixMakefileGenerator3
  772. ::AppendCustomDepend(std::vector<std::string>& depends,
  773. const cmCustomCommand& cc)
  774. {
  775. for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
  776. d != cc.GetDepends().end(); ++d)
  777. {
  778. // Lookup the real name of the dependency in case it is a CMake target.
  779. std::string dep = this->GetRealDependency
  780. (d->c_str(), this->ConfigurationName.c_str());
  781. depends.push_back(dep);
  782. }
  783. }
  784. //----------------------------------------------------------------------------
  785. void
  786. cmLocalUnixMakefileGenerator3
  787. ::AppendCustomCommands(std::vector<std::string>& commands,
  788. const std::vector<cmCustomCommand>& ccs)
  789. {
  790. for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
  791. i != ccs.end(); ++i)
  792. {
  793. this->AppendCustomCommand(commands, *i);
  794. }
  795. }
  796. //----------------------------------------------------------------------------
  797. void
  798. cmLocalUnixMakefileGenerator3
  799. ::AppendCustomCommand(std::vector<std::string>& commands,
  800. const cmCustomCommand& cc)
  801. {
  802. // if the command specified a working directory use it.
  803. const char* dir = this->Makefile->GetStartOutputDirectory();
  804. const char* workingDir = cc.GetWorkingDirectory();
  805. if(workingDir)
  806. {
  807. dir = workingDir;
  808. }
  809. bool escapeOldStyle = cc.GetEscapeOldStyle();
  810. bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
  811. // Add each command line to the set of commands.
  812. std::vector<std::string> commands1;
  813. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
  814. cl != cc.GetCommandLines().end(); ++cl)
  815. {
  816. // Build the command line in a single string.
  817. const cmCustomCommandLine& commandLine = *cl;
  818. std::string cmd = commandLine[0];
  819. if (cmd.size())
  820. {
  821. cmSystemTools::ReplaceString(cmd, "/./", "/");
  822. // Convert the command to a relative path only if the current
  823. // working directory will be the start-output directory.
  824. if(!workingDir)
  825. {
  826. cmd = this->Convert(cmd.c_str(),START_OUTPUT);
  827. }
  828. if(cmd.find("/") == cmd.npos &&
  829. commandLine[0].find("/") != cmd.npos)
  830. {
  831. // Add a leading "./" for executables in the current directory.
  832. cmd = "./" + cmd;
  833. }
  834. cmd = this->Convert(cmd.c_str(),NONE,SHELL);
  835. for(unsigned int j=1; j < commandLine.size(); ++j)
  836. {
  837. cmd += " ";
  838. if(escapeOldStyle)
  839. {
  840. cmd += this->EscapeForShellOldStyle(commandLine[j].c_str());
  841. }
  842. else
  843. {
  844. cmd += this->EscapeForShell(commandLine[j].c_str(),
  845. escapeAllowMakeVars);
  846. }
  847. }
  848. commands1.push_back(cmd);
  849. }
  850. }
  851. // Setup the proper working directory for the commands.
  852. this->CreateCDCommand(commands1, dir,
  853. this->Makefile->GetHomeOutputDirectory());
  854. // push back the custom commands
  855. commands.insert(commands.end(), commands1.begin(), commands1.end());
  856. }
  857. //----------------------------------------------------------------------------
  858. void
  859. cmLocalUnixMakefileGenerator3
  860. ::AppendCleanCommand(std::vector<std::string>& commands,
  861. const std::vector<std::string>& files,
  862. cmTarget& target, const char* filename)
  863. {
  864. if(!files.empty())
  865. {
  866. std::string cleanfile = this->Makefile->GetCurrentOutputDirectory();
  867. cleanfile += "/";
  868. cleanfile += this->GetTargetDirectory(target);
  869. cleanfile += "/cmake_clean";
  870. if(filename)
  871. {
  872. cleanfile += "_";
  873. cleanfile += filename;
  874. }
  875. cleanfile += ".cmake";
  876. std::string cleanfilePath = this->Convert(cleanfile.c_str(), FULL);
  877. std::ofstream fout(cleanfilePath.c_str());
  878. if(!fout)
  879. {
  880. cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
  881. }
  882. fout << "FILE(REMOVE\n";
  883. std::string remove = "$(CMAKE_COMMAND) -P ";
  884. remove += this->Convert(cleanfile.c_str(), START_OUTPUT, SHELL);
  885. for(std::vector<std::string>::const_iterator f = files.begin();
  886. f != files.end(); ++f)
  887. {
  888. fout << "\"" << this->Convert(f->c_str(),START_OUTPUT,UNCHANGED)
  889. << "\"\n";
  890. }
  891. fout << ")\n";
  892. commands.push_back(remove);
  893. }
  894. }
  895. //----------------------------------------------------------------------------
  896. void
  897. cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
  898. const char* text,
  899. EchoColor color)
  900. {
  901. // Choose the color for the text.
  902. std::string color_name;
  903. #ifdef CMAKE_BUILD_WITH_CMAKE
  904. if(this->GlobalGenerator->GetToolSupportsColor() && this->ColorMakefile)
  905. {
  906. // See cmake::ExecuteEchoColor in cmake.cxx for these options.
  907. // This color set is readable on both black and white backgrounds.
  908. switch(color)
  909. {
  910. case EchoNormal:
  911. break;
  912. case EchoDepend:
  913. color_name = "--magenta --bold ";
  914. break;
  915. case EchoBuild:
  916. color_name = "--green ";
  917. break;
  918. case EchoLink:
  919. color_name = "--red --bold ";
  920. break;
  921. case EchoGenerate:
  922. color_name = "--blue --bold ";
  923. break;
  924. case EchoGlobal:
  925. color_name = "--cyan ";
  926. break;
  927. }
  928. }
  929. #else
  930. (void)color;
  931. #endif
  932. // Echo one line at a time.
  933. std::string line;
  934. line.reserve(200);
  935. for(const char* c = text;; ++c)
  936. {
  937. if(*c == '\n' || *c == '\0')
  938. {
  939. // Avoid writing a blank last line on end-of-string.
  940. if(*c != '\0' || !line.empty())
  941. {
  942. // Add a command to echo this line.
  943. std::string cmd;
  944. if(color_name.empty())
  945. {
  946. // Use the native echo command.
  947. cmd = "@echo ";
  948. if(this->EchoNeedsQuote)
  949. {
  950. cmd += "\"";
  951. }
  952. cmd += line;
  953. if(this->EchoNeedsQuote)
  954. {
  955. cmd += "\"";
  956. }
  957. }
  958. else
  959. {
  960. // Use cmake to echo the text in color.
  961. cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
  962. cmd += color_name;
  963. cmd += "\"";
  964. cmd += line;
  965. cmd += "\"";
  966. }
  967. commands.push_back(cmd);
  968. }
  969. // Reset the line to emtpy.
  970. line = "";
  971. // Terminate on end-of-string.
  972. if(*c == '\0')
  973. {
  974. return;
  975. }
  976. }
  977. else if(*c != '\r')
  978. {
  979. // Append this character to the current line.
  980. line += *c;
  981. }
  982. }
  983. }
  984. //----------------------------------------------------------------------------
  985. //take a tgt path and convert it into a make target, it could be full, or
  986. //relative
  987. std::string cmLocalUnixMakefileGenerator3
  988. ::ConvertToMakeTarget(const char* tgt)
  989. {
  990. // Make targets should not have a leading './' for a file in the
  991. // directory containing the makefile.
  992. std::string ret = tgt;
  993. if(ret.size() > 2 && (ret[0] == '.') &&
  994. ( (ret[1] == '/') || ret[1] == '\\'))
  995. {
  996. std::string upath = ret;
  997. cmSystemTools::ConvertToUnixSlashes(upath);
  998. if(upath.find(2, '/') == upath.npos)
  999. {
  1000. ret = ret.substr(2, ret.size()-2);
  1001. }
  1002. }
  1003. return ret;
  1004. }
  1005. //----------------------------------------------------------------------------
  1006. std::string
  1007. cmLocalUnixMakefileGenerator3
  1008. ::CreateMakeVariable(const char* sin, const char* s2in)
  1009. {
  1010. std::string s = sin;
  1011. std::string s2 = s2in;
  1012. std::string unmodified = s;
  1013. unmodified += s2;
  1014. // if there is no restriction on the length of make variables
  1015. // and there are no "." charactors in the string, then return the
  1016. // unmodified combination.
  1017. if((!this->MakefileVariableSize && unmodified.find('.') == s.npos)
  1018. && (!this->MakefileVariableSize && unmodified.find('-') == s.npos))
  1019. {
  1020. return unmodified;
  1021. }
  1022. // see if the variable has been defined before and return
  1023. // the modified version of the variable
  1024. std::map<cmStdString, cmStdString>::iterator i =
  1025. this->MakeVariableMap.find(unmodified);
  1026. if(i != this->MakeVariableMap.end())
  1027. {
  1028. return i->second;
  1029. }
  1030. // start with the unmodified variable
  1031. std::string ret = unmodified;
  1032. // if this there is no value for this->MakefileVariableSize then
  1033. // the string must have bad characters in it
  1034. if(!this->MakefileVariableSize)
  1035. {
  1036. cmSystemTools::ReplaceString(ret, ".", "_");
  1037. cmSystemTools::ReplaceString(ret, "-", "__");
  1038. int ni = 0;
  1039. char buffer[5];
  1040. // make sure the _ version is not already used, if
  1041. // it is used then add number to the end of the variable
  1042. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  1043. {
  1044. ++ni;
  1045. sprintf(buffer, "%04d", ni);
  1046. ret = unmodified + buffer;
  1047. }
  1048. this->ShortMakeVariableMap[ret] = "1";
  1049. this->MakeVariableMap[unmodified] = ret;
  1050. return ret;
  1051. }
  1052. // if the string is greater the 32 chars it is an invalid vairable name
  1053. // for borland make
  1054. if(static_cast<int>(ret.size()) > this->MakefileVariableSize)
  1055. {
  1056. int keep = this->MakefileVariableSize - 8;
  1057. int size = keep + 3;
  1058. std::string str1 = s;
  1059. std::string str2 = s2;
  1060. // we must shorten the combined string by 4 charactors
  1061. // keep no more than 24 charactors from the second string
  1062. if(static_cast<int>(str2.size()) > keep)
  1063. {
  1064. str2 = str2.substr(0, keep);
  1065. }
  1066. if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
  1067. {
  1068. str1 = str1.substr(0, size - str2.size());
  1069. }
  1070. char buffer[5];
  1071. int ni = 0;
  1072. sprintf(buffer, "%04d", ni);
  1073. ret = str1 + str2 + buffer;
  1074. while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
  1075. {
  1076. ++ni;
  1077. sprintf(buffer, "%04d", ni);
  1078. ret = str1 + str2 + buffer;
  1079. }
  1080. if(ni == 1000)
  1081. {
  1082. cmSystemTools::Error("Borland makefile variable length too long");
  1083. return unmodified;
  1084. }
  1085. // once an unused variable is found
  1086. this->ShortMakeVariableMap[ret] = "1";
  1087. }
  1088. // always make an entry into the unmodified to variable map
  1089. this->MakeVariableMap[unmodified] = ret;
  1090. return ret;
  1091. }
  1092. //----------------------------------------------------------------------------
  1093. bool cmLocalUnixMakefileGenerator3::ScanDependencies(const char* tgtInfo)
  1094. {
  1095. // The info file for this target
  1096. std::string infoFile = tgtInfo;
  1097. // Read the directory information file.
  1098. cmMakefile* mf = this->Makefile;
  1099. bool haveDirectoryInfo = false;
  1100. std::string dirInfoFile = this->Makefile->GetStartOutputDirectory();
  1101. dirInfoFile += cmake::GetCMakeFilesDirectory();
  1102. dirInfoFile += "/CMakeDirectoryInformation.cmake";
  1103. if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
  1104. !cmSystemTools::GetErrorOccuredFlag())
  1105. {
  1106. haveDirectoryInfo = true;
  1107. }
  1108. // read in the target info file
  1109. if(!mf->ReadListFile(0, infoFile.c_str()) ||
  1110. cmSystemTools::GetErrorOccuredFlag())
  1111. {
  1112. cmSystemTools::Error("Target DependInfo.cmake file not found");
  1113. }
  1114. // Test whether we need to force Unix paths.
  1115. if(haveDirectoryInfo)
  1116. {
  1117. if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
  1118. {
  1119. if(!cmSystemTools::IsOff(force))
  1120. {
  1121. cmSystemTools::SetForceUnixPaths(true);
  1122. }
  1123. }
  1124. }
  1125. else
  1126. {
  1127. cmSystemTools::Error("Directory Information file not found");
  1128. }
  1129. // create the file stream for the depends file
  1130. std::string dir = cmSystemTools::GetFilenamePath(infoFile);
  1131. // Open the rule file. This should be copy-if-different because the
  1132. // rules may depend on this file itself.
  1133. std::string ruleFileNameFull = dir;
  1134. ruleFileNameFull += "/depend.make";
  1135. cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
  1136. ruleFileStream.SetCopyIfDifferent(true);
  1137. if(!ruleFileStream)
  1138. {
  1139. return false;
  1140. }
  1141. std::string internalRuleFileNameFull = dir;
  1142. internalRuleFileNameFull += "/depend.internal";
  1143. cmGeneratedFileStream
  1144. internalRuleFileStream(internalRuleFileNameFull.c_str());
  1145. internalRuleFileStream.SetCopyIfDifferent(true);
  1146. if(!internalRuleFileStream)
  1147. {
  1148. return false;
  1149. }
  1150. this->WriteDisclaimer(ruleFileStream);
  1151. this->WriteDisclaimer(internalRuleFileStream);
  1152. // for each language we need to scan, scan it
  1153. const char *langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
  1154. std::vector<std::string> langs;
  1155. cmSystemTools::ExpandListArgument(langStr, langs);
  1156. for (std::vector<std::string>::iterator li =
  1157. langs.begin(); li != langs.end(); ++li)
  1158. {
  1159. // construct the checker
  1160. std::string lang = li->c_str();
  1161. // Get the set of include directories.
  1162. std::vector<std::string> includes;
  1163. if(haveDirectoryInfo)
  1164. {
  1165. std::string includePathVar = "CMAKE_";
  1166. includePathVar += lang;
  1167. includePathVar += "_INCLUDE_PATH";
  1168. if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
  1169. {
  1170. cmSystemTools::ExpandListArgument(includePath, includes);
  1171. }
  1172. }
  1173. // Get the include file regular expression.
  1174. std::string includeRegexScan = "^.*$";
  1175. std::string includeRegexComplain = "^$";
  1176. if(haveDirectoryInfo)
  1177. {
  1178. std::string scanRegexVar = "CMAKE_";
  1179. scanRegexVar += lang;
  1180. scanRegexVar += "_INCLUDE_REGEX_SCAN";
  1181. if(const char* scanRegex = mf->GetDefinition(scanRegexVar.c_str()))
  1182. {
  1183. includeRegexScan = scanRegex;
  1184. }
  1185. std::string complainRegexVar = "CMAKE_";
  1186. complainRegexVar += lang;
  1187. complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
  1188. if(const char* complainRegex =
  1189. mf->GetDefinition(complainRegexVar.c_str()))
  1190. {
  1191. includeRegexComplain = complainRegex;
  1192. }
  1193. }
  1194. // Create the scanner for this language
  1195. cmDepends *scanner = 0;
  1196. if(lang == "C" || lang == "CXX" || lang == "RC")
  1197. {
  1198. std::string includeCacheFileName = dir;
  1199. includeCacheFileName += "/";
  1200. includeCacheFileName += lang;
  1201. includeCacheFileName += ".includecache";
  1202. // TODO: Handle RC (resource files) dependencies correctly.
  1203. scanner = new cmDependsC(includes,
  1204. includeRegexScan.c_str(),
  1205. includeRegexComplain.c_str(),
  1206. includeCacheFileName);
  1207. scanner->SetLocalGenerator(this);
  1208. }
  1209. #ifdef CMAKE_BUILD_WITH_CMAKE
  1210. else if(lang == "Fortran")
  1211. {
  1212. scanner = new cmDependsFortran(includes);
  1213. }
  1214. else if(lang == "Java")
  1215. {
  1216. scanner = new cmDependsJava();
  1217. }
  1218. #endif
  1219. if (scanner)
  1220. {
  1221. scanner->SetFileComparison
  1222. (this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1223. // for each file we need to scan
  1224. std::string srcLang = "CMAKE_DEPENDS_CHECK_";
  1225. srcLang += lang;
  1226. const char *srcStr = mf->GetSafeDefinition(srcLang.c_str());
  1227. std::vector<std::string> srcs;
  1228. cmSystemTools::ExpandListArgument(srcStr, srcs);
  1229. for (std::vector<std::string>::iterator si =
  1230. srcs.begin(); si != srcs.end(); ++si)
  1231. {
  1232. std::string &src = *si;
  1233. ++si;
  1234. // make sure the object file is relative to home output
  1235. std::string obj = *si;
  1236. obj = this->Convert(obj.c_str(),HOME_OUTPUT,MAKEFILE);
  1237. scanner->Write(src.c_str(),obj.c_str(),
  1238. ruleFileStream, internalRuleFileStream);
  1239. }
  1240. // free the scanner for this language
  1241. delete scanner;
  1242. }
  1243. }
  1244. // dependencies were generated, so touch the mark file
  1245. ruleFileNameFull += ".mark";
  1246. std::ofstream fmark(ruleFileNameFull.c_str());
  1247. fmark << "Dependencies updated>" << std::endl;
  1248. return true;
  1249. }
  1250. //----------------------------------------------------------------------------
  1251. void cmLocalUnixMakefileGenerator3
  1252. ::WriteLocalAllRules(std::ostream& ruleFileStream)
  1253. {
  1254. this->WriteDisclaimer(ruleFileStream);
  1255. // Write the main entry point target. This must be the VERY first
  1256. // target so that make with no arguments will run it.
  1257. {
  1258. // Just depend on the all target to drive the build.
  1259. std::vector<std::string> depends;
  1260. std::vector<std::string> no_commands;
  1261. depends.push_back("all");
  1262. // Write the rule.
  1263. this->WriteMakeRule(ruleFileStream,
  1264. "Default target executed when no arguments are "
  1265. "given to make.",
  1266. "default_target",
  1267. depends,
  1268. no_commands, true);
  1269. }
  1270. this->WriteSpecialTargetsTop(ruleFileStream);
  1271. // Include the progress variables for the target.
  1272. ruleFileStream
  1273. << "# Include the progress variables for this target.\n"
  1274. << this->IncludeDirective << " "
  1275. << "progress.make\n\n";
  1276. // Write all global targets
  1277. this->WriteDivider(ruleFileStream);
  1278. ruleFileStream
  1279. << "# Targets provided globally by CMake.\n"
  1280. << "\n";
  1281. cmTargets* targets = &(this->Makefile->GetTargets());
  1282. cmTargets::iterator glIt;
  1283. for ( glIt = targets->begin(); glIt != targets->end(); ++ glIt )
  1284. {
  1285. if ( glIt->second.GetType() == cmTarget::GLOBAL_TARGET )
  1286. {
  1287. std::string targetString = "Special rule for the target " + glIt->first;
  1288. std::vector<std::string> commands;
  1289. std::vector<std::string> depends;
  1290. const char* text = glIt->second.GetProperty("EchoString");
  1291. if ( !text )
  1292. {
  1293. text = "Running external command ...";
  1294. }
  1295. std::set<cmStdString>::const_iterator dit;
  1296. for ( dit = glIt->second.GetUtilities().begin();
  1297. dit != glIt->second.GetUtilities().end();
  1298. ++ dit )
  1299. {
  1300. depends.push_back(dit->c_str());
  1301. }
  1302. this->AppendEcho(commands, text,
  1303. cmLocalUnixMakefileGenerator3::EchoGlobal);
  1304. // Global targets store their rules in pre- and post-build commands.
  1305. this->AppendCustomDepends(depends,
  1306. glIt->second.GetPreBuildCommands());
  1307. this->AppendCustomDepends(depends,
  1308. glIt->second.GetPostBuildCommands());
  1309. this->AppendCustomCommands(commands,
  1310. glIt->second.GetPreBuildCommands());
  1311. this->AppendCustomCommands(commands,
  1312. glIt->second.GetPostBuildCommands());
  1313. std::string targetName = glIt->second.GetName();
  1314. this->WriteMakeRule(ruleFileStream, targetString.c_str(),
  1315. targetName.c_str(), depends, commands, true);
  1316. // Provide a "/fast" version of the target.
  1317. depends.clear();
  1318. if((targetName == "install") || (targetName == "install_local"))
  1319. {
  1320. // Provide a fast install target that does not depend on all
  1321. // but has the same command.
  1322. depends.push_back("preinstall/fast");
  1323. }
  1324. else
  1325. {
  1326. // Just forward to the real target so at least it will work.
  1327. depends.push_back(targetName);
  1328. commands.clear();
  1329. }
  1330. targetName += "/fast";
  1331. this->WriteMakeRule(ruleFileStream, targetString.c_str(),
  1332. targetName.c_str(), depends, commands, true);
  1333. }
  1334. }
  1335. std::vector<std::string> depends;
  1336. std::vector<std::string> commands;
  1337. // Write the all rule.
  1338. std::string dir = this->Makefile->GetStartOutputDirectory();
  1339. dir += "/all";
  1340. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1341. depends.push_back("cmake_check_build_system");
  1342. std::string progressDir = this->Makefile->GetHomeOutputDirectory();
  1343. progressDir += cmake::GetCMakeFilesDirectory();
  1344. {
  1345. cmOStringStream progCmd;
  1346. progCmd <<
  1347. "$(CMAKE_COMMAND) -E cmake_progress_start ";
  1348. progCmd << this->Convert(progressDir.c_str(),
  1349. cmLocalGenerator::FULL,
  1350. cmLocalGenerator::SHELL);
  1351. progCmd << " $(CMAKE_ALL_PROGRESS)";
  1352. commands.push_back(progCmd.str());
  1353. }
  1354. std::string mf2Dir = cmake::GetCMakeFilesDirectoryPostSlash();
  1355. mf2Dir += "Makefile2";
  1356. commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
  1357. dir.c_str()));
  1358. this->CreateCDCommand(commands,
  1359. this->Makefile->GetHomeOutputDirectory(),
  1360. this->Makefile->GetStartOutputDirectory());
  1361. {
  1362. cmOStringStream progCmd;
  1363. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
  1364. progCmd << this->Convert(progressDir.c_str(),
  1365. cmLocalGenerator::FULL,
  1366. cmLocalGenerator::SHELL);
  1367. progCmd << " 0";
  1368. commands.push_back(progCmd.str());
  1369. }
  1370. this->WriteMakeRule(ruleFileStream, "The main all target", "all",
  1371. depends, commands, true);
  1372. // Write the clean rule.
  1373. dir = this->Makefile->GetStartOutputDirectory();
  1374. dir += "/clean";
  1375. dir = this->Convert(dir.c_str(),HOME_OUTPUT,MAKEFILE);
  1376. commands.clear();
  1377. depends.clear();
  1378. commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
  1379. dir.c_str()));
  1380. this->CreateCDCommand(commands,
  1381. this->Makefile->GetHomeOutputDirectory(),
  1382. this->Makefile->GetStartOutputDirectory());
  1383. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
  1384. depends, commands, true);
  1385. commands.clear();
  1386. depends.clear();
  1387. depends.push_back("clean");
  1388. this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
  1389. depends, commands, true);
  1390. // Write the preinstall rule.
  1391. dir = this->Makefile->GetStartOutputDirectory();
  1392. dir += "/preinstall";
  1393. dir = this->Convert(dir.c_str(), HOME_OUTPUT,MAKEFILE);
  1394. commands.clear();
  1395. depends.clear();
  1396. const char* noall =
  1397. this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  1398. if(!noall || cmSystemTools::IsOff(noall))
  1399. {
  1400. // Drive the build before installing.
  1401. depends.push_back("all");
  1402. }
  1403. else
  1404. {
  1405. // At least make sure the build system is up to date.
  1406. depends.push_back("cmake_check_build_system");
  1407. }
  1408. commands.push_back
  1409. (this->GetRecursiveMakeCall(mf2Dir.c_str(), dir.c_str()));
  1410. this->CreateCDCommand(commands,
  1411. this->Makefile->GetHomeOutputDirectory(),
  1412. this->Makefile->GetStartOutputDirectory());
  1413. this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
  1414. "preinstall", depends, commands, true);
  1415. depends.clear();
  1416. this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
  1417. "preinstall/fast", depends, commands, true);
  1418. // write the depend rule, really a recompute depends rule
  1419. depends.clear();
  1420. commands.clear();
  1421. std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
  1422. cmakefileName += "Makefile.cmake";
  1423. this->Convert(cmakefileName.c_str(),HOME_OUTPUT,
  1424. cmLocalGenerator::MAKEFILE);
  1425. std::string runRule =
  1426. "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
  1427. runRule += " --check-build-system ";
  1428. runRule += this->Convert(cmakefileName.c_str(),cmLocalGenerator::NONE,
  1429. cmLocalGenerator::SHELL);
  1430. runRule += " 1";
  1431. commands.push_back(runRule);
  1432. this->WriteMakeRule(ruleFileStream, "clear depends",
  1433. "depend",
  1434. depends, commands, true);
  1435. }
  1436. //----------------------------------------------------------------------------
  1437. void cmLocalUnixMakefileGenerator3::CheckDependencies(cmMakefile* mf,
  1438. bool verbose,
  1439. bool clear)
  1440. {
  1441. // Get the list of target files to check
  1442. const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
  1443. if(!infoDef)
  1444. {
  1445. return;
  1446. }
  1447. std::vector<std::string> files;
  1448. cmSystemTools::ExpandListArgument(infoDef, files);
  1449. // For each info file run the check
  1450. cmDependsC checker;
  1451. checker.SetVerbose(verbose);
  1452. checker.SetFileComparison
  1453. (this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
  1454. for(std::vector<std::string>::iterator l = files.begin();
  1455. l != files.end(); ++l)
  1456. {
  1457. // either clear or check the files
  1458. std::string dir = cmSystemTools::GetFilenamePath(l->c_str());
  1459. std::string internalDependFile = dir + "/depend.internal";
  1460. std::string dependFile = dir + "/depend.make";
  1461. if (clear)
  1462. {
  1463. checker.Clear(internalDependFile.c_str());
  1464. checker.Clear(dependFile.c_str());
  1465. }
  1466. else
  1467. {
  1468. checker.Check(dependFile.c_str(), internalDependFile.c_str());
  1469. }
  1470. }
  1471. }
  1472. void cmLocalUnixMakefileGenerator3
  1473. ::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
  1474. {
  1475. // now write all the language stuff
  1476. // Set the set of files to check for dependency integrity.
  1477. std::set<cmStdString> checkSetLangs;
  1478. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  1479. checkSet = this->GetIntegrityCheckSet()[target.GetName()];
  1480. for(std::map<cmStdString,
  1481. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  1482. l = checkSet.begin(); l != checkSet.end(); ++l)
  1483. {
  1484. checkSetLangs.insert(l->first);
  1485. }
  1486. // list the languages
  1487. cmakefileStream
  1488. << "# The set of files whose dependency integrity should be checked:\n";
  1489. cmakefileStream
  1490. << "SET(CMAKE_DEPENDS_LANGUAGES\n";
  1491. for(std::set<cmStdString>::iterator
  1492. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1493. {
  1494. cmakefileStream << " \"" << l->c_str() << "\"\n";
  1495. }
  1496. cmakefileStream << " )\n";
  1497. // now list the files for each language
  1498. for(std::set<cmStdString>::iterator
  1499. l = checkSetLangs.begin(); l != checkSetLangs.end(); ++l)
  1500. {
  1501. cmakefileStream
  1502. << "SET(CMAKE_DEPENDS_CHECK_" << l->c_str() << "\n";
  1503. // get the check set for this local gen and language
  1504. cmLocalUnixMakefileGenerator3::IntegrityCheckSet iCheckSet =
  1505. checkSet[*l];
  1506. // for each file
  1507. for(cmLocalUnixMakefileGenerator3::IntegrityCheckSet::const_iterator
  1508. csIter = iCheckSet.begin();
  1509. csIter != iCheckSet.end(); ++csIter)
  1510. {
  1511. cmakefileStream << " \"" << (*csIter)->GetFullPath() << "\"\n";
  1512. // Get the full path name of the object file.
  1513. std::string obj = this->Makefile->GetStartOutputDirectory();
  1514. obj += "/";
  1515. obj += this->GetObjectFileName(target, **csIter);
  1516. cmakefileStream << " \"" <<
  1517. this->Convert(obj.c_str(),
  1518. cmLocalGenerator::FULL).c_str() << "\"\n";
  1519. }
  1520. cmakefileStream << " )\n";
  1521. }
  1522. }
  1523. //----------------------------------------------------------------------------
  1524. std::string
  1525. cmLocalUnixMakefileGenerator3
  1526. ::GetObjectFileName(cmTarget& target,
  1527. const cmSourceFile& source,
  1528. std::string* nameWithoutTargetDir)
  1529. {
  1530. // Get the object file name independent of target.
  1531. std::string objectName = this->GetObjectFileNameWithoutTarget(source);
  1532. if(nameWithoutTargetDir)
  1533. {
  1534. *nameWithoutTargetDir = objectName;
  1535. }
  1536. // Prepend the target directory.
  1537. std::string obj;
  1538. const char* fileTargetDirectory =
  1539. source.GetProperty("MACOSX_PACKAGE_LOCATION");
  1540. if ( fileTargetDirectory )
  1541. {
  1542. objectName = cmSystemTools::GetFilenameName(objectName.c_str());
  1543. std::string targetName;
  1544. std::string targetNameReal;
  1545. target.GetExecutableNames(targetName, targetNameReal,
  1546. this->ConfigurationName.c_str());
  1547. if ( target.GetPropertyAsBool("MACOSX_BUNDLE") )
  1548. {
  1549. // Construct the full path version of the names.
  1550. obj = this->ExecutableOutputPath;
  1551. if(obj.empty())
  1552. {
  1553. obj = this->Makefile->GetStartOutputDirectory();
  1554. obj += "/";
  1555. }
  1556. obj += targetName + ".app/Contents/";
  1557. obj += fileTargetDirectory;
  1558. }
  1559. else
  1560. {
  1561. // Framework not handled yet
  1562. abort();
  1563. }
  1564. obj = cmSystemTools::RelativePath
  1565. (this->Makefile->GetHomeOutputDirectory(), obj.c_str());
  1566. }
  1567. else
  1568. {
  1569. obj = this->GetTargetDirectory(target);
  1570. }
  1571. obj += "/";
  1572. obj += objectName;
  1573. return obj;
  1574. }
  1575. //----------------------------------------------------------------------------
  1576. void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
  1577. {
  1578. os
  1579. << "# CMAKE generated file: DO NOT EDIT!\n"
  1580. << "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
  1581. << " Generator, CMake Version "
  1582. << cmMakefile::GetMajorVersion() << "."
  1583. << cmMakefile::GetMinorVersion() << "\n\n";
  1584. }
  1585. //----------------------------------------------------------------------------
  1586. std::string
  1587. cmLocalUnixMakefileGenerator3
  1588. ::GetRecursiveMakeCall(const char *makefile, const char* tgt)
  1589. {
  1590. // Call make on the given file.
  1591. std::string cmd;
  1592. cmd += "$(MAKE) -f ";
  1593. cmd += makefile;
  1594. cmd += " ";
  1595. // Passg down verbosity level.
  1596. if(this->GetMakeSilentFlag().size())
  1597. {
  1598. cmd += this->GetMakeSilentFlag();
  1599. cmd += " ";
  1600. }
  1601. // Most unix makes will pass the command line flags to make down to
  1602. // sub-invoked makes via an environment variable. However, some
  1603. // makes do not support that, so you have to pass the flags
  1604. // explicitly.
  1605. if(this->GetPassMakeflags())
  1606. {
  1607. cmd += "-$(MAKEFLAGS) ";
  1608. }
  1609. // Add the target.
  1610. if (tgt && tgt[0] != '\0')
  1611. {
  1612. std::string tgt2 = this->Convert(tgt,HOME_OUTPUT,MAKEFILE);
  1613. tgt2 = this->ConvertToMakeTarget(tgt2.c_str());
  1614. cmd += tgt2;
  1615. }
  1616. return cmd;
  1617. }
  1618. //----------------------------------------------------------------------------
  1619. void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
  1620. {
  1621. os
  1622. << "#======================================"
  1623. << "=======================================\n";
  1624. }
  1625. //----------------------------------------------------------------------------
  1626. void
  1627. cmLocalUnixMakefileGenerator3
  1628. ::WriteCMakeArgument(std::ostream& os, const char* s)
  1629. {
  1630. // Write the given string to the stream with escaping to get it back
  1631. // into CMake through the lexical scanner.
  1632. os << "\"";
  1633. for(const char* c = s; *c; ++c)
  1634. {
  1635. if(*c == '\\')
  1636. {
  1637. os << "\\\\";
  1638. }
  1639. else if(*c == '"')
  1640. {
  1641. os << "\\\"";
  1642. }
  1643. else
  1644. {
  1645. os << *c;
  1646. }
  1647. }
  1648. os << "\"";
  1649. }
  1650. //----------------------------------------------------------------------------
  1651. std::string
  1652. cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
  1653. {
  1654. // Split the path into its components.
  1655. std::vector<std::string> components;
  1656. cmSystemTools::SplitPath(p, components);
  1657. // Return an empty path if there are no components.
  1658. if(components.empty())
  1659. {
  1660. return "\"\"";
  1661. }
  1662. // Choose a slash direction and fix root component.
  1663. const char* slash = "/";
  1664. #if defined(_WIN32) && !defined(__CYGWIN__)
  1665. if(!cmSystemTools::GetForceUnixPaths())
  1666. {
  1667. slash = "\\";
  1668. for(std::string::iterator i = components[0].begin();
  1669. i != components[0].end(); ++i)
  1670. {
  1671. if(*i == '/')
  1672. {
  1673. *i = '\\';
  1674. }
  1675. }
  1676. }
  1677. #endif
  1678. // Begin the quoted result with the root component.
  1679. std::string result = "\"";
  1680. result += components[0];
  1681. // Now add the rest of the components separated by the proper slash
  1682. // direction for this platform.
  1683. bool first = true;
  1684. for(unsigned int i=1; i < components.size(); ++i)
  1685. {
  1686. // Only the last component can be empty to avoid double slashes.
  1687. if(components[i].length() > 0 || (i == (components.size()-1)))
  1688. {
  1689. if(!first)
  1690. {
  1691. result += slash;
  1692. }
  1693. result += components[i];
  1694. first = false;
  1695. }
  1696. }
  1697. // Close the quoted result.
  1698. result += "\"";
  1699. return result;
  1700. }
  1701. //----------------------------------------------------------------------------
  1702. std::string
  1703. cmLocalUnixMakefileGenerator3::GetTargetDirectory(cmTarget& target)
  1704. {
  1705. std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
  1706. dir += target.GetName();
  1707. dir += ".dir";
  1708. return dir;
  1709. }
  1710. void cmLocalUnixMakefileGenerator3
  1711. ::CreateCDCommand(std::vector<std::string>& commands, const char *tgtDir,
  1712. const char *retDir)
  1713. {
  1714. // do we need to cd?
  1715. if (!strcmp(tgtDir,retDir))
  1716. {
  1717. return;
  1718. }
  1719. if(!this->UnixCD)
  1720. {
  1721. // On Windows we must perform each step separately and then change
  1722. // back because the shell keeps the working directory between
  1723. // commands.
  1724. std::string cmd = "cd ";
  1725. cmd += this->ConvertToOutputForExisting(tgtDir);
  1726. commands.insert(commands.begin(),cmd);
  1727. // Change back to the starting directory. Any trailing slash must be
  1728. // removed to avoid problems with Borland Make.
  1729. std::string back = retDir;
  1730. if(back.size() && back[back.size()-1] == '/')
  1731. {
  1732. back = back.substr(0, back.size()-1);
  1733. }
  1734. cmd = "cd ";
  1735. cmd += this->ConvertToOutputForExisting(back.c_str());
  1736. commands.push_back(cmd);
  1737. }
  1738. else
  1739. {
  1740. // On UNIX we must construct a single shell command to change
  1741. // directory and build because make resets the directory between
  1742. // each command.
  1743. std::vector<std::string>::iterator i = commands.begin();
  1744. for (; i != commands.end(); ++i)
  1745. {
  1746. std::string cmd = "cd ";
  1747. cmd += this->ConvertToOutputForExisting(tgtDir);
  1748. cmd += " && ";
  1749. cmd += *i;
  1750. *i = cmd;
  1751. }
  1752. }
  1753. }