cmLocalUnixMakefileGenerator2.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.
  72. */
  73. virtual void Generate();
  74. /** Called from command-line hook to scan dependencies. */
  75. static bool ScanDependencies(std::vector<std::string> const& args);
  76. /** Called from command-line hook to check dependencies. */
  77. static void CheckDependencies(cmMakefile* mf);
  78. protected:
  79. void GenerateMakefile();
  80. void GenerateCMakefile();
  81. void GenerateDirectoryInformationFile();
  82. void GenerateTargetRuleFile(const cmTarget& target);
  83. void GenerateObjectRuleFile(const cmTarget& target,
  84. const cmSourceFile& source,
  85. std::vector<std::string>& objects,
  86. std::vector<std::string>& provides_requires);
  87. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  88. void GenerateUtilityRuleFile(const cmTarget& target);
  89. bool GenerateDependsMakeFile(const std::string& lang,
  90. const char* objFile,
  91. std::string& depMakeFile,
  92. std::string& depMarkFile);
  93. void WriteMakeRule(std::ostream& os,
  94. const char* comment,
  95. const char* target,
  96. const std::vector<std::string>& depends,
  97. const std::vector<std::string>& commands);
  98. void WriteDivider(std::ostream& os);
  99. void WriteDisclaimer(std::ostream& os);
  100. void WriteMakeVariables(std::ostream& makefileStream);
  101. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  102. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  103. void WriteRuleFileIncludes(std::ostream& makefileStream);
  104. void WriteAllRules(std::ostream& makefileStream);
  105. void WritePassRules(std::ostream& makefileStream, const char* pass);
  106. void WriteDriverRules(std::ostream& makefileStream, const char* pass,
  107. const char* local1, const char* local2=0);
  108. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  109. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  110. const char* subdir, std::string& last);
  111. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  112. const char* order, const std::string& last);
  113. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  114. const char* dependency);
  115. void WriteConvenienceRules(std::ostream& ruleFileStream,
  116. const cmTarget& target,
  117. const char* targetOutPath);
  118. void WriteConvenienceRule(std::ostream& ruleFileStream,
  119. const char* realTarget,
  120. const char* helpTarget);
  121. void WriteExecutableRule(std::ostream& ruleFileStream,
  122. const char* ruleFileName,
  123. const cmTarget& target,
  124. const std::vector<std::string>& objects,
  125. const std::vector<std::string>& external_objects,
  126. const std::vector<std::string>& provides_requires);
  127. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  128. const char* ruleFileName,
  129. const cmTarget& target,
  130. const std::vector<std::string>& objects,
  131. const std::vector<std::string>& external_objects,
  132. const std::vector<std::string>& provides_requires);
  133. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  134. const char* ruleFileName,
  135. const cmTarget& target,
  136. const std::vector<std::string>& objects,
  137. const std::vector<std::string>& external_objects,
  138. const std::vector<std::string>& provides_requires);
  139. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  140. const char* ruleFileName,
  141. const cmTarget& target,
  142. const std::vector<std::string>& objects,
  143. const std::vector<std::string>& external_objects,
  144. const std::vector<std::string>& provides_requires);
  145. void WriteLibraryRule(std::ostream& ruleFileStream,
  146. const char* ruleFileName,
  147. const cmTarget& target,
  148. const std::vector<std::string>& objects,
  149. const std::vector<std::string>& external_objects,
  150. const char* linkRuleVar,
  151. const char* extraLinkFlags,
  152. const std::vector<std::string>& provides_requires);
  153. void WriteObjectsVariable(std::ostream& ruleFileStream,
  154. const cmTarget& target,
  155. const std::vector<std::string>& objects,
  156. const std::vector<std::string>& external_objects,
  157. std::string& variableName,
  158. std::string& variableNameExternal);
  159. void WriteTargetDependsRule(std::ostream& ruleFileStream,
  160. const char* ruleFileName,
  161. const cmTarget& target,
  162. const std::vector<std::string>& objects);
  163. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  164. const cmTarget& target,
  165. const std::vector<std::string>& files);
  166. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  167. const cmTarget& target,
  168. const std::vector<std::string>& provides_requires);
  169. void WriteLocalCleanRule(std::ostream& makefileStream);
  170. void WriteCMakeArgument(std::ostream& os, const char* s);
  171. std::string GetTargetDirectory(const cmTarget& target);
  172. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  173. std::string GetObjectFileName(const cmTarget& target,
  174. const cmSourceFile& source);
  175. const char* GetSourceFileLanguage(const cmSourceFile& source);
  176. std::string ConvertToFullPath(const std::string& localPath);
  177. std::string ConvertToRelativeOutputPath(const char* p);
  178. std::string ConvertToQuotedOutputPath(const char* p);
  179. void ConfigureOutputPaths();
  180. void FormatOutputPath(std::string& path, const char* name);
  181. void AppendTargetDepends(std::vector<std::string>& depends,
  182. const cmTarget& target);
  183. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  184. bool assume_unknown_is_file=false);
  185. void AppendRuleDepend(std::vector<std::string>& depends,
  186. const char* ruleFileName);
  187. void AppendCustomDepends(std::vector<std::string>& depends,
  188. const std::vector<cmCustomCommand>& ccs);
  189. void AppendCustomDepend(std::vector<std::string>& depends,
  190. const cmCustomCommand& cc);
  191. void AppendCustomCommands(std::vector<std::string>& commands,
  192. const std::vector<cmCustomCommand>& ccs);
  193. void AppendCustomCommand(std::vector<std::string>& commands,
  194. const cmCustomCommand& cc);
  195. void AppendCleanCommand(std::vector<std::string>& commands,
  196. const std::vector<std::string>& files);
  197. void AppendEcho(std::vector<std::string>& commands,
  198. const char* text);
  199. //==========================================================================
  200. bool SamePath(const char* path1, const char* path2);
  201. void GetLibraryNames(const cmTarget& t,
  202. std::string& name, std::string& soName,
  203. std::string& realName, std::string& baseName);
  204. std::string ConvertToMakeTarget(const char* tgt);
  205. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  206. std::string CreateMakeVariable(const char* sin, const char* s2in);
  207. //==========================================================================
  208. std::string GetRecursiveMakeCall(const char* tgt);
  209. void WriteJumpAndBuildRules(std::ostream& makefileStream);
  210. static cmDepends* GetDependsChecker(const std::string& lang,
  211. const char* dir,
  212. const char* objFile);
  213. private:
  214. // Map from target name to build directory containing it for
  215. // jump-and-build targets.
  216. struct RemoteTarget
  217. {
  218. std::string m_BuildDirectory;
  219. std::string m_FilePath;
  220. };
  221. std::map<cmStdString, RemoteTarget> m_JumpAndBuild;
  222. // List the files for which to check dependency integrity. Each
  223. // language has its own list because integrity may be checked
  224. // differently.
  225. struct IntegrityCheckSet: public std::set<cmStdString> {};
  226. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  227. // Command used when a rule has no dependencies or commands.
  228. std::vector<std::string> m_EmptyCommands;
  229. //==========================================================================
  230. // Configuration settings.
  231. int m_MakefileVariableSize;
  232. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  233. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  234. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  235. std::string m_IncludeDirective;
  236. std::string m_MakeSilentFlag;
  237. std::string m_ExecutableOutputPath;
  238. std::string m_LibraryOutputPath;
  239. bool m_PassMakeflags;
  240. //==========================================================================
  241. // Flag for whether echo command needs quotes.
  242. bool m_EchoNeedsQuote;
  243. // List of make rule files that need to be included by the makefile.
  244. std::vector<std::string> m_IncludeRuleFiles;
  245. // Set of custom rule files that have been generated.
  246. std::set<cmStdString> m_CustomRuleFiles;
  247. // Set of object file names that will be built in this directory.
  248. std::set<cmStdString> m_ObjectFiles;
  249. };
  250. #endif