cmLocalUnixMakefileGenerator2.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  58. void GenerateUtilityRuleFile(const cmTarget& target);
  59. bool GenerateDependsMakeFile(const std::string& lang,
  60. const char* objFile,
  61. std::string& depMakeFile,
  62. std::string& depMarkFile);
  63. void WriteMakeRule(std::ostream& os,
  64. const char* comment,
  65. const char* preEcho,
  66. const char* target,
  67. const std::vector<std::string>& depends,
  68. const std::vector<std::string>& commands,
  69. const char* postEcho=0);
  70. void WriteDivider(std::ostream& os);
  71. void WriteDisclaimer(std::ostream& os);
  72. void WriteMakeVariables(std::ostream& makefileStream);
  73. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  74. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  75. void WriteRuleFileIncludes(std::ostream& makefileStream);
  76. void WriteAllRules(std::ostream& makefileStream);
  77. void WritePassRules(std::ostream& makefileStream,
  78. const char* pass, const char* comment,
  79. const std::vector<std::string>& depends);
  80. void WriteDriverRules(std::ostream& makefileStream, const char* pass,
  81. const char* local1, const char* local2=0);
  82. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  83. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  84. const char* subdir, std::string& last);
  85. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  86. const char* order, const std::string& last);
  87. void WriteConvenienceRules(std::ostream& ruleFileStream,
  88. const cmTarget& target,
  89. const char* targetOutPath);
  90. void WriteConvenienceRule(std::ostream& ruleFileStream,
  91. const char* realTarget,
  92. const char* helpTarget);
  93. void WriteExecutableRule(std::ostream& ruleFileStream,
  94. const char* ruleFileName,
  95. const cmTarget& target,
  96. std::vector<std::string>& objects);
  97. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  98. const char* ruleFileName,
  99. const cmTarget& target,
  100. std::vector<std::string>& objects);
  101. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  102. const char* ruleFileName,
  103. const cmTarget& target,
  104. std::vector<std::string>& objects);
  105. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  106. const char* ruleFileName,
  107. const cmTarget& target,
  108. std::vector<std::string>& objects);
  109. void WriteLibraryRule(std::ostream& ruleFileStream,
  110. const char* ruleFileName,
  111. const cmTarget& target,
  112. std::vector<std::string>& objects,
  113. const char* linkRuleVar,
  114. const char* extraLinkFlags);
  115. void WriteObjectsVariable(std::ostream& ruleFileStream,
  116. const cmTarget& target,
  117. std::vector<std::string>& objects);
  118. void WriteTargetDependsRule(std::ostream& ruleFileStream,
  119. const char* ruleFileName,
  120. const cmTarget& target,
  121. const std::vector<std::string>& objects);
  122. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  123. const cmTarget& target,
  124. const std::vector<std::string>& files);
  125. std::string GetTargetDirectory(const cmTarget& target);
  126. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  127. std::string GetObjectFileName(const cmTarget& target,
  128. const cmSourceFile& source);
  129. std::string GetCustomBaseName(const cmCustomCommand& cc);
  130. const char* GetSourceFileLanguage(const cmSourceFile& source);
  131. std::string ConvertToFullPath(const std::string& localPath);
  132. std::string ConvertToRelativePath(const char* p);
  133. std::string ConvertToRelativeOutputPath(const char* p);
  134. virtual void ConfigureOutputPaths();
  135. void SplitFullPath(const char* p, std::vector<std::string>& components);
  136. bool ComparePath(const char* c1, const char* c2);
  137. void AddLanguageFlags(std::string& flags, const char* lang);
  138. void AddSharedFlags(std::string& flags, const char* lang, bool shared);
  139. void AddConfigVariableFlags(std::string& flags, const char* var);
  140. void AppendFlags(std::string& flags, const char* newFlags);
  141. void AppendTargetDepends(std::vector<std::string>& depends,
  142. const cmTarget& target);
  143. void AppendAnyDepend(std::vector<std::string>& depends, const char* name);
  144. void AppendCustomDepends(std::vector<std::string>& depends,
  145. const std::vector<cmCustomCommand>& ccs);
  146. void AppendCustomDepend(std::vector<std::string>& depends,
  147. const cmCustomCommand& cc);
  148. void AppendCustomCommands(std::vector<std::string>& commands,
  149. const std::vector<cmCustomCommand>& ccs);
  150. void AppendCustomCommand(std::vector<std::string>& commands,
  151. const cmCustomCommand& cc);
  152. std::string GetRecursiveMakeCall(const char* tgt);
  153. void WriteJumpAndBuildRules(std::ostream& makefileStream);
  154. static cmDepends* GetDependsChecker(const std::string& lang,
  155. const char* dir,
  156. const char* objFile);
  157. private:
  158. // Map from target name to build directory containing it for
  159. // jump-and-build targets.
  160. struct RemoteTarget
  161. {
  162. std::string m_BuildDirectory;
  163. std::string m_FilePath;
  164. };
  165. std::map<cmStdString, RemoteTarget> m_JumpAndBuild;
  166. // List the files for which to check dependency integrity. Each
  167. // language has its own list because integrity may be checked
  168. // differently.
  169. struct IntegrityCheckSet: public std::set<cmStdString> {};
  170. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  171. // Command used when a rule has no dependencies or commands.
  172. std::vector<std::string> m_EmptyCommands;
  173. // List of make rule files that need to be included by the makefile.
  174. std::vector<std::string> m_IncludeRuleFiles;
  175. // Set of custom rule files that have been generated.
  176. std::set<cmStdString> m_CustomRuleFiles;
  177. // List of target-level rules for each pass. These are populated by
  178. // target rule file writing methods.
  179. std::vector<std::string> m_DependTargets;
  180. std::vector<std::string> m_BuildTargets;
  181. std::vector<std::string> m_CleanTargets;
  182. // The prefix required of a path to be converted to a relative path.
  183. // No sequence of ../.. will ever go past this path.
  184. std::string m_RelativePathTop;
  185. // The pre-split current output directory.
  186. std::vector<std::string> m_CurrentOutputDirectoryComponents;
  187. };
  188. #endif