cmGlobalUnixMakefileGenerator3.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmGlobalUnixMakefileGenerator3_h
  11. #define cmGlobalUnixMakefileGenerator3_h
  12. #include "cmGlobalGenerator.h"
  13. class cmGeneratedFileStream;
  14. class cmMakefileTargetGenerator;
  15. class cmLocalUnixMakefileGenerator3;
  16. /** \class cmGlobalUnixMakefileGenerator3
  17. * \brief Write a Unix makefiles.
  18. *
  19. * cmGlobalUnixMakefileGenerator3 manages UNIX build process for a tree
  20. The basic approach of this generator is to produce Makefiles that will all
  21. be run with the current working directory set to the Home Output
  22. directory. The one exception to this is the subdirectory Makefiles which are
  23. created as a convenience and just cd up to the Home Output directory and
  24. invoke the main Makefiles.
  25. The make process starts with Makefile. Makefile should only contain the
  26. targets the user is likely to invoke directly from a make command line. No
  27. internal targets should be in this file. Makefile2 contains the internal
  28. targets that are required to make the process work.
  29. Makefile2 in turn will recursively make targets in the correct order. Each
  30. target has its own directory <target>.dir and its own makefile build.make in
  31. that directory. Also in that directory is a couple makefiles per source file
  32. used by the target. Typically these are named source.obj.build.make and
  33. source.obj.build.depend.make. The source.obj.build.make contains the rules
  34. for building, cleaning, and computing dependencies for the given source
  35. file. The build.depend.make contains additional dependencies that were
  36. computed during dependency scanning. An additional file called
  37. source.obj.depend is used as a marker to indicate when dependencies must be
  38. rescanned.
  39. Rules for custom commands follow the same model as rules for source files.
  40. */
  41. class cmGlobalUnixMakefileGenerator3 : public cmGlobalGenerator
  42. {
  43. public:
  44. cmGlobalUnixMakefileGenerator3();
  45. static cmGlobalGenerator* New() {
  46. return new cmGlobalUnixMakefileGenerator3; }
  47. ///! Get the name for the generator.
  48. virtual const char* GetName() const {
  49. return cmGlobalUnixMakefileGenerator3::GetActualName();}
  50. static const char* GetActualName() {return "Unix Makefiles";}
  51. /** Get the documentation entry for this generator. */
  52. virtual void GetDocumentation(cmDocumentationEntry& entry) const;
  53. ///! Create a local generator appropriate to this Global Generator3
  54. virtual cmLocalGenerator *CreateLocalGenerator();
  55. /**
  56. * Try to determine system infomation such as shared library
  57. * extension, pthreads, byte order etc.
  58. */
  59. virtual void EnableLanguage(std::vector<std::string>const& languages,
  60. cmMakefile *, bool optional);
  61. /**
  62. * Generate the all required files for building this project/tree. This
  63. * basically creates a series of LocalGenerators for each directory and
  64. * requests that they Generate.
  65. */
  66. virtual void Generate();
  67. void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
  68. std::vector<cmLocalGenerator *> &);
  69. // write out the help rule listing the valid targets
  70. void WriteHelpRule(std::ostream& ruleFileStream,
  71. cmLocalUnixMakefileGenerator3 *);
  72. // write the top lvel target rules
  73. void WriteConvenienceRules(std::ostream& ruleFileStream,
  74. std::set<cmStdString> &emitted);
  75. /** Get the command to use for a target that has no rule. This is
  76. used for multiple output dependencies and for cmake_force. */
  77. std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; }
  78. /** Get the fake dependency to use when a rule has no real commands
  79. or dependencies. */
  80. std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
  81. // change the build command for speed
  82. virtual std::string GenerateBuildCommand
  83. (const char* makeProgram,
  84. const char *projectName, const char* additionalOptions,
  85. const char *targetName,
  86. const char* config, bool ignoreErrors, bool fast);
  87. /** Record per-target progress information. */
  88. void RecordTargetProgress(cmMakefileTargetGenerator* tg);
  89. protected:
  90. void WriteMainMakefile2();
  91. void WriteMainCMakefile();
  92. void WriteConvenienceRules2(std::ostream& ruleFileStream,
  93. cmLocalUnixMakefileGenerator3*);
  94. void WriteDirectoryRule2(std::ostream& ruleFileStream,
  95. cmLocalUnixMakefileGenerator3* lg,
  96. const char* pass, bool check_all,
  97. bool check_relink);
  98. void WriteDirectoryRules2(std::ostream& ruleFileStream,
  99. cmLocalUnixMakefileGenerator3* lg);
  100. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  101. cmTarget& target);
  102. // does this generator need a requires step for any of its targets
  103. bool NeedRequiresStep(cmTarget const&);
  104. // Setup target names
  105. virtual const char* GetAllTargetName() { return "all"; }
  106. virtual const char* GetInstallTargetName() { return "install"; }
  107. virtual const char* GetInstallLocalTargetName() { return "install/local"; }
  108. virtual const char* GetInstallStripTargetName() { return "install/strip"; }
  109. virtual const char* GetPreinstallTargetName() { return "preinstall"; }
  110. virtual const char* GetTestTargetName() { return "test"; }
  111. virtual const char* GetPackageTargetName() { return "package"; }
  112. virtual const char* GetPackageSourceTargetName(){ return "package_source"; }
  113. virtual const char* GetEditCacheTargetName() { return "edit_cache"; }
  114. virtual const char* GetRebuildCacheTargetName() { return "rebuild_cache"; }
  115. virtual const char* GetCleanTargetName() { return "clean"; }
  116. virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
  117. // Some make programs (Borland) do not keep a rule if there are no
  118. // dependencies or commands. This is a problem for creating rules
  119. // that might not do anything but might have other dependencies
  120. // added later. If non-empty this variable holds a fake dependency
  121. // that can be added.
  122. std::string EmptyRuleHackDepends;
  123. // Some make programs (Watcom) do not like rules with no commands.
  124. // If non-empty this variable holds a bogus command that may be put
  125. // in the rule to satisfy the make program.
  126. std::string EmptyRuleHackCommand;
  127. bool NoRuleMessages;
  128. // Store per-target progress counters.
  129. struct TargetProgress
  130. {
  131. TargetProgress(): NumberOfActions(0) {}
  132. unsigned long NumberOfActions;
  133. std::string VariableFile;
  134. std::vector<unsigned long> Marks;
  135. void WriteProgressVariables(unsigned long total, unsigned long& current);
  136. };
  137. struct ProgressMapCompare { bool operator()(cmTarget*,cmTarget*) const; };
  138. typedef std::map<cmTarget*, TargetProgress,
  139. ProgressMapCompare> ProgressMapType;
  140. ProgressMapType ProgressMap;
  141. size_t CountProgressMarksInTarget(cmTarget* target,
  142. std::set<cmTarget*>& emitted);
  143. size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
  144. };
  145. #endif