cmGlobalUnixMakefileGenerator3.cxx 43 KB

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