cmGlobalUnixMakefileGenerator3.cxx 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator3
  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 "cmGlobalUnixMakefileGenerator3.h"
  14. #include "cmLocalUnixMakefileGenerator3.h"
  15. #include "cmMakefile.h"
  16. #include "cmake.h"
  17. #include "cmGeneratedFileStream.h"
  18. #include "cmSourceFile.h"
  19. #include "cmTarget.h"
  20. cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3()
  21. {
  22. // This type of makefile always requires unix style paths
  23. this->ForceUnixPaths = true;
  24. this->FindMakeProgramFile = "CMakeUnixFindMake.cmake";
  25. this->ToolSupportsColor = true;
  26. #ifdef _WIN32
  27. this->UseLinkScript = false;
  28. #else
  29. this->UseLinkScript = true;
  30. #endif
  31. }
  32. void cmGlobalUnixMakefileGenerator3
  33. ::EnableLanguage(std::vector<std::string>const& languages, cmMakefile *mf)
  34. {
  35. this->cmGlobalGenerator::EnableLanguage(languages, mf);
  36. std::string path;
  37. for(std::vector<std::string>::const_iterator l = languages.begin();
  38. l != languages.end(); ++l)
  39. {
  40. if(*l == "NONE")
  41. {
  42. continue;
  43. }
  44. const char* lang = l->c_str();
  45. std::string langComp = "CMAKE_";
  46. langComp += lang;
  47. langComp += "_COMPILER";
  48. if(!mf->GetDefinition(langComp.c_str()))
  49. {
  50. cmSystemTools::Error(langComp.c_str(),
  51. " not set, after EnableLanguage");
  52. continue;
  53. }
  54. const char* name = mf->GetRequiredDefinition(langComp.c_str());
  55. if(!cmSystemTools::FileIsFullPath(name))
  56. {
  57. path = cmSystemTools::FindProgram(name);
  58. }
  59. else
  60. {
  61. path = name;
  62. }
  63. if(path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
  64. {
  65. std::string message = "your ";
  66. message += lang;
  67. message += " compiler: \"";
  68. message += name;
  69. message += "\" was not found. Please set ";
  70. message += langComp;
  71. message += " to a valid compiler path or name.";
  72. cmSystemTools::Error(message.c_str());
  73. path = name;
  74. }
  75. std::string doc = lang;
  76. doc += " compiler.";
  77. mf->AddCacheDefinition(langComp.c_str(), path.c_str(),
  78. doc.c_str(), cmCacheManager::FILEPATH);
  79. }
  80. }
  81. ///! Create a local generator appropriate to this Global Generator
  82. cmLocalGenerator *cmGlobalUnixMakefileGenerator3::CreateLocalGenerator()
  83. {
  84. cmLocalGenerator* lg = new cmLocalUnixMakefileGenerator3;
  85. lg->SetGlobalGenerator(this);
  86. return lg;
  87. }
  88. //----------------------------------------------------------------------------
  89. void cmGlobalUnixMakefileGenerator3
  90. ::GetDocumentation(cmDocumentationEntry& entry) const
  91. {
  92. entry.name = this->GetName();
  93. entry.brief = "Generates standard UNIX makefiles.";
  94. entry.full =
  95. "A hierarchy of UNIX makefiles is generated into the build tree. Any "
  96. "standard UNIX-style make program can build the project through the "
  97. "default make target. A \"make install\" target is also provided.";
  98. }
  99. //----------------------------------------------------------------------------
  100. void
  101. cmGlobalUnixMakefileGenerator3
  102. ::AddMultipleOutputPair(const char* depender, const char* dependee)
  103. {
  104. MultipleOutputPairsType::value_type p(depender, dependee);
  105. this->MultipleOutputPairs.insert(p);
  106. }
  107. //----------------------------------------------------------------------------
  108. void cmGlobalUnixMakefileGenerator3::Generate()
  109. {
  110. // first do superclass method
  111. this->cmGlobalGenerator::Generate();
  112. // initialize progress
  113. unsigned int i;
  114. unsigned long total = 0;
  115. for (i = 0; i < this->LocalGenerators.size(); ++i)
  116. {
  117. cmLocalUnixMakefileGenerator3 *lg =
  118. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  119. total += lg->GetNumberOfProgressActions();
  120. }
  121. // write each target's progress.make this loop is done twice. Bascially the
  122. // Generate pass counts all the actions, the first loop below determines
  123. // how many actions have progress updates for each target and writes to
  124. // corrrect variable values for everything except the all targets. The
  125. // second loop actually writes out correct values for the all targets as
  126. // well. This is because the all targets require more information that is
  127. // computed in the first loop.
  128. unsigned long current = 0;
  129. for (i = 0; i < this->LocalGenerators.size(); ++i)
  130. {
  131. cmLocalUnixMakefileGenerator3 *lg =
  132. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  133. lg->WriteProgressVariables(total,current);
  134. }
  135. for (i = 0; i < this->LocalGenerators.size(); ++i)
  136. {
  137. cmLocalUnixMakefileGenerator3 *lg =
  138. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  139. lg->WriteAllProgressVariable();
  140. }
  141. // write the main makefile
  142. this->WriteMainMakefile2();
  143. this->WriteMainCMakefile();
  144. }
  145. void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
  146. {
  147. // Open the output file. This should not be copy-if-different
  148. // because the check-build-system step compares the makefile time to
  149. // see if the build system must be regenerated.
  150. std::string makefileName =
  151. this->GetCMakeInstance()->GetHomeOutputDirectory();
  152. makefileName += cmake::GetCMakeFilesDirectory();
  153. makefileName += "/Makefile2";
  154. cmGeneratedFileStream makefileStream(makefileName.c_str());
  155. if(!makefileStream)
  156. {
  157. return;
  158. }
  159. // get a local generator for some useful methods
  160. cmLocalUnixMakefileGenerator3 *lg =
  161. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
  162. // Write the do not edit header.
  163. lg->WriteDisclaimer(makefileStream);
  164. // Write the main entry point target. This must be the VERY first
  165. // target so that make with no arguments will run it.
  166. // Just depend on the all target to drive the build.
  167. std::vector<std::string> depends;
  168. std::vector<std::string> no_commands;
  169. depends.push_back("all");
  170. // Write the rule.
  171. lg->WriteMakeRule(makefileStream,
  172. "Default target executed when no arguments are "
  173. "given to make.",
  174. "default_target",
  175. depends,
  176. no_commands, true);
  177. depends.clear();
  178. // The all and preinstall rules might never have any dependencies
  179. // added to them.
  180. if(this->EmptyRuleHackDepends != "")
  181. {
  182. depends.push_back(this->EmptyRuleHackDepends);
  183. }
  184. // Write and empty all:
  185. lg->WriteMakeRule(makefileStream,
  186. "The main recursive all target", "all",
  187. depends, no_commands, true);
  188. // Write an empty preinstall:
  189. lg->WriteMakeRule(makefileStream,
  190. "The main recursive preinstall target", "preinstall",
  191. depends, no_commands, true);
  192. lg->WriteMakeVariables(makefileStream);
  193. // Write out the "special" stuff
  194. lg->WriteSpecialTargetsTop(makefileStream);
  195. // write the target convenience rules
  196. unsigned int i;
  197. for (i = 0; i < this->LocalGenerators.size(); ++i)
  198. {
  199. lg =
  200. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  201. // are any parents excluded
  202. bool exclude = false;
  203. cmLocalGenerator *lg3 = lg;
  204. while (lg3)
  205. {
  206. if (lg3->GetExcludeAll())
  207. {
  208. exclude = true;
  209. break;
  210. }
  211. lg3 = lg3->GetParent();
  212. }
  213. this->WriteConvenienceRules2(makefileStream,lg,exclude);
  214. }
  215. lg = static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
  216. lg->WriteSpecialTargetsBottom(makefileStream);
  217. }
  218. //----------------------------------------------------------------------------
  219. void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
  220. {
  221. // Open the output file. This should not be copy-if-different
  222. // because the check-build-system step compares the makefile time to
  223. // see if the build system must be regenerated.
  224. std::string cmakefileName =
  225. this->GetCMakeInstance()->GetHomeOutputDirectory();
  226. cmakefileName += cmake::GetCMakeFilesDirectory();
  227. cmakefileName += "/Makefile.cmake";
  228. cmGeneratedFileStream cmakefileStream(cmakefileName.c_str());
  229. if(!cmakefileStream)
  230. {
  231. return;
  232. }
  233. std::string makefileName =
  234. this->GetCMakeInstance()->GetHomeOutputDirectory();
  235. makefileName += "/Makefile";
  236. // get a local generator for some useful methods
  237. cmLocalUnixMakefileGenerator3 *lg =
  238. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
  239. // Write the do not edit header.
  240. lg->WriteDisclaimer(cmakefileStream);
  241. // Save the generator name
  242. cmakefileStream
  243. << "# The generator used is:\n"
  244. << "SET(CMAKE_DEPENDS_GENERATOR \"" << this->GetName() << "\")\n\n";
  245. // for each cmMakefile get its list of dependencies
  246. std::vector<std::string> lfiles;
  247. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  248. {
  249. lg =
  250. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  251. // Get the list of files contributing to this generation step.
  252. lfiles.insert(lfiles.end(),lg->GetMakefile()->GetListFiles().begin(),
  253. lg->GetMakefile()->GetListFiles().end());
  254. }
  255. // Sort the list and remove duplicates.
  256. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  257. std::vector<std::string>::iterator new_end =
  258. std::unique(lfiles.begin(),lfiles.end());
  259. lfiles.erase(new_end, lfiles.end());
  260. // reset lg to the first makefile
  261. lg = static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[0]);
  262. // Build the path to the cache file.
  263. std::string cache = this->GetCMakeInstance()->GetHomeOutputDirectory();
  264. cache += "/CMakeCache.txt";
  265. // Save the list to the cmake file.
  266. cmakefileStream
  267. << "# The top level Makefile was generated from the following files:\n"
  268. << "SET(CMAKE_MAKEFILE_DEPENDS\n"
  269. << " \""
  270. << lg->Convert(cache.c_str(),
  271. cmLocalGenerator::START_OUTPUT).c_str() << "\"\n";
  272. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  273. i != lfiles.end(); ++i)
  274. {
  275. cmakefileStream
  276. << " \""
  277. << lg->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT).c_str()
  278. << "\"\n";
  279. }
  280. cmakefileStream
  281. << " )\n\n";
  282. // Build the path to the cache check file.
  283. std::string check = this->GetCMakeInstance()->GetHomeOutputDirectory();
  284. check += cmake::GetCMakeFilesDirectory();
  285. check += "/cmake.check_cache";
  286. // Set the corresponding makefile in the cmake file.
  287. cmakefileStream
  288. << "# The corresponding makefile is:\n"
  289. << "SET(CMAKE_MAKEFILE_OUTPUTS\n"
  290. << " \""
  291. << lg->Convert(makefileName.c_str(),
  292. cmLocalGenerator::START_OUTPUT).c_str() << "\"\n"
  293. << " \""
  294. << lg->Convert(check.c_str(),
  295. cmLocalGenerator::START_OUTPUT).c_str() << "\"\n";
  296. // add in all the directory information files
  297. std::string tmpStr;
  298. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  299. {
  300. lg =
  301. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  302. tmpStr = lg->GetMakefile()->GetStartOutputDirectory();
  303. tmpStr += cmake::GetCMakeFilesDirectory();
  304. tmpStr += "/CMakeDirectoryInformation.cmake";
  305. cmakefileStream << " \"" <<
  306. lg->Convert(tmpStr.c_str(),cmLocalGenerator::HOME_OUTPUT).c_str()
  307. << "\"\n";
  308. const std::vector<std::string>& outfiles =
  309. lg->GetMakefile()->GetOutputFiles();
  310. for(std::vector<std::string>::const_iterator k= outfiles.begin();
  311. k != outfiles.end(); ++k)
  312. {
  313. cmakefileStream << " \"" <<
  314. lg->Convert(k->c_str(),cmLocalGenerator::HOME_OUTPUT).c_str()
  315. << "\"\n";
  316. }
  317. }
  318. cmakefileStream << " )\n\n";
  319. this->WriteMainCMakefileLanguageRules(cmakefileStream,
  320. this->LocalGenerators);
  321. if(!this->MultipleOutputPairs.empty())
  322. {
  323. cmakefileStream
  324. << "\n"
  325. << "SET(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
  326. for(MultipleOutputPairsType::const_iterator pi =
  327. this->MultipleOutputPairs.begin();
  328. pi != this->MultipleOutputPairs.end(); ++pi)
  329. {
  330. cmakefileStream << " \"" << pi->first << "\" \""
  331. << pi->second << "\"\n";
  332. }
  333. cmakefileStream << " )\n\n";
  334. }
  335. }
  336. //----------------------------------------------------------------------------
  337. void cmGlobalUnixMakefileGenerator3::CheckMultipleOutputs(cmMakefile* mf,
  338. bool verbose)
  339. {
  340. // Get the string listing the multiple output pairs.
  341. const char* pairs_string = mf->GetDefinition("CMAKE_MULTIPLE_OUTPUT_PAIRS");
  342. if(!pairs_string)
  343. {
  344. return;
  345. }
  346. // Convert the string to a list and preserve empty entries.
  347. std::vector<std::string> pairs;
  348. cmSystemTools::ExpandListArgument(pairs_string, pairs, true);
  349. for(std::vector<std::string>::const_iterator i = pairs.begin();
  350. i != pairs.end(); ++i)
  351. {
  352. const std::string& depender = *i;
  353. if(++i != pairs.end())
  354. {
  355. const std::string& dependee = *i;
  356. // If the depender is missing then delete the dependee to make
  357. // sure both will be regenerated.
  358. if(cmSystemTools::FileExists(dependee.c_str()) &&
  359. !cmSystemTools::FileExists(depender.c_str()))
  360. {
  361. if(verbose)
  362. {
  363. cmOStringStream msg;
  364. msg << "Deleting primary custom command output \"" << dependee
  365. << "\" because another output \""
  366. << depender << "\" does not exist." << std::endl;
  367. cmSystemTools::Stdout(msg.str().c_str());
  368. }
  369. cmSystemTools::RemoveFile(dependee.c_str());
  370. }
  371. }
  372. }
  373. }
  374. void cmGlobalUnixMakefileGenerator3
  375. ::WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
  376. std::vector<cmLocalGenerator *> &lGenerators
  377. )
  378. {
  379. cmLocalUnixMakefileGenerator3 *lg;
  380. // now list all the target info files
  381. cmakefileStream
  382. << "# The set of files whose dependency integrity should be checked:\n";
  383. cmakefileStream
  384. << "SET(CMAKE_DEPEND_INFO_FILES\n";
  385. for (unsigned int i = 0; i < lGenerators.size(); ++i)
  386. {
  387. lg = static_cast<cmLocalUnixMakefileGenerator3 *>(lGenerators[i]);
  388. // for all of out targets
  389. for (cmTargets::iterator l = lg->GetMakefile()->GetTargets().begin();
  390. l != lg->GetMakefile()->GetTargets().end(); l++)
  391. {
  392. if((l->second.GetType() == cmTarget::EXECUTABLE) ||
  393. (l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  394. (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  395. (l->second.GetType() == cmTarget::MODULE_LIBRARY) )
  396. {
  397. std::string tname = lg->GetRelativeTargetDirectory(l->second);
  398. tname += "/DependInfo.cmake";
  399. cmSystemTools::ConvertToUnixSlashes(tname);
  400. cmakefileStream << " \"" << tname.c_str() << "\"\n";
  401. }
  402. }
  403. }
  404. cmakefileStream << " )\n";
  405. }
  406. //----------------------------------------------------------------------------
  407. void
  408. cmGlobalUnixMakefileGenerator3
  409. ::WriteDirectoryRule2(std::ostream& ruleFileStream,
  410. cmLocalUnixMakefileGenerator3* lg,
  411. const char* pass, bool check_all,
  412. bool check_relink)
  413. {
  414. // Get the relative path to the subdirectory from the top.
  415. std::string makeTarget = lg->GetMakefile()->GetStartOutputDirectory();
  416. makeTarget += "/";
  417. makeTarget += pass;
  418. makeTarget = lg->Convert(makeTarget.c_str(),
  419. cmLocalGenerator::HOME_OUTPUT,
  420. cmLocalGenerator::MAKEFILE);
  421. // The directory-level rule should depend on the target-level rules
  422. // for all targets in the directory.
  423. std::vector<std::string> depends;
  424. for(cmTargets::iterator l = lg->GetMakefile()->GetTargets().begin();
  425. l != lg->GetMakefile()->GetTargets().end(); ++l)
  426. {
  427. if((l->second.GetType() == cmTarget::EXECUTABLE) ||
  428. (l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  429. (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  430. (l->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  431. (l->second.GetType() == cmTarget::UTILITY))
  432. {
  433. // Add this to the list of depends rules in this directory.
  434. if((!check_all || l->second.IsInAll()) &&
  435. (!check_relink || l->second.NeedRelinkBeforeInstall()))
  436. {
  437. std::string tname = lg->GetRelativeTargetDirectory(l->second);
  438. tname += "/";
  439. tname += pass;
  440. depends.push_back(tname);
  441. }
  442. }
  443. }
  444. // The directory-level rule should depend on the directory-level
  445. // rules of the subdirectories.
  446. for(std::vector<cmLocalGenerator*>::iterator sdi =
  447. lg->GetChildren().begin(); sdi != lg->GetChildren().end(); ++sdi)
  448. {
  449. cmLocalUnixMakefileGenerator3* slg =
  450. static_cast<cmLocalUnixMakefileGenerator3*>(*sdi);
  451. std::string subdir = slg->GetMakefile()->GetStartOutputDirectory();
  452. subdir += "/";
  453. subdir += pass;
  454. subdir = slg->Convert(subdir.c_str(),
  455. cmLocalGenerator::HOME_OUTPUT,
  456. cmLocalGenerator::MAKEFILE);
  457. depends.push_back(subdir);
  458. }
  459. // Work-around for makes that drop rules that have no dependencies
  460. // or commands.
  461. if(depends.empty() && this->EmptyRuleHackDepends != "")
  462. {
  463. depends.push_back(this->EmptyRuleHackDepends);
  464. }
  465. // Write the rule.
  466. std::string doc = "Convenience name for \"";
  467. doc += pass;
  468. doc += "\" pass in the directory.";
  469. std::vector<std::string> no_commands;
  470. lg->WriteMakeRule(ruleFileStream, doc.c_str(),
  471. makeTarget.c_str(), depends, no_commands, true);
  472. }
  473. //----------------------------------------------------------------------------
  474. void
  475. cmGlobalUnixMakefileGenerator3
  476. ::WriteDirectoryRules2(std::ostream& ruleFileStream,
  477. cmLocalUnixMakefileGenerator3* lg)
  478. {
  479. // Only subdirectories need these rules.
  480. if(!lg->GetParent())
  481. {
  482. return;
  483. }
  484. // Begin the directory-level rules section.
  485. std::string dir = lg->GetMakefile()->GetStartOutputDirectory();
  486. dir = lg->Convert(dir.c_str(), cmLocalGenerator::HOME_OUTPUT,
  487. cmLocalGenerator::MAKEFILE);
  488. lg->WriteDivider(ruleFileStream);
  489. ruleFileStream
  490. << "# Directory level rules for directory "
  491. << dir << "\n\n";
  492. // Write directory-level rules for "all".
  493. this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false);
  494. // Write directory-level rules for "clean".
  495. this->WriteDirectoryRule2(ruleFileStream, lg, "clean", false, false);
  496. // Write directory-level rules for "preinstall".
  497. this->WriteDirectoryRule2(ruleFileStream, lg, "preinstall", false, true);
  498. }
  499. std::string cmGlobalUnixMakefileGenerator3
  500. ::GenerateBuildCommand(const char* makeProgram, const char *projectName,
  501. const char* additionalOptions, const char *targetName,
  502. const char* config, bool ignoreErrors, bool fast)
  503. {
  504. // Project name and config are not used yet.
  505. (void)projectName;
  506. (void)config;
  507. std::string makeCommand =
  508. cmSystemTools::ConvertToUnixOutputPath(makeProgram);
  509. // Since we have full control over the invocation of nmake, let us
  510. // make it quiet.
  511. if ( strcmp(this->GetName(), "NMake Makefiles") == 0 )
  512. {
  513. makeCommand += " /NOLOGO ";
  514. }
  515. if ( ignoreErrors )
  516. {
  517. makeCommand += " -i";
  518. }
  519. if ( additionalOptions )
  520. {
  521. makeCommand += " ";
  522. makeCommand += additionalOptions;
  523. }
  524. if ( targetName && strlen(targetName))
  525. {
  526. cmLocalUnixMakefileGenerator3 *lg;
  527. if (this->LocalGenerators.size())
  528. {
  529. lg = static_cast<cmLocalUnixMakefileGenerator3 *>
  530. (this->LocalGenerators[0]);
  531. }
  532. else
  533. {
  534. lg = static_cast<cmLocalUnixMakefileGenerator3 *>
  535. (this->CreateLocalGenerator());
  536. // set the Start directories
  537. lg->GetMakefile()->SetStartDirectory
  538. (this->CMakeInstance->GetStartDirectory());
  539. lg->GetMakefile()->SetStartOutputDirectory
  540. (this->CMakeInstance->GetStartOutputDirectory());
  541. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  542. }
  543. lg->SetupPathConversions();
  544. makeCommand += " \"";
  545. std::string tname = targetName;
  546. if(fast)
  547. {
  548. tname += "/fast";
  549. }
  550. tname = lg->Convert(tname.c_str(),cmLocalGenerator::HOME_OUTPUT,
  551. cmLocalGenerator::MAKEFILE);
  552. tname = lg->ConvertToMakeTarget(tname.c_str());
  553. makeCommand += tname.c_str();
  554. makeCommand += "\"";
  555. if (!this->LocalGenerators.size())
  556. {
  557. delete lg;
  558. }
  559. }
  560. return makeCommand;
  561. }
  562. //----------------------------------------------------------------------------
  563. void
  564. cmGlobalUnixMakefileGenerator3
  565. ::WriteConvenienceRules(std::ostream& ruleFileStream,
  566. std::set<cmStdString> &emitted)
  567. {
  568. std::vector<std::string> depends;
  569. std::vector<std::string> commands;
  570. depends.push_back("cmake_check_build_system");
  571. // write the target convenience rules
  572. unsigned int i;
  573. cmLocalUnixMakefileGenerator3 *lg;
  574. for (i = 0; i < this->LocalGenerators.size(); ++i)
  575. {
  576. lg = static_cast<cmLocalUnixMakefileGenerator3 *>
  577. (this->LocalGenerators[i]);
  578. // for each target Generate the rule files for each target.
  579. cmTargets& targets = lg->GetMakefile()->GetTargets();
  580. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  581. {
  582. // Don't emit the same rule twice (e.g. two targets with the same
  583. // simple name)
  584. if(t->second.GetName() &&
  585. strlen(t->second.GetName()) &&
  586. emitted.insert(t->second.GetName()).second)
  587. {
  588. // Handle user targets here. Global targets are handled in
  589. // the local generator on a per-directory basis.
  590. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  591. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  592. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  593. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  594. (t->second.GetType() == cmTarget::UTILITY))
  595. {
  596. // Add a rule to build the target by name.
  597. lg->WriteDivider(ruleFileStream);
  598. ruleFileStream
  599. << "# Target rules for targets named "
  600. << t->second.GetName() << "\n\n";
  601. // Write the rule.
  602. commands.clear();
  603. std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
  604. tmp += "Makefile2";
  605. commands.push_back(lg->GetRecursiveMakeCall
  606. (tmp.c_str(),t->second.GetName()));
  607. depends.clear();
  608. depends.push_back("cmake_check_build_system");
  609. lg->WriteMakeRule(ruleFileStream,
  610. "Build rule for target.",
  611. t->second.GetName(), depends, commands,
  612. true);
  613. // Add a fast rule to build the target
  614. std::string localName = lg->GetRelativeTargetDirectory(t->second);
  615. std::string makefileName;
  616. makefileName = localName;
  617. makefileName += "/build.make";
  618. depends.clear();
  619. commands.clear();
  620. std::string makeTargetName = localName;
  621. makeTargetName += "/build";
  622. localName = t->second.GetName();
  623. localName += "/fast";
  624. commands.push_back(lg->GetRecursiveMakeCall
  625. (makefileName.c_str(), makeTargetName.c_str()));
  626. lg->WriteMakeRule(ruleFileStream, "fast build rule for target.",
  627. localName.c_str(), depends, commands, true);
  628. }
  629. }
  630. }
  631. }
  632. }
  633. //----------------------------------------------------------------------------
  634. void
  635. cmGlobalUnixMakefileGenerator3
  636. ::WriteConvenienceRules2(std::ostream& ruleFileStream,
  637. cmLocalUnixMakefileGenerator3 *lg,
  638. bool exclude)
  639. {
  640. std::vector<std::string> depends;
  641. std::vector<std::string> commands;
  642. std::string localName;
  643. std::string makeTargetName;
  644. // write the directory level rules for this local gen
  645. this->WriteDirectoryRules2(ruleFileStream,lg);
  646. depends.push_back("cmake_check_build_system");
  647. // for each target Generate the rule files for each target.
  648. cmTargets& targets = lg->GetMakefile()->GetTargets();
  649. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  650. {
  651. if (t->second.GetName() && strlen(t->second.GetName()))
  652. {
  653. std::string makefileName;
  654. // Add a rule to build the target by name.
  655. localName = lg->GetRelativeTargetDirectory(t->second);
  656. makefileName = localName;
  657. makefileName += "/build.make";
  658. if (((t->second.GetType() == cmTarget::EXECUTABLE) ||
  659. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  660. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  661. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  662. (t->second.GetType() == cmTarget::UTILITY)))
  663. {
  664. bool needRequiresStep =
  665. this->NeedRequiresStep(lg,t->second.GetName());
  666. lg->WriteDivider(ruleFileStream);
  667. ruleFileStream
  668. << "# Target rules for target "
  669. << localName << "\n\n";
  670. commands.clear();
  671. if (t->second.GetType() != cmTarget::UTILITY)
  672. {
  673. makeTargetName = localName;
  674. makeTargetName += "/depend";
  675. commands.push_back(lg->GetRecursiveMakeCall
  676. (makefileName.c_str(),makeTargetName.c_str()));
  677. // add requires if we need it for this generator
  678. if (needRequiresStep)
  679. {
  680. makeTargetName = localName;
  681. makeTargetName += "/requires";
  682. commands.push_back(lg->GetRecursiveMakeCall
  683. (makefileName.c_str(),makeTargetName.c_str()));
  684. }
  685. }
  686. makeTargetName = localName;
  687. makeTargetName += "/build";
  688. commands.push_back(lg->GetRecursiveMakeCall
  689. (makefileName.c_str(),makeTargetName.c_str()));
  690. // Write the rule.
  691. localName += "/all";
  692. depends.clear();
  693. std::string progressDir =
  694. lg->GetMakefile()->GetHomeOutputDirectory();
  695. progressDir += cmake::GetCMakeFilesDirectory();
  696. {
  697. cmOStringStream progCmd;
  698. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
  699. // all target counts
  700. progCmd << lg->Convert(progressDir.c_str(),
  701. cmLocalGenerator::FULL,
  702. cmLocalGenerator::SHELL);
  703. progCmd << " ";
  704. std::vector<int> &progFiles = lg->ProgressFiles[t->first];
  705. for (std::vector<int>::iterator i = progFiles.begin();
  706. i != progFiles.end(); ++i)
  707. {
  708. progCmd << " " << *i;
  709. }
  710. commands.push_back(progCmd.str());
  711. }
  712. progressDir = "Building target ";
  713. progressDir += t->first;
  714. lg->AppendEcho(commands,progressDir.c_str());
  715. this->AppendGlobalTargetDepends(depends,t->second);
  716. lg->WriteMakeRule(ruleFileStream, "All Build rule for target.",
  717. localName.c_str(), depends, commands, true);
  718. // add the all/all dependency
  719. if (!exclude && t->second.IsInAll())
  720. {
  721. depends.clear();
  722. depends.push_back(localName);
  723. commands.clear();
  724. lg->WriteMakeRule(ruleFileStream, "Include target in all.",
  725. "all", depends, commands, true);
  726. }
  727. // Write the rule.
  728. commands.clear();
  729. progressDir = lg->GetMakefile()->GetHomeOutputDirectory();
  730. progressDir += cmake::GetCMakeFilesDirectory();
  731. {
  732. // TODO: Convert the total progress count to a make variable.
  733. cmOStringStream progCmd;
  734. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
  735. // # in target
  736. progCmd << lg->Convert(progressDir.c_str(),
  737. cmLocalGenerator::FULL,
  738. cmLocalGenerator::SHELL);
  739. //
  740. progCmd << " "
  741. << this->GetTargetTotalNumberOfActions(t->second);
  742. commands.push_back(progCmd.str());
  743. }
  744. std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
  745. tmp += "Makefile2";
  746. commands.push_back(lg->GetRecursiveMakeCall
  747. (tmp.c_str(),localName.c_str()));
  748. {
  749. cmOStringStream progCmd;
  750. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
  751. progCmd << lg->Convert(progressDir.c_str(),
  752. cmLocalGenerator::FULL,
  753. cmLocalGenerator::SHELL);
  754. progCmd << " 0";
  755. commands.push_back(progCmd.str());
  756. }
  757. depends.clear();
  758. depends.push_back("cmake_check_build_system");
  759. localName = lg->GetRelativeTargetDirectory(t->second);
  760. localName += "/rule";
  761. lg->WriteMakeRule(ruleFileStream,
  762. "Build rule for subdir invocation for target.",
  763. localName.c_str(), depends, commands, true);
  764. // Add a target with the canonical name (no prefix, suffix or path).
  765. commands.clear();
  766. depends.clear();
  767. depends.push_back(localName);
  768. lg->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  769. t->second.GetName(), depends, commands, true);
  770. // Add rules to prepare the target for installation.
  771. if(t->second.NeedRelinkBeforeInstall())
  772. {
  773. localName = lg->GetRelativeTargetDirectory(t->second);
  774. localName += "/preinstall";
  775. depends.clear();
  776. commands.clear();
  777. commands.push_back(lg->GetRecursiveMakeCall
  778. (makefileName.c_str(), localName.c_str()));
  779. lg->WriteMakeRule(ruleFileStream,
  780. "Pre-install relink rule for target.",
  781. localName.c_str(), depends, commands, true);
  782. depends.clear();
  783. depends.push_back(localName);
  784. commands.clear();
  785. lg->WriteMakeRule(ruleFileStream, "Prepare target for install.",
  786. "preinstall", depends, commands, true);
  787. }
  788. // add the clean rule
  789. localName = lg->GetRelativeTargetDirectory(t->second);
  790. makeTargetName = localName;
  791. makeTargetName += "/clean";
  792. depends.clear();
  793. commands.clear();
  794. commands.push_back(lg->GetRecursiveMakeCall
  795. (makefileName.c_str(), makeTargetName.c_str()));
  796. lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
  797. makeTargetName.c_str(), depends, commands, true);
  798. commands.clear();
  799. depends.push_back(makeTargetName);
  800. lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
  801. "clean", depends, commands, true);
  802. }
  803. }
  804. }
  805. }
  806. //----------------------------------------------------------------------------
  807. int cmGlobalUnixMakefileGenerator3
  808. ::GetTargetTotalNumberOfActions(cmTarget& target)
  809. {
  810. cmLocalUnixMakefileGenerator3 *lg =
  811. static_cast<cmLocalUnixMakefileGenerator3 *>
  812. (target.GetMakefile()->GetLocalGenerator());
  813. int result = static_cast<int>(lg->ProgressFiles[target.GetName()].size());
  814. std::vector<cmTarget *>& depends = this->GetTargetDepends(target);
  815. std::vector<cmTarget *>::iterator i;
  816. for (i = depends.begin(); i != depends.end(); ++i)
  817. {
  818. result += this->GetTargetTotalNumberOfActions(**i);
  819. }
  820. return result;
  821. }
  822. unsigned long cmGlobalUnixMakefileGenerator3::
  823. GetNumberOfProgressActionsInAll(cmLocalUnixMakefileGenerator3 *lg)
  824. {
  825. unsigned long result = 0;
  826. // for every target in the top level all
  827. if (!lg->GetParent())
  828. {
  829. // loop over the generators and targets
  830. unsigned int i;
  831. cmLocalUnixMakefileGenerator3 *lg3;
  832. for (i = 0; i < this->LocalGenerators.size(); ++i)
  833. {
  834. lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>
  835. (this->LocalGenerators[i]);
  836. // for each target Generate the rule files for each target.
  837. cmTargets& targets = lg3->GetMakefile()->GetTargets();
  838. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  839. {
  840. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  841. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  842. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  843. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  844. (t->second.GetType() == cmTarget::UTILITY))
  845. {
  846. if (t->second.IsInAll())
  847. {
  848. std::vector<int> &progFiles = lg3->ProgressFiles[t->first];
  849. result += static_cast<unsigned long>(progFiles.size());
  850. }
  851. }
  852. }
  853. }
  854. }
  855. else
  856. {
  857. std::deque<cmLocalUnixMakefileGenerator3 *> lg3Stack;
  858. lg3Stack.push_back(lg);
  859. std::vector<cmStdString> targetsInAll;
  860. std::set<cmTarget *> targets;
  861. while (lg3Stack.size())
  862. {
  863. cmLocalUnixMakefileGenerator3 *lg3 = lg3Stack.front();
  864. lg3Stack.pop_front();
  865. for(cmTargets::iterator l = lg3->GetMakefile()->GetTargets().begin();
  866. l != lg3->GetMakefile()->GetTargets().end(); ++l)
  867. {
  868. if((l->second.GetType() == cmTarget::EXECUTABLE) ||
  869. (l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  870. (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  871. (l->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  872. (l->second.GetType() == cmTarget::UTILITY))
  873. {
  874. // Add this to the list of depends rules in this directory.
  875. if (l->second.IsInAll() &&
  876. targets.find(&l->second) == targets.end())
  877. {
  878. std::deque<cmTarget *> activeTgts;
  879. activeTgts.push_back(&(l->second));
  880. // trace depth of target dependencies
  881. while (activeTgts.size())
  882. {
  883. if (targets.find(activeTgts.front()) == targets.end())
  884. {
  885. targets.insert(activeTgts.front());
  886. cmLocalUnixMakefileGenerator3 *lg4 =
  887. static_cast<cmLocalUnixMakefileGenerator3 *>
  888. (activeTgts.front()->GetMakefile()->GetLocalGenerator());
  889. std::vector<int> &progFiles2 =
  890. lg4->ProgressFiles[activeTgts.front()->GetName()];
  891. result += progFiles2.size();
  892. std::vector<cmTarget *> deps2 =
  893. this->GetTargetDepends(*activeTgts.front());
  894. activeTgts.insert(activeTgts.end(),deps2.begin(),deps2.end());
  895. }
  896. activeTgts.pop_front();
  897. }
  898. }
  899. }
  900. }
  901. // The directory-level rule depends on the directory-level
  902. // rules of the subdirectories.
  903. for(std::vector<cmLocalGenerator*>::iterator sdi =
  904. lg3->GetChildren().begin(); sdi != lg3->GetChildren().end(); ++sdi)
  905. {
  906. cmLocalUnixMakefileGenerator3* slg =
  907. static_cast<cmLocalUnixMakefileGenerator3*>(*sdi);
  908. lg3Stack.push_back(slg);
  909. }
  910. }
  911. }
  912. return result;
  913. }
  914. //----------------------------------------------------------------------------
  915. std::vector<cmTarget *>& cmGlobalUnixMakefileGenerator3
  916. ::GetTargetDepends(cmTarget& target)
  917. {
  918. // if the depends are already in the map then return
  919. std::map<cmStdString, std::vector<cmTarget *> >::iterator tgtI =
  920. this->TargetDependencies.find(target.GetName());
  921. if (tgtI != this->TargetDependencies.end())
  922. {
  923. return tgtI->second;
  924. }
  925. // A target should not depend on itself.
  926. std::set<cmStdString> emitted;
  927. emitted.insert(target.GetName());
  928. // the vector of results
  929. std::vector<cmTarget *>& result =
  930. this->TargetDependencies[target.GetName()];
  931. // Loop over all library dependencies but not for static libs
  932. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  933. {
  934. const cmTarget::LinkLibraryVectorType& tlibs = target.GetLinkLibraries();
  935. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  936. lib != tlibs.end(); ++lib)
  937. {
  938. // Don't emit the same library twice for this target.
  939. if(emitted.insert(lib->first).second)
  940. {
  941. cmTarget *target2 =
  942. target.GetMakefile()->FindTarget(lib->first.c_str());
  943. // search each local generator until a match is found
  944. if (!target2)
  945. {
  946. target2 = this->FindTarget(0,lib->first.c_str());
  947. }
  948. // if a match was found then ...
  949. if (target2)
  950. {
  951. // Add this dependency.
  952. result.push_back(target2);
  953. }
  954. }
  955. }
  956. }
  957. // Loop over all utility dependencies.
  958. const std::set<cmStdString>& tutils = target.GetUtilities();
  959. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  960. util != tutils.end(); ++util)
  961. {
  962. // Don't emit the same utility twice for this target.
  963. if(emitted.insert(*util).second)
  964. {
  965. cmTarget *target2 = target.GetMakefile()->FindTarget(util->c_str());
  966. // search each local generator until a match is found
  967. if (!target2)
  968. {
  969. target2 = this->FindTarget(0,util->c_str());
  970. }
  971. // if a match was found then ...
  972. if (target2)
  973. {
  974. // Add this dependency.
  975. result.push_back(target2);
  976. }
  977. }
  978. }
  979. return result;
  980. }
  981. //----------------------------------------------------------------------------
  982. void
  983. cmGlobalUnixMakefileGenerator3
  984. ::AppendGlobalTargetDepends(std::vector<std::string>& depends,
  985. cmTarget& target)
  986. {
  987. // Keep track of dependencies already listed.
  988. std::set<cmStdString> emitted;
  989. // A target should not depend on itself.
  990. emitted.insert(target.GetName());
  991. // Loop over all library dependencies but not for static libs
  992. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  993. {
  994. const cmTarget::LinkLibraryVectorType& tlibs = target.GetLinkLibraries();
  995. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  996. lib != tlibs.end(); ++lib)
  997. {
  998. // Don't emit the same library twice for this target.
  999. if(emitted.insert(lib->first).second)
  1000. {
  1001. // Add this dependency.
  1002. this->AppendAnyGlobalDepend(depends, lib->first.c_str(),
  1003. emitted, target);
  1004. }
  1005. }
  1006. }
  1007. // Loop over all utility dependencies.
  1008. const std::set<cmStdString>& tutils = target.GetUtilities();
  1009. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  1010. util != tutils.end(); ++util)
  1011. {
  1012. // Don't emit the same utility twice for this target.
  1013. if(emitted.insert(*util).second)
  1014. {
  1015. // Add this dependency.
  1016. this->AppendAnyGlobalDepend(depends, util->c_str(), emitted, target);
  1017. }
  1018. }
  1019. }
  1020. //----------------------------------------------------------------------------
  1021. void
  1022. cmGlobalUnixMakefileGenerator3
  1023. ::AppendAnyGlobalDepend(std::vector<std::string>& depends, const char* name,
  1024. std::set<cmStdString>& emitted, cmTarget &target)
  1025. {
  1026. cmTarget *result;
  1027. cmLocalUnixMakefileGenerator3 *lg3;
  1028. // first check the same dir as the current target
  1029. lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>
  1030. (target.GetMakefile()->GetLocalGenerator());
  1031. result = target.GetMakefile()->FindTarget(name);
  1032. // search each local generator until a match is found
  1033. if (!result)
  1034. {
  1035. result = this->FindTarget(0,name);
  1036. if (result)
  1037. {
  1038. lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>
  1039. (result->GetMakefile()->GetLocalGenerator());
  1040. }
  1041. }
  1042. // if a match was found then ...
  1043. if (result)
  1044. {
  1045. std::string tgtName = lg3->GetRelativeTargetDirectory(*result);
  1046. tgtName += "/all";
  1047. depends.push_back(tgtName);
  1048. if(result->GetType() == cmTarget::STATIC_LIBRARY)
  1049. {
  1050. const cmTarget::LinkLibraryVectorType& tlibs
  1051. = result->GetLinkLibraries();
  1052. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  1053. lib != tlibs.end(); ++lib)
  1054. {
  1055. // Don't emit the same library twice for this target.
  1056. if(emitted.insert(lib->first).second)
  1057. {
  1058. // Add this dependency.
  1059. this->AppendAnyGlobalDepend(depends, lib->first.c_str(),
  1060. emitted, *result);
  1061. }
  1062. }
  1063. }
  1064. return;
  1065. }
  1066. }
  1067. //----------------------------------------------------------------------------
  1068. void cmGlobalUnixMakefileGenerator3::WriteHelpRule
  1069. (std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *lg)
  1070. {
  1071. // add the help target
  1072. std::string path;
  1073. std::vector<std::string> no_depends;
  1074. std::vector<std::string> commands;
  1075. lg->AppendEcho(commands,"The following are some of the valid targets "
  1076. "for this Makefile:");
  1077. lg->AppendEcho(commands,"... all (the default if no target is provided)");
  1078. lg->AppendEcho(commands,"... clean");
  1079. lg->AppendEcho(commands,"... depend");
  1080. // Keep track of targets already listed.
  1081. std::set<cmStdString> emittedTargets;
  1082. // for each local generator
  1083. unsigned int i;
  1084. cmLocalUnixMakefileGenerator3 *lg2;
  1085. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1086. {
  1087. lg2 =
  1088. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  1089. // for the passed in makefile or if this is the top Makefile wripte out
  1090. // the targets
  1091. if (lg2 == lg || !lg->GetParent())
  1092. {
  1093. // for each target Generate the rule files for each target.
  1094. cmTargets& targets = lg2->GetMakefile()->GetTargets();
  1095. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  1096. {
  1097. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  1098. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  1099. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  1100. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  1101. (t->second.GetType() == cmTarget::GLOBAL_TARGET) ||
  1102. (t->second.GetType() == cmTarget::UTILITY))
  1103. {
  1104. if(emittedTargets.insert(t->second.GetName()).second)
  1105. {
  1106. path = "... ";
  1107. path += t->second.GetName();
  1108. lg->AppendEcho(commands,path.c_str());
  1109. }
  1110. }
  1111. }
  1112. std::map<cmStdString,std::vector<cmTarget *> > const& objs =
  1113. lg->GetLocalObjectFiles();
  1114. for(std::map<cmStdString,std::vector<cmTarget *> >::const_iterator o =
  1115. objs.begin(); o != objs.end(); ++o)
  1116. {
  1117. path = "... ";
  1118. path += o->first;
  1119. lg->AppendEcho(commands, path.c_str());
  1120. }
  1121. }
  1122. }
  1123. lg->WriteMakeRule(ruleFileStream, "Help Target",
  1124. "help:",
  1125. no_depends, commands, true);
  1126. ruleFileStream << "\n\n";
  1127. }
  1128. bool cmGlobalUnixMakefileGenerator3
  1129. ::NeedRequiresStep(cmLocalUnixMakefileGenerator3 *lg,const char *name)
  1130. {
  1131. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  1132. checkSet = lg->GetIntegrityCheckSet()[name];
  1133. for(std::map<cmStdString,
  1134. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  1135. l = checkSet.begin(); l != checkSet.end(); ++l)
  1136. {
  1137. std::string name2 = "CMAKE_NEEDS_REQUIRES_STEP_";
  1138. name2 += l->first;
  1139. name2 += "_FLAG";
  1140. if(lg->GetMakefile()->GetDefinition(name2.c_str()))
  1141. {
  1142. return true;
  1143. }
  1144. }
  1145. return false;
  1146. }