cmGlobalUnixMakefileGenerator3.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. return new cmGlobalGeneratorSimpleFactory
  48. <cmGlobalUnixMakefileGenerator3>(); }
  49. ///! Get the name for the generator.
  50. virtual std::string GetName() const {
  51. return cmGlobalUnixMakefileGenerator3::GetActualName();}
  52. static std::string GetActualName() {return "Unix Makefiles";}
  53. /** Get the documentation entry for this generator. */
  54. static void GetDocumentation(cmDocumentationEntry& entry);
  55. ///! Create a local generator appropriate to this Global Generator3
  56. virtual cmLocalGenerator *CreateLocalGenerator(cmState::Snapshot snapshot);
  57. /**
  58. * Try to determine system information such as shared library
  59. * extension, pthreads, byte order etc.
  60. */
  61. virtual void EnableLanguage(std::vector<std::string>const& languages,
  62. cmMakefile *, bool optional);
  63. virtual void Configure();
  64. /**
  65. * Generate the all required files for building this project/tree. This
  66. * basically creates a series of LocalGenerators for each directory and
  67. * requests that they Generate.
  68. */
  69. virtual void Generate();
  70. void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
  71. std::vector<cmLocalGenerator *> &);
  72. // write out the help rule listing the valid targets
  73. void WriteHelpRule(std::ostream& ruleFileStream,
  74. cmLocalUnixMakefileGenerator3 *);
  75. // write the top level target rules
  76. void WriteConvenienceRules(std::ostream& ruleFileStream,
  77. std::set<std::string> &emitted);
  78. /** Get the command to use for a target that has no rule. This is
  79. used for multiple output dependencies and for cmake_force. */
  80. std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; }
  81. /** Get the fake dependency to use when a rule has no real commands
  82. or dependencies. */
  83. std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
  84. // change the build command for speed
  85. virtual void GenerateBuildCommand(
  86. std::vector<std::string>& makeCommand,
  87. const std::string& makeProgram,
  88. const std::string& projectName,
  89. const std::string& projectDir,
  90. const std::string& targetName,
  91. const std::string& config,
  92. bool fast, bool verbose,
  93. std::vector<std::string> const& makeOptions = std::vector<std::string>()
  94. );
  95. /** Record per-target progress information. */
  96. void RecordTargetProgress(cmMakefileTargetGenerator* tg);
  97. void AddCXXCompileCommand(const std::string &sourceFile,
  98. const std::string &workingDirectory,
  99. const std::string &compileCommand);
  100. /** Does the make tool tolerate .NOTPARALLEL? */
  101. virtual bool AllowNotParallel() const { return true; }
  102. /** Does the make tool tolerate .DELETE_ON_ERROR? */
  103. virtual bool AllowDeleteOnError() const { return true; }
  104. virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
  105. std::string IncludeDirective;
  106. bool DefineWindowsNULL;
  107. bool PassMakeflags;
  108. bool UnixCD;
  109. protected:
  110. void WriteMainMakefile2();
  111. void WriteMainCMakefile();
  112. void WriteConvenienceRules2(std::ostream& ruleFileStream,
  113. cmLocalUnixMakefileGenerator3*);
  114. void WriteDirectoryRule2(std::ostream& ruleFileStream,
  115. cmLocalUnixMakefileGenerator3* lg,
  116. const char* pass, bool check_all,
  117. bool check_relink);
  118. void WriteDirectoryRules2(std::ostream& ruleFileStream,
  119. cmLocalUnixMakefileGenerator3* lg);
  120. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  121. cmGeneratorTarget* target);
  122. // does this generator need a requires step for any of its targets
  123. bool NeedRequiresStep(cmTarget const&);
  124. // Target name hooks for superclass.
  125. const char* GetAllTargetName() const { return "all"; }
  126. const char* GetInstallTargetName() const { return "install"; }
  127. const char* GetInstallLocalTargetName() const { return "install/local"; }
  128. const char* GetInstallStripTargetName() const { return "install/strip"; }
  129. const char* GetPreinstallTargetName() const { return "preinstall"; }
  130. const char* GetTestTargetName() const { return "test"; }
  131. const char* GetPackageTargetName() const { return "package"; }
  132. const char* GetPackageSourceTargetName() const { return "package_source"; }
  133. const char* GetEditCacheTargetName() const { return "edit_cache"; }
  134. const char* GetRebuildCacheTargetName() const { return "rebuild_cache"; }
  135. const char* GetCleanTargetName() const { return "clean"; }
  136. virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const { return true; }
  137. // Some make programs (Borland) do not keep a rule if there are no
  138. // dependencies or commands. This is a problem for creating rules
  139. // that might not do anything but might have other dependencies
  140. // added later. If non-empty this variable holds a fake dependency
  141. // that can be added.
  142. std::string EmptyRuleHackDepends;
  143. // Some make programs (Watcom) do not like rules with no commands.
  144. // If non-empty this variable holds a bogus command that may be put
  145. // in the rule to satisfy the make program.
  146. std::string EmptyRuleHackCommand;
  147. // Store per-target progress counters.
  148. struct TargetProgress
  149. {
  150. TargetProgress(): NumberOfActions(0) {}
  151. unsigned long NumberOfActions;
  152. std::string VariableFile;
  153. std::vector<unsigned long> Marks;
  154. void WriteProgressVariables(unsigned long total, unsigned long& current);
  155. };
  156. typedef std::map<cmTarget const*, TargetProgress,
  157. cmStrictTargetComparison> ProgressMapType;
  158. ProgressMapType ProgressMap;
  159. size_t CountProgressMarksInTarget(cmGeneratorTarget const* target,
  160. std::set<cmGeneratorTarget const*>& emitted);
  161. size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
  162. cmGeneratedFileStream *CommandDatabase;
  163. private:
  164. virtual const char* GetBuildIgnoreErrorsFlag() const { return "-i"; }
  165. virtual std::string GetEditCacheCommand() const;
  166. std::map<cmState::Snapshot,
  167. std::set<cmGeneratorTarget const*>,
  168. cmState::Snapshot::StrictWeakOrder> DirectoryTargetsMap;
  169. virtual void InitializeProgressMarks();
  170. };
  171. #endif