cmLocalUnixMakefileGenerator2.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. #if defined(__sgi) && !defined(__GNUC__)
  17. # pragma set woff 1375 /* base class destructor not virtual */
  18. #endif
  19. class cmCustomCommand;
  20. class cmDependInformation;
  21. class cmDepends;
  22. class cmMakeDepend;
  23. class cmTarget;
  24. class cmSourceFile;
  25. /** \class cmLocalUnixMakefileGenerator2
  26. * \brief Write a LocalUnix makefiles.
  27. *
  28. * cmLocalUnixMakefileGenerator2 produces a LocalUnix makefile from its
  29. * member m_Makefile.
  30. */
  31. class cmLocalUnixMakefileGenerator2 : public cmLocalGenerator
  32. {
  33. public:
  34. ///! Set cache only and recurse to false by default.
  35. cmLocalUnixMakefileGenerator2();
  36. virtual ~cmLocalUnixMakefileGenerator2();
  37. /** Set the command used when there are no dependencies or rules for
  38. a target. This is used to avoid errors on some make
  39. implementations. */
  40. void SetEmptyCommand(const char* cmd);
  41. /** Set whether the echo command needs its argument quoted. */
  42. void SetEchoNeedsQuote(bool b) { m_EchoNeedsQuote = b; }
  43. /**
  44. * Set to true if the shell being used is the windows shell.
  45. * This controls if statements in the makefile and the SHELL variable.
  46. * The default is false.
  47. */
  48. void SetWindowsShell(bool v) {m_WindowsShell = v;}
  49. /**
  50. * Set the string used to include one makefile into another default
  51. * is include.
  52. */
  53. void SetIncludeDirective(const char* s) { m_IncludeDirective = s; }
  54. /**
  55. * Set the flag used to keep the make program silent.
  56. */
  57. void SetMakeSilentFlag(const char* s) { m_MakeSilentFlag = s; }
  58. /**
  59. * Set max makefile variable size, default is 0 which means unlimited.
  60. */
  61. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  62. /**
  63. * If ignore lib prefix is true, then do not strip lib from the name
  64. * of a library.
  65. */
  66. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  67. /**
  68. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  69. * that do not use environment variables.
  70. *
  71. */
  72. void SetPassMakeflags(bool s){m_PassMakeflags = s;}
  73. /**
  74. * Generate the makefile for this directory.
  75. */
  76. virtual void Generate();
  77. /** Called from command-line hook to scan dependencies. */
  78. static bool ScanDependencies(std::vector<std::string> const& args);
  79. /** Called from command-line hook to check dependencies. */
  80. static void CheckDependencies(cmMakefile* mf);
  81. protected:
  82. void GenerateMakefile();
  83. void GenerateCMakefile();
  84. void GenerateDirectoryInformationFile();
  85. void GenerateTargetRuleFile(const cmTarget& target);
  86. void GenerateObjectRuleFile(const cmTarget& target,
  87. const cmSourceFile& source,
  88. std::vector<std::string>& objects,
  89. std::vector<std::string>& provides_requires);
  90. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  91. void GenerateUtilityRuleFile(const cmTarget& target);
  92. bool GenerateDependsMakeFile(const std::string& lang,
  93. const char* objFile,
  94. std::string& depMakeFile,
  95. std::string& depMarkFile);
  96. void WriteMakeRule(std::ostream& os,
  97. const char* comment,
  98. const char* target,
  99. const std::vector<std::string>& depends,
  100. const std::vector<std::string>& commands);
  101. void WriteDivider(std::ostream& os);
  102. void WriteDisclaimer(std::ostream& os);
  103. void WriteMakeVariables(std::ostream& makefileStream);
  104. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  105. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  106. void WriteRuleFileIncludes(std::ostream& makefileStream);
  107. void WriteAllRules(std::ostream& makefileStream);
  108. void WritePassRules(std::ostream& makefileStream, const char* pass);
  109. void WriteDriverRules(std::ostream& makefileStream, const char* pass,
  110. const char* local1, const char* local2=0);
  111. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  112. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  113. const char* subdir, std::string& last);
  114. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  115. const char* order, const std::string& last);
  116. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  117. const char* dependency);
  118. void WriteConvenienceRules(std::ostream& ruleFileStream,
  119. const cmTarget& target,
  120. const char* targetOutPath);
  121. void WriteConvenienceRule(std::ostream& ruleFileStream,
  122. const char* realTarget,
  123. const char* helpTarget);
  124. void WriteExecutableRule(std::ostream& ruleFileStream,
  125. const char* ruleFileName,
  126. const cmTarget& target,
  127. const std::vector<std::string>& objects,
  128. const std::vector<std::string>& external_objects,
  129. const std::vector<std::string>& provides_requires);
  130. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  131. const char* ruleFileName,
  132. const cmTarget& target,
  133. const std::vector<std::string>& objects,
  134. const std::vector<std::string>& external_objects,
  135. const std::vector<std::string>& provides_requires);
  136. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  137. const char* ruleFileName,
  138. const cmTarget& target,
  139. const std::vector<std::string>& objects,
  140. const std::vector<std::string>& external_objects,
  141. const std::vector<std::string>& provides_requires);
  142. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  143. const char* ruleFileName,
  144. const cmTarget& target,
  145. const std::vector<std::string>& objects,
  146. const std::vector<std::string>& external_objects,
  147. const std::vector<std::string>& provides_requires);
  148. void WriteLibraryRule(std::ostream& ruleFileStream,
  149. const char* ruleFileName,
  150. const cmTarget& target,
  151. const std::vector<std::string>& objects,
  152. const std::vector<std::string>& external_objects,
  153. const char* linkRuleVar,
  154. const char* extraLinkFlags,
  155. const std::vector<std::string>& provides_requires);
  156. void WriteObjectsVariable(std::ostream& ruleFileStream,
  157. const cmTarget& target,
  158. const std::vector<std::string>& objects,
  159. const std::vector<std::string>& external_objects,
  160. std::string& variableName,
  161. std::string& variableNameExternal);
  162. void WriteTargetDependsRule(std::ostream& ruleFileStream,
  163. const char* ruleFileName,
  164. const cmTarget& target,
  165. const std::vector<std::string>& objects);
  166. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  167. const cmTarget& target,
  168. const std::vector<std::string>& files);
  169. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  170. const cmTarget& target,
  171. const std::vector<std::string>& provides_requires);
  172. void WriteLocalCleanRule(std::ostream& makefileStream);
  173. void WriteCMakeArgument(std::ostream& os, const char* s);
  174. std::string GetTargetDirectory(const cmTarget& target);
  175. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  176. std::string GetObjectFileName(const cmTarget& target,
  177. const cmSourceFile& source);
  178. const char* GetSourceFileLanguage(const cmSourceFile& source);
  179. std::string ConvertToFullPath(const std::string& localPath);
  180. std::string ConvertToRelativeOutputPath(const char* p);
  181. std::string ConvertToQuotedOutputPath(const char* p);
  182. void ConfigureOutputPaths();
  183. void FormatOutputPath(std::string& path, const char* name);
  184. void AppendTargetDepends(std::vector<std::string>& depends,
  185. const cmTarget& target);
  186. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  187. bool assume_unknown_is_file=false);
  188. void AppendRuleDepend(std::vector<std::string>& depends,
  189. const char* ruleFileName);
  190. void AppendCustomDepends(std::vector<std::string>& depends,
  191. const std::vector<cmCustomCommand>& ccs);
  192. void AppendCustomDepend(std::vector<std::string>& depends,
  193. const cmCustomCommand& cc);
  194. void AppendCustomCommands(std::vector<std::string>& commands,
  195. const std::vector<cmCustomCommand>& ccs);
  196. void AppendCustomCommand(std::vector<std::string>& commands,
  197. const cmCustomCommand& cc);
  198. void AppendCleanCommand(std::vector<std::string>& commands,
  199. const std::vector<std::string>& files);
  200. void AppendEcho(std::vector<std::string>& commands,
  201. const char* text);
  202. //==========================================================================
  203. bool SamePath(const char* path1, const char* path2);
  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. #if defined(__sgi) && !defined(__GNUC__)
  251. # pragma reset woff 1375 /* base class destructor not virtual */
  252. #endif
  253. #endif