cmGlobalUnixMakefileGenerator3.cxx 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  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.GetPropertyAsBool("EXCLUDE_FROM_ALL")) &&
  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. makeCommand += " \"";
  537. std::string tname = targetName;
  538. if(fast)
  539. {
  540. tname += "/fast";
  541. }
  542. tname = lg->Convert(tname.c_str(),cmLocalGenerator::HOME_OUTPUT,
  543. cmLocalGenerator::MAKEFILE);
  544. makeCommand += tname.c_str();
  545. makeCommand += "\"";
  546. if (!this->LocalGenerators.size())
  547. {
  548. delete lg;
  549. }
  550. }
  551. return makeCommand;
  552. }
  553. //----------------------------------------------------------------------------
  554. void
  555. cmGlobalUnixMakefileGenerator3
  556. ::WriteConvenienceRules(std::ostream& ruleFileStream,
  557. std::set<cmStdString> &emitted)
  558. {
  559. std::vector<std::string> depends;
  560. std::vector<std::string> commands;
  561. depends.push_back("cmake_check_build_system");
  562. // write the target convenience rules
  563. unsigned int i;
  564. cmLocalUnixMakefileGenerator3 *lg;
  565. for (i = 0; i < this->LocalGenerators.size(); ++i)
  566. {
  567. lg = static_cast<cmLocalUnixMakefileGenerator3 *>
  568. (this->LocalGenerators[i]);
  569. // for each target Generate the rule files for each target.
  570. cmTargets& targets = lg->GetMakefile()->GetTargets();
  571. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  572. {
  573. // Don't emit the same rule twice (e.g. two targets with the same
  574. // simple name)
  575. if(t->second.GetName() &&
  576. strlen(t->second.GetName()) &&
  577. emitted.insert(t->second.GetName()).second)
  578. {
  579. // Handle user targets here. Global targets are handled in
  580. // the local generator on a per-directory basis.
  581. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  582. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  583. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  584. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  585. (t->second.GetType() == cmTarget::UTILITY))
  586. {
  587. // Add a rule to build the target by name.
  588. lg->WriteDivider(ruleFileStream);
  589. ruleFileStream
  590. << "# Target rules for targets named "
  591. << t->second.GetName() << "\n\n";
  592. // Write the rule.
  593. commands.clear();
  594. std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
  595. tmp += "Makefile2";
  596. commands.push_back(lg->GetRecursiveMakeCall
  597. (tmp.c_str(),t->second.GetName()));
  598. depends.clear();
  599. depends.push_back("cmake_check_build_system");
  600. lg->WriteMakeRule(ruleFileStream,
  601. "Build rule for target.",
  602. t->second.GetName(), depends, commands,
  603. true);
  604. // Add a fast rule to build the target
  605. std::string localName = lg->GetRelativeTargetDirectory(t->second);
  606. std::string makefileName;
  607. makefileName = localName;
  608. makefileName += "/build.make";
  609. depends.clear();
  610. commands.clear();
  611. std::string makeTargetName = localName;
  612. makeTargetName += "/build";
  613. localName = t->second.GetName();
  614. localName += "/fast";
  615. commands.push_back(lg->GetRecursiveMakeCall
  616. (makefileName.c_str(), makeTargetName.c_str()));
  617. lg->WriteMakeRule(ruleFileStream, "fast build rule for target.",
  618. localName.c_str(), depends, commands, true);
  619. }
  620. }
  621. }
  622. }
  623. }
  624. //----------------------------------------------------------------------------
  625. void
  626. cmGlobalUnixMakefileGenerator3
  627. ::WriteConvenienceRules2(std::ostream& ruleFileStream,
  628. cmLocalUnixMakefileGenerator3 *lg,
  629. bool exclude)
  630. {
  631. std::vector<std::string> depends;
  632. std::vector<std::string> commands;
  633. std::string localName;
  634. std::string makeTargetName;
  635. // write the directory level rules for this local gen
  636. this->WriteDirectoryRules2(ruleFileStream,lg);
  637. depends.push_back("cmake_check_build_system");
  638. // for each target Generate the rule files for each target.
  639. cmTargets& targets = lg->GetMakefile()->GetTargets();
  640. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  641. {
  642. if (t->second.GetName() && strlen(t->second.GetName()))
  643. {
  644. std::string makefileName;
  645. // Add a rule to build the target by name.
  646. localName = lg->GetRelativeTargetDirectory(t->second);
  647. makefileName = localName;
  648. makefileName += "/build.make";
  649. if (((t->second.GetType() == cmTarget::EXECUTABLE) ||
  650. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  651. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  652. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  653. (t->second.GetType() == cmTarget::UTILITY)))
  654. {
  655. bool needRequiresStep =
  656. this->NeedRequiresStep(lg,t->second.GetName());
  657. lg->WriteDivider(ruleFileStream);
  658. ruleFileStream
  659. << "# Target rules for target "
  660. << localName << "\n\n";
  661. commands.clear();
  662. if (t->second.GetType() != cmTarget::UTILITY)
  663. {
  664. makeTargetName = localName;
  665. makeTargetName += "/depend";
  666. commands.push_back(lg->GetRecursiveMakeCall
  667. (makefileName.c_str(),makeTargetName.c_str()));
  668. // add requires if we need it for this generator
  669. if (needRequiresStep)
  670. {
  671. makeTargetName = localName;
  672. makeTargetName += "/requires";
  673. commands.push_back(lg->GetRecursiveMakeCall
  674. (makefileName.c_str(),makeTargetName.c_str()));
  675. }
  676. }
  677. makeTargetName = localName;
  678. makeTargetName += "/build";
  679. commands.push_back(lg->GetRecursiveMakeCall
  680. (makefileName.c_str(),makeTargetName.c_str()));
  681. // Write the rule.
  682. localName += "/all";
  683. depends.clear();
  684. std::string progressDir =
  685. lg->GetMakefile()->GetHomeOutputDirectory();
  686. progressDir += cmake::GetCMakeFilesDirectory();
  687. {
  688. cmOStringStream progCmd;
  689. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
  690. // all target counts
  691. progCmd << lg->Convert(progressDir.c_str(),
  692. cmLocalGenerator::FULL,
  693. cmLocalGenerator::SHELL);
  694. progCmd << " ";
  695. std::vector<int> &progFiles = lg->ProgressFiles[t->first];
  696. for (std::vector<int>::iterator i = progFiles.begin();
  697. i != progFiles.end(); ++i)
  698. {
  699. progCmd << " " << *i;
  700. }
  701. commands.push_back(progCmd.str());
  702. }
  703. progressDir = "Built target ";
  704. progressDir += t->first;
  705. lg->AppendEcho(commands,progressDir.c_str());
  706. this->AppendGlobalTargetDepends(depends,t->second);
  707. lg->WriteMakeRule(ruleFileStream, "All Build rule for target.",
  708. localName.c_str(), depends, commands, true);
  709. // add the all/all dependency
  710. if (!exclude && !t->second.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  711. {
  712. depends.clear();
  713. depends.push_back(localName);
  714. commands.clear();
  715. lg->WriteMakeRule(ruleFileStream, "Include target in all.",
  716. "all", depends, commands, true);
  717. }
  718. // Write the rule.
  719. commands.clear();
  720. progressDir = lg->GetMakefile()->GetHomeOutputDirectory();
  721. progressDir += cmake::GetCMakeFilesDirectory();
  722. {
  723. // TODO: Convert the total progress count to a make variable.
  724. cmOStringStream progCmd;
  725. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
  726. // # in target
  727. progCmd << lg->Convert(progressDir.c_str(),
  728. cmLocalGenerator::FULL,
  729. cmLocalGenerator::SHELL);
  730. //
  731. std::set<cmStdString> emitted;
  732. progCmd << " "
  733. << this->GetTargetTotalNumberOfActions(t->second,
  734. emitted);
  735. commands.push_back(progCmd.str());
  736. }
  737. std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
  738. tmp += "Makefile2";
  739. commands.push_back(lg->GetRecursiveMakeCall
  740. (tmp.c_str(),localName.c_str()));
  741. {
  742. cmOStringStream progCmd;
  743. progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
  744. progCmd << lg->Convert(progressDir.c_str(),
  745. cmLocalGenerator::FULL,
  746. cmLocalGenerator::SHELL);
  747. progCmd << " 0";
  748. commands.push_back(progCmd.str());
  749. }
  750. depends.clear();
  751. depends.push_back("cmake_check_build_system");
  752. localName = lg->GetRelativeTargetDirectory(t->second);
  753. localName += "/rule";
  754. lg->WriteMakeRule(ruleFileStream,
  755. "Build rule for subdir invocation for target.",
  756. localName.c_str(), depends, commands, true);
  757. // Add a target with the canonical name (no prefix, suffix or path).
  758. commands.clear();
  759. depends.clear();
  760. depends.push_back(localName);
  761. lg->WriteMakeRule(ruleFileStream, "Convenience name for target.",
  762. t->second.GetName(), depends, commands, true);
  763. // Add rules to prepare the target for installation.
  764. if(t->second.NeedRelinkBeforeInstall())
  765. {
  766. localName = lg->GetRelativeTargetDirectory(t->second);
  767. localName += "/preinstall";
  768. depends.clear();
  769. commands.clear();
  770. commands.push_back(lg->GetRecursiveMakeCall
  771. (makefileName.c_str(), localName.c_str()));
  772. lg->WriteMakeRule(ruleFileStream,
  773. "Pre-install relink rule for target.",
  774. localName.c_str(), depends, commands, true);
  775. depends.clear();
  776. depends.push_back(localName);
  777. commands.clear();
  778. lg->WriteMakeRule(ruleFileStream, "Prepare target for install.",
  779. "preinstall", depends, commands, true);
  780. }
  781. // add the clean rule
  782. localName = lg->GetRelativeTargetDirectory(t->second);
  783. makeTargetName = localName;
  784. makeTargetName += "/clean";
  785. depends.clear();
  786. commands.clear();
  787. commands.push_back(lg->GetRecursiveMakeCall
  788. (makefileName.c_str(), makeTargetName.c_str()));
  789. lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
  790. makeTargetName.c_str(), depends, commands, true);
  791. commands.clear();
  792. depends.push_back(makeTargetName);
  793. lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
  794. "clean", depends, commands, true);
  795. }
  796. }
  797. }
  798. }
  799. //----------------------------------------------------------------------------
  800. int cmGlobalUnixMakefileGenerator3
  801. ::GetTargetTotalNumberOfActions(cmTarget& target,
  802. std::set<cmStdString> &emitted)
  803. {
  804. // do not double count
  805. int result = 0;
  806. if(emitted.insert(target.GetName()).second)
  807. {
  808. cmLocalUnixMakefileGenerator3 *lg =
  809. static_cast<cmLocalUnixMakefileGenerator3 *>
  810. (target.GetMakefile()->GetLocalGenerator());
  811. result = static_cast<int>(lg->ProgressFiles[target.GetName()].size());
  812. std::vector<cmTarget *>& depends = this->GetTargetDepends(target);
  813. std::vector<cmTarget *>::iterator i;
  814. for (i = depends.begin(); i != depends.end(); ++i)
  815. {
  816. result += this->GetTargetTotalNumberOfActions(**i, emitted);
  817. }
  818. }
  819. return result;
  820. }
  821. unsigned long cmGlobalUnixMakefileGenerator3
  822. ::GetNumberOfProgressActionsInAll(cmLocalUnixMakefileGenerator3 *lg)
  823. {
  824. unsigned long result = 0;
  825. // for every target in the top level all
  826. if (!lg->GetParent())
  827. {
  828. // use the new project to target map
  829. std::set<cmTarget*> &targets =
  830. this->ProjectToTargetMap[lg->GetMakefile()->GetProjectName()];
  831. std::set<cmTarget*>::iterator t = targets.begin();
  832. for(; t != targets.end(); ++t)
  833. {
  834. cmTarget* target = *t;
  835. cmLocalUnixMakefileGenerator3 *lg3 =
  836. static_cast<cmLocalUnixMakefileGenerator3 *>
  837. (target->GetMakefile()->GetLocalGenerator());
  838. std::vector<int> &progFiles = lg3->ProgressFiles[target->GetName()];
  839. result += static_cast<unsigned long>(progFiles.size());
  840. }
  841. }
  842. // for subdirectories
  843. else
  844. {
  845. std::deque<cmLocalUnixMakefileGenerator3 *> lg3Stack;
  846. lg3Stack.push_back(lg);
  847. std::vector<cmStdString> targetsInAll;
  848. std::set<cmTarget *> targets;
  849. while (lg3Stack.size())
  850. {
  851. cmLocalUnixMakefileGenerator3 *lg3 = lg3Stack.front();
  852. lg3Stack.pop_front();
  853. for(cmTargets::iterator l = lg3->GetMakefile()->GetTargets().begin();
  854. l != lg3->GetMakefile()->GetTargets().end(); ++l)
  855. {
  856. if((l->second.GetType() == cmTarget::EXECUTABLE) ||
  857. (l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  858. (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  859. (l->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  860. (l->second.GetType() == cmTarget::UTILITY))
  861. {
  862. // Add this to the list of depends rules in this directory.
  863. if (!l->second.GetPropertyAsBool("EXCLUDE_FROM_ALL") &&
  864. targets.find(&l->second) == targets.end())
  865. {
  866. std::deque<cmTarget *> activeTgts;
  867. activeTgts.push_back(&(l->second));
  868. // trace depth of target dependencies
  869. while (activeTgts.size())
  870. {
  871. if (targets.find(activeTgts.front()) == targets.end())
  872. {
  873. targets.insert(activeTgts.front());
  874. cmLocalUnixMakefileGenerator3 *lg4 =
  875. static_cast<cmLocalUnixMakefileGenerator3 *>
  876. (activeTgts.front()->GetMakefile()->GetLocalGenerator());
  877. std::vector<int> &progFiles2 =
  878. lg4->ProgressFiles[activeTgts.front()->GetName()];
  879. result += static_cast<unsigned long>(progFiles2.size());
  880. std::vector<cmTarget *> deps2 =
  881. this->GetTargetDepends(*activeTgts.front());
  882. for (std::vector<cmTarget *>::const_iterator di =
  883. deps2.begin(); di != deps2.end(); ++di)
  884. {
  885. activeTgts.push_back(*di);
  886. }
  887. }
  888. activeTgts.pop_front();
  889. }
  890. }
  891. }
  892. }
  893. // The directory-level rule depends on the directory-level
  894. // rules of the subdirectories.
  895. for(std::vector<cmLocalGenerator*>::iterator sdi =
  896. lg3->GetChildren().begin();
  897. sdi != lg3->GetChildren().end(); ++sdi)
  898. {
  899. cmLocalUnixMakefileGenerator3* slg =
  900. static_cast<cmLocalUnixMakefileGenerator3*>(*sdi);
  901. lg3Stack.push_back(slg);
  902. }
  903. }
  904. }
  905. return result;
  906. }
  907. //----------------------------------------------------------------------------
  908. std::vector<cmTarget *>& cmGlobalUnixMakefileGenerator3
  909. ::GetTargetDepends(cmTarget& target)
  910. {
  911. // if the depends are already in the map then return
  912. std::map<cmStdString, std::vector<cmTarget *> >::iterator tgtI =
  913. this->TargetDependencies.find(target.GetName());
  914. if (tgtI != this->TargetDependencies.end())
  915. {
  916. return tgtI->second;
  917. }
  918. // A target should not depend on itself.
  919. std::set<cmStdString> emitted;
  920. emitted.insert(target.GetName());
  921. // the vector of results
  922. std::vector<cmTarget *>& result =
  923. this->TargetDependencies[target.GetName()];
  924. // Loop over all library dependencies but not for static libs
  925. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  926. {
  927. const cmTarget::LinkLibraryVectorType& tlibs = target.GetLinkLibraries();
  928. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  929. lib != tlibs.end(); ++lib)
  930. {
  931. // Don't emit the same library twice for this target.
  932. if(emitted.insert(lib->first).second)
  933. {
  934. cmTarget *target2 =
  935. target.GetMakefile()->FindTarget(lib->first.c_str());
  936. // search each local generator until a match is found
  937. if (!target2)
  938. {
  939. target2 = this->FindTarget(0,lib->first.c_str());
  940. }
  941. // if a match was found then ...
  942. if (target2)
  943. {
  944. // Add this dependency.
  945. result.push_back(target2);
  946. }
  947. }
  948. }
  949. }
  950. // Loop over all utility dependencies.
  951. const std::set<cmStdString>& tutils = target.GetUtilities();
  952. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  953. util != tutils.end(); ++util)
  954. {
  955. // Don't emit the same utility twice for this target.
  956. if(emitted.insert(*util).second)
  957. {
  958. cmTarget *target2 = target.GetMakefile()->FindTarget(util->c_str());
  959. // search each local generator until a match is found
  960. if (!target2)
  961. {
  962. target2 = this->FindTarget(0,util->c_str());
  963. }
  964. // if a match was found then ...
  965. if (target2)
  966. {
  967. // Add this dependency.
  968. result.push_back(target2);
  969. }
  970. }
  971. }
  972. return result;
  973. }
  974. //----------------------------------------------------------------------------
  975. void
  976. cmGlobalUnixMakefileGenerator3
  977. ::AppendGlobalTargetDepends(std::vector<std::string>& depends,
  978. cmTarget& target)
  979. {
  980. // Keep track of dependencies already listed.
  981. std::set<cmStdString> emitted;
  982. // A target should not depend on itself.
  983. emitted.insert(target.GetName());
  984. // Loop over all library dependencies but not for static libs
  985. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  986. {
  987. const cmTarget::LinkLibraryVectorType& tlibs = target.GetLinkLibraries();
  988. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  989. lib != tlibs.end(); ++lib)
  990. {
  991. // Don't emit the same library twice for this target.
  992. if(emitted.insert(lib->first).second)
  993. {
  994. // Add this dependency.
  995. this->AppendAnyGlobalDepend(depends, lib->first.c_str(),
  996. emitted, target);
  997. }
  998. }
  999. }
  1000. // Loop over all utility dependencies.
  1001. const std::set<cmStdString>& tutils = target.GetUtilities();
  1002. for(std::set<cmStdString>::const_iterator util = tutils.begin();
  1003. util != tutils.end(); ++util)
  1004. {
  1005. // Don't emit the same utility twice for this target.
  1006. if(emitted.insert(*util).second)
  1007. {
  1008. // Add this dependency.
  1009. this->AppendAnyGlobalDepend(depends, util->c_str(), emitted, target);
  1010. }
  1011. }
  1012. }
  1013. //----------------------------------------------------------------------------
  1014. void
  1015. cmGlobalUnixMakefileGenerator3
  1016. ::AppendAnyGlobalDepend(std::vector<std::string>& depends, const char* name,
  1017. std::set<cmStdString>& emitted, cmTarget &target)
  1018. {
  1019. cmTarget *result;
  1020. cmLocalUnixMakefileGenerator3 *lg3;
  1021. // first check the same dir as the current target
  1022. lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>
  1023. (target.GetMakefile()->GetLocalGenerator());
  1024. result = target.GetMakefile()->FindTarget(name);
  1025. // search each local generator until a match is found
  1026. if (!result)
  1027. {
  1028. result = this->FindTarget(0,name);
  1029. if (result)
  1030. {
  1031. lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>
  1032. (result->GetMakefile()->GetLocalGenerator());
  1033. }
  1034. }
  1035. // if a match was found then ...
  1036. if (result)
  1037. {
  1038. std::string tgtName = lg3->GetRelativeTargetDirectory(*result);
  1039. tgtName += "/all";
  1040. depends.push_back(tgtName);
  1041. if(result->GetType() == cmTarget::STATIC_LIBRARY)
  1042. {
  1043. // Since the static library itself does not list dependencies we
  1044. // need to chain its dependencies here.
  1045. const cmTarget::LinkLibraryVectorType& tlibs
  1046. = result->GetLinkLibraries();
  1047. for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
  1048. lib != tlibs.end(); ++lib)
  1049. {
  1050. // Don't emit the same library twice for this target.
  1051. if(emitted.insert(lib->first).second)
  1052. {
  1053. // Add this dependency.
  1054. this->AppendAnyGlobalDepend(depends, lib->first.c_str(),
  1055. emitted, *result);
  1056. }
  1057. }
  1058. }
  1059. return;
  1060. }
  1061. }
  1062. //----------------------------------------------------------------------------
  1063. void cmGlobalUnixMakefileGenerator3::WriteHelpRule
  1064. (std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *lg)
  1065. {
  1066. // add the help target
  1067. std::string path;
  1068. std::vector<std::string> no_depends;
  1069. std::vector<std::string> commands;
  1070. lg->AppendEcho(commands,"The following are some of the valid targets "
  1071. "for this Makefile:");
  1072. lg->AppendEcho(commands,"... all (the default if no target is provided)");
  1073. lg->AppendEcho(commands,"... clean");
  1074. lg->AppendEcho(commands,"... depend");
  1075. // Keep track of targets already listed.
  1076. std::set<cmStdString> emittedTargets;
  1077. // for each local generator
  1078. unsigned int i;
  1079. cmLocalUnixMakefileGenerator3 *lg2;
  1080. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1081. {
  1082. lg2 =
  1083. static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
  1084. // for the passed in makefile or if this is the top Makefile wripte out
  1085. // the targets
  1086. if (lg2 == lg || !lg->GetParent())
  1087. {
  1088. // for each target Generate the rule files for each target.
  1089. cmTargets& targets = lg2->GetMakefile()->GetTargets();
  1090. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  1091. {
  1092. if((t->second.GetType() == cmTarget::EXECUTABLE) ||
  1093. (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
  1094. (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
  1095. (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
  1096. (t->second.GetType() == cmTarget::GLOBAL_TARGET) ||
  1097. (t->second.GetType() == cmTarget::UTILITY))
  1098. {
  1099. if(emittedTargets.insert(t->second.GetName()).second)
  1100. {
  1101. path = "... ";
  1102. path += t->second.GetName();
  1103. lg->AppendEcho(commands,path.c_str());
  1104. }
  1105. }
  1106. }
  1107. std::vector<cmStdString> const& localHelp = lg->GetLocalHelp();
  1108. for(std::vector<cmStdString>::const_iterator o = localHelp.begin();
  1109. o != localHelp.end(); ++o)
  1110. {
  1111. path = "... ";
  1112. path += *o;
  1113. lg->AppendEcho(commands, path.c_str());
  1114. }
  1115. }
  1116. }
  1117. lg->WriteMakeRule(ruleFileStream, "Help Target",
  1118. "help:",
  1119. no_depends, commands, true);
  1120. ruleFileStream << "\n\n";
  1121. }
  1122. bool cmGlobalUnixMakefileGenerator3
  1123. ::NeedRequiresStep(cmLocalUnixMakefileGenerator3 *lg,const char *name)
  1124. {
  1125. std::map<cmStdString,cmLocalUnixMakefileGenerator3::IntegrityCheckSet>&
  1126. checkSet = lg->GetIntegrityCheckSet()[name];
  1127. for(std::map<cmStdString,
  1128. cmLocalUnixMakefileGenerator3::IntegrityCheckSet>::const_iterator
  1129. l = checkSet.begin(); l != checkSet.end(); ++l)
  1130. {
  1131. std::string name2 = "CMAKE_NEEDS_REQUIRES_STEP_";
  1132. name2 += l->first;
  1133. name2 += "_FLAG";
  1134. if(lg->GetMakefile()->GetDefinition(name2.c_str()))
  1135. {
  1136. return true;
  1137. }
  1138. }
  1139. return false;
  1140. }