cmGlobalUnixMakefileGenerator3.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator3
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2005 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. #ifndef cmGlobalUnixMakefileGenerator3_h
  14. #define cmGlobalUnixMakefileGenerator3_h
  15. #include "cmGlobalGenerator.h"
  16. class cmGeneratedFileStream;
  17. class cmLocalUnixMakefileGenerator3;
  18. /** \class cmGlobalUnixMakefileGenerator3
  19. * \brief Write a Unix makefiles.
  20. *
  21. * cmGlobalUnixMakefileGenerator3 manages UNIX build process for a tree
  22. The basic approach of this generator is to produce Makefiles that will all
  23. be run with the current working directory set to the Home Output
  24. directory. The one exception to this is the subdirectory Makefiles which are
  25. created as a convenience and just cd up to the Home Output directory and
  26. invoke the main Makefiles.
  27. The make process starts with Makefile. Makefile should only contain the
  28. targets the user is likely to invoke directly from a make command line. No
  29. internal targets should be in this file. Makefile2 contains the internal
  30. targets that are required to make the process work.
  31. Makefile2 in turn will recursively make targets in the correct order. Each
  32. target has its own directory <target>.dir and its own makefile build.make in
  33. that directory. Also in that directory is a couple makefiles per source file
  34. used by the target. Typically these are named source.obj.build.make and
  35. source.obj.build.depend.make. The source.obj.build.make contains the rules
  36. for building, cleaning, and computing dependencies for the given source
  37. file. The build.depend.make contains additional dependencies that were
  38. computed during dependency scanning. An additional file called
  39. source.obj.depend is used as a marker to indicate when dependencies must be
  40. rescanned.
  41. Rules for custom commands follow the same model as rules for source files.
  42. */
  43. class cmGlobalUnixMakefileGenerator3 : public cmGlobalGenerator
  44. {
  45. public:
  46. cmGlobalUnixMakefileGenerator3();
  47. static cmGlobalGenerator* New() {
  48. return new cmGlobalUnixMakefileGenerator3; }
  49. ///! Get the name for the generator.
  50. virtual const char* GetName() const {
  51. return cmGlobalUnixMakefileGenerator3::GetActualName();}
  52. static const char* GetActualName() {return "Unix Makefiles";}
  53. /** Get the documentation entry for this generator. */
  54. virtual void GetDocumentation(cmDocumentationEntry& entry) const;
  55. ///! Create a local generator appropriate to this Global Generator3
  56. virtual cmLocalGenerator *CreateLocalGenerator();
  57. /**
  58. * Try to determine system infomation such as shared library
  59. * extension, pthreads, byte order etc.
  60. */
  61. virtual void EnableLanguage(std::vector<std::string>const& languages,
  62. cmMakefile *);
  63. /**
  64. * Generate the all required files for building this project/tree. This
  65. * basically creates a series of LocalGenerators for each directory and
  66. * requests that they Generate.
  67. */
  68. virtual void Generate();
  69. void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
  70. std::vector<cmLocalGenerator *> &);
  71. // write out the help rule listing the valid targets
  72. void WriteHelpRule(std::ostream& ruleFileStream,
  73. cmLocalUnixMakefileGenerator3 *);
  74. // write the top lvel target rules
  75. void WriteConvenienceRules(std::ostream& ruleFileStream,
  76. std::set<cmStdString> &emitted);
  77. /** In order to support parallel builds for custom commands with
  78. multiple outputs the outputs are given a serial order, and only
  79. the first output actually has the build rule. Other outputs
  80. just depend on the first one. The check-build-system step must
  81. remove a dependee if the depender is missing to make sure both
  82. are regenerated properly. This method is used by the local
  83. makefile generators to register such pairs. */
  84. void AddMultipleOutputPair(const char* depender, const char* dependee);
  85. /** Support for multiple custom command outputs. Called during
  86. check-build-system step. */
  87. virtual void CheckMultipleOutputs(cmMakefile* mf, bool verbose);
  88. /** Get the command to use for a non-symbolic target file that has
  89. no rule. This is used for multiple output dependencies. */
  90. std::string GetEmptyCommandHack() { return this->EmptyCommandsHack; }
  91. // change the build command for speed
  92. virtual std::string GenerateBuildCommand
  93. (const char* makeProgram,
  94. const char *projectName, const char* additionalOptions,
  95. const char *targetName,
  96. const char* config, bool ignoreErrors, bool fast);
  97. // returns true if a progress rule should be added
  98. int ShouldAddProgressRule();
  99. int GetNumberOfCompilableSourceFilesForTarget(cmTarget &tgt);
  100. int GetTargetTotalNumberOfSourceFiles(cmTarget& target);
  101. int GetNumberOfSourceFiles() { return this->NumberOfSourceFiles; };
  102. // what targets does the specified target depend on
  103. std::vector<cmTarget *>& GetTargetDepends(cmTarget& target);
  104. protected:
  105. void WriteMainMakefile2();
  106. void WriteMainCMakefile();
  107. void WriteConvenienceRules2(std::ostream& ruleFileStream,
  108. cmLocalUnixMakefileGenerator3 *,
  109. bool exclude);
  110. void WriteDirectoryRule2(std::ostream& ruleFileStream,
  111. cmLocalUnixMakefileGenerator3* lg,
  112. const char* pass, bool check_all,
  113. bool check_relink);
  114. void WriteDirectoryRules2(std::ostream& ruleFileStream,
  115. cmLocalUnixMakefileGenerator3* lg);
  116. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  117. cmTarget& target);
  118. void AppendAnyGlobalDepend(std::vector<std::string>& depends,
  119. const char* name,
  120. std::set<cmStdString>& emitted,
  121. cmTarget &target);
  122. // does this generator need a requires step for any of its targets
  123. bool NeedRequiresStep(cmLocalUnixMakefileGenerator3 *lg, const char *);
  124. // Setup target names
  125. virtual const char* GetAllTargetName() { return "all"; }
  126. virtual const char* GetInstallTargetName() { return "install"; }
  127. virtual const char* GetPreinstallTargetName() { return "preinstall"; }
  128. virtual const char* GetTestTargetName() { return "test"; }
  129. virtual const char* GetPackageTargetName() { return "package"; }
  130. virtual const char* GetPackageSourceTargetName(){ return "package_source"; }
  131. virtual const char* GetEditCacheTargetName() { return "edit_cache"; }
  132. virtual const char* GetRebuildCacheTargetName() { return "rebuild_cache"; }
  133. // Some make programs (Borland) do not keep a rule if there are no
  134. // dependencies or commands. This is a problem for creating rules
  135. // that might not do anything but might have other dependencies
  136. // added later. If non-empty this variable holds a fake dependency
  137. // that can be added.
  138. std::string EmptyRuleHackDepends;
  139. // Some make programs (Watcom) do not like rules with no commands
  140. // for non-symbolic targets. If non-empty this variable holds a
  141. // bogus command that may be put in the rule to satisfy the make
  142. // program.
  143. std::string EmptyCommandsHack;
  144. typedef std::map<cmStdString, cmStdString> MultipleOutputPairsType;
  145. MultipleOutputPairsType MultipleOutputPairs;
  146. int NumberOfSourceFiles;
  147. int NumberOfSourceFilesWritten;
  148. std::map<cmStdString, std::vector<cmTarget *> > TargetDependencies;
  149. std::map<cmStdString, int > TargetSourceFileCount;
  150. };
  151. #endif