cmGlobalUnixMakefileGenerator3.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 "cmGlobalCommonGenerator.h"
  13. #include "cmGlobalGeneratorFactory.h"
  14. class cmGeneratedFileStream;
  15. class cmMakefileTargetGenerator;
  16. class cmLocalUnixMakefileGenerator3;
  17. /** \class cmGlobalUnixMakefileGenerator3
  18. * \brief Write a Unix makefiles.
  19. *
  20. * cmGlobalUnixMakefileGenerator3 manages UNIX build process for a tree
  21. The basic approach of this generator is to produce Makefiles that will all
  22. be run with the current working directory set to the Home Output
  23. directory. The one exception to this is the subdirectory Makefiles which are
  24. created as a convenience and just cd up to the Home Output directory and
  25. invoke the main Makefiles.
  26. The make process starts with Makefile. Makefile should only contain the
  27. targets the user is likely to invoke directly from a make command line. No
  28. internal targets should be in this file. Makefile2 contains the internal
  29. targets that are required to make the process work.
  30. Makefile2 in turn will recursively make targets in the correct order. Each
  31. target has its own directory \<target\>.dir and its own makefile build.make in
  32. that directory. Also in that directory is a couple makefiles per source file
  33. used by the target. Typically these are named source.obj.build.make and
  34. source.obj.build.depend.make. The source.obj.build.make contains the rules
  35. for building, cleaning, and computing dependencies for the given source
  36. file. The build.depend.make contains additional dependencies that were
  37. computed during dependency scanning. An additional file called
  38. source.obj.depend is used as a marker to indicate when dependencies must be
  39. rescanned.
  40. Rules for custom commands follow the same model as rules for source files.
  41. */
  42. class cmGlobalUnixMakefileGenerator3 : public cmGlobalCommonGenerator
  43. {
  44. public:
  45. cmGlobalUnixMakefileGenerator3(cmake* cm);
  46. static cmGlobalGeneratorFactory* NewFactory()
  47. {
  48. return new cmGlobalGeneratorSimpleFactory<
  49. cmGlobalUnixMakefileGenerator3>();
  50. }
  51. ///! Get the name for the generator.
  52. std::string GetName() const CM_OVERRIDE
  53. {
  54. return cmGlobalUnixMakefileGenerator3::GetActualName();
  55. }
  56. static std::string GetActualName() { return "Unix Makefiles"; }
  57. /**
  58. * Utilized by the generator factory to determine if this generator
  59. * supports toolsets.
  60. */
  61. static bool SupportsToolset() { return false; }
  62. /**
  63. * Utilized by the generator factory to determine if this generator
  64. * supports platforms.
  65. */
  66. static bool SupportsPlatform() { return false; }
  67. /** Get the documentation entry for this generator. */
  68. static void GetDocumentation(cmDocumentationEntry& entry);
  69. cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) CM_OVERRIDE;
  70. /**
  71. * Try to determine system information such as shared library
  72. * extension, pthreads, byte order etc.
  73. */
  74. void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
  75. bool optional) CM_OVERRIDE;
  76. void Configure() CM_OVERRIDE;
  77. /**
  78. * Generate the all required files for building this project/tree. This
  79. * basically creates a series of LocalGenerators for each directory and
  80. * requests that they Generate.
  81. */
  82. void Generate() CM_OVERRIDE;
  83. void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
  84. std::vector<cmLocalGenerator*>&);
  85. // write out the help rule listing the valid targets
  86. void WriteHelpRule(std::ostream& ruleFileStream,
  87. cmLocalUnixMakefileGenerator3*);
  88. // write the top level target rules
  89. void WriteConvenienceRules(std::ostream& ruleFileStream,
  90. std::set<std::string>& emitted);
  91. /** Get the command to use for a target that has no rule. This is
  92. used for multiple output dependencies and for cmake_force. */
  93. std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; }
  94. /** Get the fake dependency to use when a rule has no real commands
  95. or dependencies. */
  96. std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
  97. // change the build command for speed
  98. void GenerateBuildCommand(std::vector<std::string>& makeCommand,
  99. const std::string& makeProgram,
  100. const std::string& projectName,
  101. const std::string& projectDir,
  102. const std::string& targetName,
  103. const std::string& config, bool fast, bool verbose,
  104. std::vector<std::string> const& makeOptions =
  105. std::vector<std::string>()) CM_OVERRIDE;
  106. /** Record per-target progress information. */
  107. void RecordTargetProgress(cmMakefileTargetGenerator* tg);
  108. void AddCXXCompileCommand(const std::string& sourceFile,
  109. const std::string& workingDirectory,
  110. const std::string& compileCommand);
  111. /** Does the make tool tolerate .NOTPARALLEL? */
  112. virtual bool AllowNotParallel() const { return true; }
  113. /** Does the make tool tolerate .DELETE_ON_ERROR? */
  114. virtual bool AllowDeleteOnError() const { return true; }
  115. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const CM_OVERRIDE;
  116. std::string IncludeDirective;
  117. bool DefineWindowsNULL;
  118. bool PassMakeflags;
  119. bool UnixCD;
  120. protected:
  121. void WriteMainMakefile2();
  122. void WriteMainCMakefile();
  123. void WriteConvenienceRules2(std::ostream& ruleFileStream,
  124. cmLocalUnixMakefileGenerator3*);
  125. void WriteDirectoryRule2(std::ostream& ruleFileStream,
  126. cmLocalUnixMakefileGenerator3* lg, const char* pass,
  127. bool check_all, bool check_relink);
  128. void WriteDirectoryRules2(std::ostream& ruleFileStream,
  129. cmLocalUnixMakefileGenerator3* lg);
  130. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  131. cmGeneratorTarget* target);
  132. // does this generator need a requires step for any of its targets
  133. bool NeedRequiresStep(cmGeneratorTarget const*);
  134. // Target name hooks for superclass.
  135. const char* GetAllTargetName() const CM_OVERRIDE { return "all"; }
  136. const char* GetInstallTargetName() const CM_OVERRIDE { return "install"; }
  137. const char* GetInstallLocalTargetName() const CM_OVERRIDE
  138. {
  139. return "install/local";
  140. }
  141. const char* GetInstallStripTargetName() const CM_OVERRIDE
  142. {
  143. return "install/strip";
  144. }
  145. const char* GetPreinstallTargetName() const CM_OVERRIDE
  146. {
  147. return "preinstall";
  148. }
  149. const char* GetTestTargetName() const CM_OVERRIDE { return "test"; }
  150. const char* GetPackageTargetName() const CM_OVERRIDE { return "package"; }
  151. const char* GetPackageSourceTargetName() const CM_OVERRIDE
  152. {
  153. return "package_source";
  154. }
  155. const char* GetEditCacheTargetName() const CM_OVERRIDE
  156. {
  157. return "edit_cache";
  158. }
  159. const char* GetRebuildCacheTargetName() const CM_OVERRIDE
  160. {
  161. return "rebuild_cache";
  162. }
  163. const char* GetCleanTargetName() const CM_OVERRIDE { return "clean"; }
  164. bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const CM_OVERRIDE { return true; }
  165. // Some make programs (Borland) do not keep a rule if there are no
  166. // dependencies or commands. This is a problem for creating rules
  167. // that might not do anything but might have other dependencies
  168. // added later. If non-empty this variable holds a fake dependency
  169. // that can be added.
  170. std::string EmptyRuleHackDepends;
  171. // Some make programs (Watcom) do not like rules with no commands.
  172. // If non-empty this variable holds a bogus command that may be put
  173. // in the rule to satisfy the make program.
  174. std::string EmptyRuleHackCommand;
  175. // Store per-target progress counters.
  176. struct TargetProgress
  177. {
  178. TargetProgress()
  179. : NumberOfActions(0)
  180. {
  181. }
  182. unsigned long NumberOfActions;
  183. std::string VariableFile;
  184. std::vector<unsigned long> Marks;
  185. void WriteProgressVariables(unsigned long total, unsigned long& current);
  186. };
  187. typedef std::map<cmGeneratorTarget const*, TargetProgress,
  188. cmGeneratorTarget::StrictTargetComparison>
  189. ProgressMapType;
  190. ProgressMapType ProgressMap;
  191. size_t CountProgressMarksInTarget(
  192. cmGeneratorTarget const* target,
  193. std::set<cmGeneratorTarget const*>& emitted);
  194. size_t CountProgressMarksInAll(cmLocalGenerator* lg);
  195. cmGeneratedFileStream* CommandDatabase;
  196. private:
  197. const char* GetBuildIgnoreErrorsFlag() const CM_OVERRIDE { return "-i"; }
  198. std::string GetEditCacheCommand() const CM_OVERRIDE;
  199. std::map<cmState::Snapshot, std::set<cmGeneratorTarget const*>,
  200. cmState::Snapshot::StrictWeakOrder>
  201. DirectoryTargetsMap;
  202. void InitializeProgressMarks() CM_OVERRIDE;
  203. };
  204. #endif