cmGlobalUnixMakefileGenerator3.cxx 43 KB

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