cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 cmLocalUnixMakefileGenerator3_h
  14. #define cmLocalUnixMakefileGenerator3_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 cmLocalUnixMakefileGenerator3
  23. * \brief Write a LocalUnix makefiles.
  24. *
  25. * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
  26. * member m_Makefile.
  27. */
  28. class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
  29. {
  30. public:
  31. ///! Set cache only and recurse to false by default.
  32. cmLocalUnixMakefileGenerator3();
  33. virtual ~cmLocalUnixMakefileGenerator3();
  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. const char *GetIncludeDirective() { return m_IncludeDirective.c_str(); }
  52. /**
  53. * Set the flag used to keep the make program silent.
  54. */
  55. void SetMakeSilentFlag(const char* s) { m_MakeSilentFlag = s; }
  56. /**
  57. * Set max makefile variable size, default is 0 which means unlimited.
  58. */
  59. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  60. /**
  61. * If ignore lib prefix is true, then do not strip lib from the name
  62. * of a library.
  63. */
  64. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  65. /**
  66. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  67. * that do not use environment variables.
  68. *
  69. */
  70. void SetPassMakeflags(bool s){m_PassMakeflags = s;}
  71. /**
  72. * Generate the makefile for this directory.
  73. */
  74. virtual void Generate();
  75. /** Called from command-line hook to scan dependencies. */
  76. static bool ScanDependencies(std::vector<std::string> const& args);
  77. /** Called from command-line hook to check dependencies. */
  78. static void CheckDependencies(cmMakefile* mf);
  79. void WriteDisclaimer(std::ostream& os);
  80. void WriteMakeRule(std::ostream& os,
  81. const char* comment,
  82. const char* target,
  83. const std::vector<std::string>& depends,
  84. const std::vector<std::string>& commands);
  85. void WriteAllRules(std::ostream& makefileStream);
  86. void WriteTargetIncludes(std::ostream& makefileStream,const char *file,
  87. const char *rule);
  88. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  89. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  90. void WriteMakeVariables(std::ostream& makefileStream);
  91. std::string ConvertToRelativeOutputPath(const char* p);
  92. void WriteConvenienceRules(std::ostream& ruleFileStream);
  93. std::string GetRelativeTargetDirectory(const cmTarget& target);
  94. void WriteLocalCleanRule(std::ostream& makefileStream);
  95. // this returns the relative path between the HomeOutputDirectory and this
  96. // local generators StartOutputDirectory
  97. std::string GetHomeRelativeOutputPath();
  98. // List the files for which to check dependency integrity. Each
  99. // language has its own list because integrity may be checked
  100. // differently.
  101. struct IntegrityCheckSet: public std::set<cmStdString> {};
  102. std::map<cmStdString, IntegrityCheckSet> &GetIntegrityCheckSet()
  103. { return m_CheckDependFiles;}
  104. protected:
  105. void GenerateMakefile();
  106. void GenerateCMakefile();
  107. void GenerateDirectoryInformationFile();
  108. void GenerateTargetRuleFile(const cmTarget& target);
  109. void GenerateObjectRuleFile(const cmTarget& target,
  110. const cmSourceFile& source,
  111. std::vector<std::string>& objects,
  112. std::vector<std::string>& provides_requires);
  113. void GenerateObjectDependFile(const std::string& obj,
  114. const cmSourceFile& source,
  115. std::vector<std::string>& objects,
  116. std::vector<std::string>& provides_requires,
  117. const std::string& depMarkFile,
  118. std::vector<std::string>& depends);
  119. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  120. void GenerateUtilityRuleFile(const cmTarget& target);
  121. bool GenerateDependsMakeFile(const std::string& lang,
  122. const char* objFile,
  123. std::string& depMakeFile,
  124. std::string& depMarkFile);
  125. void WriteDivider(std::ostream& os);
  126. void WriteRuleFileIncludes(std::ostream& makefileStream);
  127. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  128. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  129. const char* subdir, std::string& last);
  130. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  131. const char* order, const std::string& last);
  132. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  133. const char* dependency);
  134. void WriteConvenienceRule(std::ostream& ruleFileStream,
  135. const char* realTarget,
  136. const char* helpTarget);
  137. void WriteCustomCommands();
  138. void WriteExecutableRule(std::ostream& ruleFileStream,
  139. const char* ruleFileName,
  140. const cmTarget& target,
  141. const std::vector<std::string>& objects,
  142. const std::vector<std::string>& external_objects,
  143. const std::vector<std::string>& provides_requires);
  144. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  145. const char* ruleFileName,
  146. const cmTarget& target,
  147. const std::vector<std::string>& objects,
  148. const std::vector<std::string>& external_objects,
  149. const std::vector<std::string>& provides_requires);
  150. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  151. const char* ruleFileName,
  152. const cmTarget& target,
  153. const std::vector<std::string>& objects,
  154. const std::vector<std::string>& external_objects,
  155. const std::vector<std::string>& provides_requires);
  156. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  157. const char* ruleFileName,
  158. const cmTarget& target,
  159. const std::vector<std::string>& objects,
  160. const std::vector<std::string>& external_objects,
  161. const std::vector<std::string>& provides_requires);
  162. void WriteLibraryRule(std::ostream& ruleFileStream,
  163. const char* ruleFileName,
  164. const cmTarget& target,
  165. const std::vector<std::string>& objects,
  166. const std::vector<std::string>& external_objects,
  167. const char* linkRuleVar,
  168. const char* extraLinkFlags,
  169. const std::vector<std::string>& provides_requires);
  170. void WriteObjectsVariable(std::ostream& ruleFileStream,
  171. const cmTarget& target,
  172. const std::vector<std::string>& objects,
  173. const std::vector<std::string>& external_objects,
  174. std::string& variableName,
  175. std::string& variableNameExternal);
  176. void WriteTargetDependRule(const char* ruleFileName,
  177. const cmTarget& target,
  178. const std::vector<std::string>& objects);
  179. void WriteTargetCleanRule(const char *ruleFileName,
  180. const cmTarget& target,
  181. const std::vector<std::string>& files,
  182. const std::vector<std::string>& objects,
  183. const std::vector<std::string>& external_objects);
  184. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  185. const cmTarget& target,
  186. const std::vector<std::string>& provides_requires);
  187. void WriteCMakeArgument(std::ostream& os, const char* s);
  188. std::string GetTargetDirectory(const cmTarget& target);
  189. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  190. std::string GetObjectFileName(const cmTarget& target,
  191. const cmSourceFile& source);
  192. const char* GetSourceFileLanguage(const cmSourceFile& source);
  193. std::string ConvertToFullPath(const std::string& localPath);
  194. std::string ConvertToQuotedOutputPath(const char* p);
  195. void ConfigureOutputPaths();
  196. void FormatOutputPath(std::string& path, const char* name);
  197. void AppendTargetDepends(std::vector<std::string>& depends,
  198. const cmTarget& target);
  199. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  200. bool assume_unknown_is_file=false);
  201. void AppendRuleDepend(std::vector<std::string>& depends,
  202. const char* ruleFileName);
  203. void AppendCustomDepends(std::vector<std::string>& depends,
  204. const std::vector<cmCustomCommand>& ccs);
  205. void AppendCustomDepend(std::vector<std::string>& depends,
  206. const cmCustomCommand& cc);
  207. void AppendCustomCommands(std::vector<std::string>& commands,
  208. const std::vector<cmCustomCommand>& ccs);
  209. void AppendCustomCommand(std::vector<std::string>& commands,
  210. const cmCustomCommand& cc);
  211. void AppendCleanCommand(std::vector<std::string>& commands,
  212. const std::vector<std::string>& files);
  213. void AppendEcho(std::vector<std::string>& commands,
  214. const char* text);
  215. //==========================================================================
  216. bool SamePath(const char* path1, const char* path2);
  217. std::string ConvertToMakeTarget(const char* tgt);
  218. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  219. std::string CreateMakeVariable(const char* sin, const char* s2in);
  220. //==========================================================================
  221. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  222. void WriteJumpAndBuildRules(std::ostream& makefileStream);
  223. static cmDepends* GetDependsChecker(const std::string& lang,
  224. const char* dir,
  225. const char* objFile);
  226. private:
  227. // Map from target name to build directory containing it for
  228. // jump-and-build targets.
  229. struct RemoteTarget
  230. {
  231. std::string m_BuildDirectory;
  232. std::string m_FilePath;
  233. };
  234. std::map<cmStdString, RemoteTarget> m_JumpAndBuild;
  235. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  236. // Command used when a rule has no dependencies or commands.
  237. std::vector<std::string> m_EmptyCommands;
  238. //==========================================================================
  239. // Configuration settings.
  240. int m_MakefileVariableSize;
  241. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  242. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  243. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  244. std::string m_IncludeDirective;
  245. std::string m_MakeSilentFlag;
  246. std::string m_ExecutableOutputPath;
  247. std::string m_LibraryOutputPath;
  248. bool m_PassMakeflags;
  249. //==========================================================================
  250. // Flag for whether echo command needs quotes.
  251. bool m_EchoNeedsQuote;
  252. // List of make rule files that need to be included by the makefile.
  253. std::vector<std::string> m_IncludeRuleFiles;
  254. // Set of custom rule files that have been generated.
  255. std::set<cmStdString> m_CustomRuleFiles;
  256. // Set of object file names that will be built in this directory.
  257. std::set<cmStdString> m_ObjectFiles;
  258. };
  259. #endif