cmGlobalUnixMakefileGenerator3.h 8.9 KB

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