cmLocalUnixMakefileGenerator2.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 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 cmLocalUnixMakefileGenerator2_h
  14. #define cmLocalUnixMakefileGenerator2_h
  15. #include "cmLocalUnixMakefileGenerator.h"
  16. class cmCustomCommand;
  17. class cmDependInformation;
  18. class cmDepends;
  19. class cmMakeDepend;
  20. class cmTarget;
  21. class cmSourceFile;
  22. /** \class cmLocalUnixMakefileGenerator2
  23. * \brief Write a LocalUnix makefiles.
  24. *
  25. * cmLocalUnixMakefileGenerator2 produces a LocalUnix makefile from its
  26. * member m_Makefile.
  27. */
  28. class cmLocalUnixMakefileGenerator2 : public cmLocalUnixMakefileGenerator
  29. {
  30. public:
  31. ///! Set cache only and recurse to false by default.
  32. cmLocalUnixMakefileGenerator2();
  33. virtual ~cmLocalUnixMakefileGenerator2();
  34. /** Set the command used when there are no dependencies or rules for
  35. a target. This is used to avoid errors on some make
  36. implementations. */
  37. void SetEmptyCommand(const char* cmd);
  38. /**
  39. * Generate the makefile for this directory. fromTheTop indicates if this
  40. * is being invoked as part of a global Generate or specific to this
  41. * directory. The difference is that when done from the Top we might skip
  42. * some steps to save time, such as dependency generation for the
  43. * makefiles. This is done by a direct invocation from make.
  44. */
  45. virtual void Generate(bool fromTheTop);
  46. /** Called from command-line hook to scan dependencies. */
  47. static bool ScanDependencies(std::vector<std::string> const& args);
  48. /** Called from command-line hook to check dependencies. */
  49. static void CheckDependencies(cmMakefile* mf);
  50. protected:
  51. void GenerateMakefile();
  52. void GenerateCMakefile();
  53. void GenerateTargetRuleFile(const cmTarget& target);
  54. void GenerateObjectRuleFile(const cmTarget& target,
  55. const cmSourceFile& source,
  56. std::vector<std::string>& objects,
  57. std::vector<std::string>& provides_requires);
  58. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  59. void GenerateUtilityRuleFile(const cmTarget& target);
  60. bool GenerateDependsMakeFile(const std::string& lang,
  61. const char* objFile,
  62. std::string& depMakeFile,
  63. std::string& depMarkFile);
  64. void WriteMakeRule(std::ostream& os,
  65. const char* comment,
  66. const char* preEcho,
  67. const char* target,
  68. const std::vector<std::string>& depends,
  69. const std::vector<std::string>& commands,
  70. const char* postEcho=0);
  71. void WriteDivider(std::ostream& os);
  72. void WriteDisclaimer(std::ostream& os);
  73. void WriteMakeVariables(std::ostream& makefileStream);
  74. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  75. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  76. void WriteRuleFileIncludes(std::ostream& makefileStream);
  77. void WriteAllRules(std::ostream& makefileStream);
  78. void WritePassRules(std::ostream& makefileStream,
  79. const char* pass, const char* comment,
  80. const std::vector<std::string>& depends);
  81. void WriteDriverRules(std::ostream& makefileStream, const char* pass,
  82. const char* local1, const char* local2=0);
  83. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  84. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  85. const char* subdir, std::string& last);
  86. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  87. const char* order, const std::string& last);
  88. void WriteConvenienceRules(std::ostream& ruleFileStream,
  89. const cmTarget& target,
  90. const char* targetOutPath);
  91. void WriteConvenienceRule(std::ostream& ruleFileStream,
  92. const char* realTarget,
  93. const char* helpTarget);
  94. void WriteExecutableRule(std::ostream& ruleFileStream,
  95. const char* ruleFileName,
  96. const cmTarget& target,
  97. std::vector<std::string>& objects,
  98. const std::vector<std::string>& provides_requires);
  99. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  100. const char* ruleFileName,
  101. const cmTarget& target,
  102. std::vector<std::string>& objects,
  103. const std::vector<std::string>& provides_requires);
  104. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  105. const char* ruleFileName,
  106. const cmTarget& target,
  107. std::vector<std::string>& objects,
  108. const std::vector<std::string>& provides_requires);
  109. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  110. const char* ruleFileName,
  111. const cmTarget& target,
  112. std::vector<std::string>& objects,
  113. const std::vector<std::string>& provides_requires);
  114. void WriteLibraryRule(std::ostream& ruleFileStream,
  115. const char* ruleFileName,
  116. const cmTarget& target,
  117. std::vector<std::string>& objects,
  118. const char* linkRuleVar,
  119. const char* extraLinkFlags,
  120. const std::vector<std::string>& provides_requires);
  121. void WriteObjectsVariable(std::ostream& ruleFileStream,
  122. const cmTarget& target,
  123. const std::vector<std::string>& objects,
  124. std::string& variableName);
  125. void WriteTargetDependsRule(std::ostream& ruleFileStream,
  126. const char* ruleFileName,
  127. const cmTarget& target,
  128. const std::vector<std::string>& objects);
  129. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  130. const cmTarget& target,
  131. const std::vector<std::string>& files);
  132. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  133. const cmTarget& target,
  134. const std::vector<std::string>& provides_requires);
  135. std::string GetTargetDirectory(const cmTarget& target);
  136. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  137. std::string GetObjectFileName(const cmTarget& target,
  138. const cmSourceFile& source);
  139. std::string GetCustomBaseName(const cmCustomCommand& cc);
  140. const char* GetSourceFileLanguage(const cmSourceFile& source);
  141. std::string ConvertToFullPath(const std::string& localPath);
  142. std::string ConvertToRelativePath(const char* p);
  143. std::string ConvertToRelativeOutputPath(const char* p);
  144. virtual void ConfigureOutputPaths();
  145. void SplitFullPath(const char* p, std::vector<std::string>& components);
  146. bool ComparePath(const char* c1, const char* c2);
  147. void AppendTargetDepends(std::vector<std::string>& depends,
  148. const cmTarget& target);
  149. void AppendAnyDepend(std::vector<std::string>& depends, const char* name);
  150. void AppendCustomDepends(std::vector<std::string>& depends,
  151. const std::vector<cmCustomCommand>& ccs);
  152. void AppendCustomDepend(std::vector<std::string>& depends,
  153. const cmCustomCommand& cc);
  154. void AppendCustomCommands(std::vector<std::string>& commands,
  155. const std::vector<cmCustomCommand>& ccs);
  156. void AppendCustomCommand(std::vector<std::string>& commands,
  157. const cmCustomCommand& cc);
  158. std::string GetRecursiveMakeCall(const char* tgt);
  159. void WriteJumpAndBuildRules(std::ostream& makefileStream);
  160. static cmDepends* GetDependsChecker(const std::string& lang,
  161. const char* dir,
  162. const char* objFile);
  163. private:
  164. // Map from target name to build directory containing it for
  165. // jump-and-build targets.
  166. struct RemoteTarget
  167. {
  168. std::string m_BuildDirectory;
  169. std::string m_FilePath;
  170. };
  171. std::map<cmStdString, RemoteTarget> m_JumpAndBuild;
  172. // List the files for which to check dependency integrity. Each
  173. // language has its own list because integrity may be checked
  174. // differently.
  175. struct IntegrityCheckSet: public std::set<cmStdString> {};
  176. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  177. // Command used when a rule has no dependencies or commands.
  178. std::vector<std::string> m_EmptyCommands;
  179. // List of make rule files that need to be included by the makefile.
  180. std::vector<std::string> m_IncludeRuleFiles;
  181. // Set of custom rule files that have been generated.
  182. std::set<cmStdString> m_CustomRuleFiles;
  183. // List of target-level rules for each pass. These are populated by
  184. // target rule file writing methods.
  185. std::vector<std::string> m_DependTargets;
  186. std::vector<std::string> m_BuildTargets;
  187. std::vector<std::string> m_CleanTargets;
  188. // The prefix required of a path to be converted to a relative path.
  189. // No sequence of ../.. will ever go past this path.
  190. std::string m_RelativePathTop;
  191. // The pre-split current output directory.
  192. std::vector<std::string> m_CurrentOutputDirectoryComponents;
  193. };
  194. #endif