cmLocalUnixMakefileGenerator2.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 "cmLocalGenerator.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 cmLocalGenerator
  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. /** Set whether the echo command needs its argument quoted. */
  39. void SetEchoNeedsQuote(bool b) { m_EchoNeedsQuote = b; }
  40. /**
  41. * Set to true if the shell being used is the windows shell.
  42. * This controls if statements in the makefile and the SHELL variable.
  43. * The default is false.
  44. */
  45. void SetWindowsShell(bool v) {m_WindowsShell = v;}
  46. /**
  47. * Set the string used to include one makefile into another default
  48. * is include.
  49. */
  50. void SetIncludeDirective(const char* s) { m_IncludeDirective = s; }
  51. /**
  52. * Set the flag used to keep the make program silent.
  53. */
  54. void SetMakeSilentFlag(const char* s) { m_MakeSilentFlag = s; }
  55. /**
  56. * Set max makefile variable size, default is 0 which means unlimited.
  57. */
  58. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  59. /**
  60. * If ignore lib prefix is true, then do not strip lib from the name
  61. * of a library.
  62. */
  63. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  64. /**
  65. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  66. * that do not use environment variables.
  67. *
  68. */
  69. void SetPassMakeflags(bool s){m_PassMakeflags = s;}
  70. /**
  71. * Generate the makefile for this directory. fromTheTop indicates if this
  72. * is being invoked as part of a global Generate or specific to this
  73. * directory. The difference is that when done from the Top we might skip
  74. * some steps to save time, such as dependency generation for the
  75. * makefiles. This is done by a direct invocation from make.
  76. */
  77. virtual void Generate(bool fromTheTop);
  78. /** Called from command-line hook to scan dependencies. */
  79. static bool ScanDependencies(std::vector<std::string> const& args);
  80. /** Called from command-line hook to check dependencies. */
  81. static void CheckDependencies(cmMakefile* mf);
  82. protected:
  83. void GenerateMakefile();
  84. void GenerateCMakefile();
  85. void GenerateDirectoryInformationFile();
  86. void GenerateTargetRuleFile(const cmTarget& target);
  87. void GenerateObjectRuleFile(const cmTarget& target,
  88. const cmSourceFile& source,
  89. std::vector<std::string>& objects,
  90. std::vector<std::string>& provides_requires);
  91. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  92. void GenerateUtilityRuleFile(const cmTarget& target);
  93. bool GenerateDependsMakeFile(const std::string& lang,
  94. const char* objFile,
  95. std::string& depMakeFile,
  96. std::string& depMarkFile);
  97. void WriteMakeRule(std::ostream& os,
  98. const char* comment,
  99. const char* target,
  100. const std::vector<std::string>& depends,
  101. const std::vector<std::string>& commands);
  102. void WriteDivider(std::ostream& os);
  103. void WriteDisclaimer(std::ostream& os);
  104. void WriteMakeVariables(std::ostream& makefileStream);
  105. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  106. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  107. void WriteRuleFileIncludes(std::ostream& makefileStream);
  108. void WriteAllRules(std::ostream& makefileStream);
  109. void WritePassRules(std::ostream& makefileStream, const char* pass);
  110. void WriteDriverRules(std::ostream& makefileStream, const char* pass,
  111. const char* local1, const char* local2=0);
  112. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  113. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  114. const char* subdir, std::string& last);
  115. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  116. const char* order, const std::string& last);
  117. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  118. const char* dependency);
  119. void WriteConvenienceRules(std::ostream& ruleFileStream,
  120. const cmTarget& target,
  121. const char* targetOutPath);
  122. void WriteConvenienceRule(std::ostream& ruleFileStream,
  123. const char* realTarget,
  124. const char* helpTarget);
  125. void WriteExecutableRule(std::ostream& ruleFileStream,
  126. const char* ruleFileName,
  127. const cmTarget& target,
  128. const std::vector<std::string>& objects,
  129. const std::vector<std::string>& external_objects,
  130. const std::vector<std::string>& provides_requires);
  131. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  132. const char* ruleFileName,
  133. const cmTarget& target,
  134. const std::vector<std::string>& objects,
  135. const std::vector<std::string>& external_objects,
  136. const std::vector<std::string>& provides_requires);
  137. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  138. const char* ruleFileName,
  139. const cmTarget& target,
  140. const std::vector<std::string>& objects,
  141. const std::vector<std::string>& external_objects,
  142. const std::vector<std::string>& provides_requires);
  143. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  144. const char* ruleFileName,
  145. const cmTarget& target,
  146. const std::vector<std::string>& objects,
  147. const std::vector<std::string>& external_objects,
  148. const std::vector<std::string>& provides_requires);
  149. void WriteLibraryRule(std::ostream& ruleFileStream,
  150. const char* ruleFileName,
  151. const cmTarget& target,
  152. const std::vector<std::string>& objects,
  153. const std::vector<std::string>& external_objects,
  154. const char* linkRuleVar,
  155. const char* extraLinkFlags,
  156. const std::vector<std::string>& provides_requires);
  157. void WriteObjectsVariable(std::ostream& ruleFileStream,
  158. const cmTarget& target,
  159. const std::vector<std::string>& objects,
  160. const std::vector<std::string>& external_objects,
  161. std::string& variableName,
  162. std::string& variableNameExternal);
  163. void WriteTargetDependsRule(std::ostream& ruleFileStream,
  164. const char* ruleFileName,
  165. const cmTarget& target,
  166. const std::vector<std::string>& objects);
  167. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  168. const cmTarget& target,
  169. const std::vector<std::string>& files);
  170. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  171. const cmTarget& target,
  172. const std::vector<std::string>& provides_requires);
  173. void WriteLocalCleanRule(std::ostream& makefileStream);
  174. void WriteCMakeArgument(std::ostream& os, const char* s);
  175. std::string GetTargetDirectory(const cmTarget& target);
  176. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  177. std::string GetObjectFileName(const cmTarget& target,
  178. const cmSourceFile& source);
  179. const char* GetSourceFileLanguage(const cmSourceFile& source);
  180. std::string ConvertToFullPath(const std::string& localPath);
  181. std::string ConvertToRelativeOutputPath(const char* p);
  182. std::string ConvertToQuotedOutputPath(const char* p);
  183. void ConfigureOutputPaths();
  184. void FormatOutputPath(std::string& path, const char* name);
  185. void AppendTargetDepends(std::vector<std::string>& depends,
  186. const cmTarget& target);
  187. void AppendAnyDepend(std::vector<std::string>& depends, const char* name);
  188. void AppendCustomDepends(std::vector<std::string>& depends,
  189. const std::vector<cmCustomCommand>& ccs);
  190. void AppendCustomDepend(std::vector<std::string>& depends,
  191. const cmCustomCommand& cc);
  192. void AppendCustomCommands(std::vector<std::string>& commands,
  193. const std::vector<cmCustomCommand>& ccs);
  194. void AppendCustomCommand(std::vector<std::string>& commands,
  195. const cmCustomCommand& cc);
  196. void AppendCleanCommand(std::vector<std::string>& commands,
  197. const std::vector<std::string>& files);
  198. void AppendEcho(std::vector<std::string>& commands,
  199. const char* text);
  200. //==========================================================================
  201. bool SamePath(const char* path1, const char* path2);
  202. std::string GetBaseTargetName(const cmTarget& t);
  203. void GetLibraryNames(const cmTarget& t,
  204. std::string& name, std::string& soName,
  205. std::string& realName, std::string& baseName);
  206. std::string ConvertToMakeTarget(const char* tgt);
  207. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  208. std::string CreateMakeVariable(const char* sin, const char* s2in);
  209. //==========================================================================
  210. std::string GetRecursiveMakeCall(const char* tgt);
  211. void WriteJumpAndBuildRules(std::ostream& makefileStream);
  212. static cmDepends* GetDependsChecker(const std::string& lang,
  213. const char* dir,
  214. const char* objFile);
  215. private:
  216. // Map from target name to build directory containing it for
  217. // jump-and-build targets.
  218. struct RemoteTarget
  219. {
  220. std::string m_BuildDirectory;
  221. std::string m_FilePath;
  222. };
  223. std::map<cmStdString, RemoteTarget> m_JumpAndBuild;
  224. // List the files for which to check dependency integrity. Each
  225. // language has its own list because integrity may be checked
  226. // differently.
  227. struct IntegrityCheckSet: public std::set<cmStdString> {};
  228. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  229. // Command used when a rule has no dependencies or commands.
  230. std::vector<std::string> m_EmptyCommands;
  231. //==========================================================================
  232. // Configuration settings.
  233. int m_MakefileVariableSize;
  234. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  235. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  236. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  237. std::string m_IncludeDirective;
  238. std::string m_MakeSilentFlag;
  239. std::string m_ExecutableOutputPath;
  240. std::string m_LibraryOutputPath;
  241. bool m_PassMakeflags;
  242. //==========================================================================
  243. // Flag for whether echo command needs quotes.
  244. bool m_EchoNeedsQuote;
  245. // List of make rule files that need to be included by the makefile.
  246. std::vector<std::string> m_IncludeRuleFiles;
  247. // Set of custom rule files that have been generated.
  248. std::set<cmStdString> m_CustomRuleFiles;
  249. // Set of object file names that will be built in this directory.
  250. std::set<cmStdString> m_ObjectFiles;
  251. };
  252. #endif