cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. cmLocalUnixMakefileGenerator3();
  32. virtual ~cmLocalUnixMakefileGenerator3();
  33. /**
  34. * Generate the makefile for this directory.
  35. */
  36. virtual void Generate();
  37. /** creates the common disclainer text at the top of each makefile */
  38. void WriteDisclaimer(std::ostream& os);
  39. // this returns the relative path between the HomeOutputDirectory and this
  40. // local generators StartOutputDirectory
  41. std::string GetHomeRelativeOutputPath();
  42. // Write out a make rule
  43. void WriteMakeRule(std::ostream& os,
  44. const char* comment,
  45. const char* target,
  46. const std::vector<std::string>& depends,
  47. const std::vector<std::string>& commands);
  48. // write the main variables used by the makefiles
  49. void WriteMakeVariables(std::ostream& makefileStream);
  50. // write a comment line #====... in the stream
  51. void WriteDivider(std::ostream& os);
  52. /**
  53. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  54. * that do not use environment variables.
  55. *
  56. */
  57. void SetPassMakeflags(bool s){m_PassMakeflags = s;}
  58. bool GetPassMakeflags() { return m_PassMakeflags; }
  59. /**
  60. * Set the flag used to keep the make program silent.
  61. */
  62. void SetMakeSilentFlag(const char* s) { m_MakeSilentFlag = s; }
  63. std::string &GetMakeSilentFlag() { return m_MakeSilentFlag; }
  64. /** Set whether the echo command needs its argument quoted. */
  65. void SetEchoNeedsQuote(bool b) { m_EchoNeedsQuote = b; }
  66. /**
  67. * Set to true if the shell being used is the windows shell.
  68. * This controls if statements in the makefile and the SHELL variable.
  69. * The default is false.
  70. */
  71. void SetWindowsShell(bool v) {m_WindowsShell = v;}
  72. /**
  73. * Set the string used to include one makefile into another default
  74. * is include.
  75. */
  76. void SetIncludeDirective(const char* s) { m_IncludeDirective = s; }
  77. const char *GetIncludeDirective() { return m_IncludeDirective.c_str(); }
  78. /**
  79. * Set max makefile variable size, default is 0 which means unlimited.
  80. */
  81. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  82. /**
  83. * If ignore lib prefix is true, then do not strip lib from the name
  84. * of a library.
  85. */
  86. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  87. /** Called from command-line hook to scan dependencies. */
  88. static bool ScanDependencies(std::vector<std::string> const& args);
  89. /** Called from command-line hook to check dependencies. */
  90. static void CheckDependencies(cmMakefile* mf);
  91. /** write some extra rules suahc as make test etc */
  92. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  93. void WriteTargetIncludes(std::ostream& makefileStream,const char *file,
  94. const char *rule);
  95. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  96. std::string ConvertToRelativeOutputPath(const char* p);
  97. std::string GetRelativeTargetDirectory(const cmTarget& target);
  98. void WriteLocalCleanRule(std::ostream& makefileStream);
  99. // List the files for which to check dependency integrity. Each
  100. // language has its own list because integrity may be checked
  101. // differently.
  102. struct IntegrityCheckSet: public std::set<cmStdString> {};
  103. std::map<cmStdString, IntegrityCheckSet> &GetIntegrityCheckSet()
  104. { return m_CheckDependFiles;}
  105. protected:
  106. // these two methods just compute reasonable values for m_LibraryOutputPath and
  107. // m_ExecutableOutputPath
  108. void ConfigureOutputPaths();
  109. void FormatOutputPath(std::string& path, const char* name);
  110. // this converts a file name that is relative to the StartOuputDirectory
  111. // into a full path
  112. std::string ConvertToFullPath(const std::string& localPath);
  113. // this is responsible for writing all of the rules for all this
  114. // directories custom commands (but not utility targets)
  115. void WriteCustomCommands();
  116. // this method Writes the Directory informaiton files
  117. void WriteDirectoryInformationFile();
  118. // cleanup the name of a potential target
  119. std::string ConvertToMakeTarget(const char* tgt);
  120. // used in writing out Cmake files such as WriteDirectoryInformation
  121. void WriteCMakeArgument(std::ostream& os, const char* s);
  122. // write out all the rules for this target
  123. void WriteTargetRuleFiles(const cmTarget& target);
  124. void WriteUtilityRuleFiles(const cmTarget& target);
  125. // create the rule files for an object
  126. void WriteObjectRuleFiles(const cmTarget& target,
  127. const cmSourceFile& source,
  128. std::vector<std::string>& objects,
  129. std::vector<std::string>& provides_requires);
  130. // write the build rule for an object
  131. void WriteObjectBuildFile(std::string &obj,
  132. const char *lang,
  133. const cmTarget& target,
  134. const cmSourceFile& source,
  135. std::vector<std::string>& depends,
  136. std::string &depMakeFile,
  137. std::vector<std::string>& provides_requires);
  138. // write the depend.make file for an object
  139. void WriteObjectDependFile(std::string& obj,
  140. const char *lang,
  141. const cmSourceFile& source,
  142. std::vector<std::string>& depends,
  143. std::string& depMarkFile);
  144. // this is used only by WriteObjectDependFile
  145. bool GenerateDependsMakeFile(const std::string& lang,
  146. const char* objFile,
  147. std::string& depMakeFile,
  148. std::string& depMarkFile);
  149. // return the appropriate depends checker
  150. static cmDepends* GetDependsChecker(const std::string& lang,
  151. const char* dir,
  152. const char* objFile);
  153. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  154. // these three make some simple changes and then call WriteLibraryRule
  155. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  156. const char* ruleFileName,
  157. const cmTarget& target,
  158. const std::vector<std::string>& objects,
  159. const std::vector<std::string>& external_objects,
  160. const std::vector<std::string>& provides_requires);
  161. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  162. const char* ruleFileName,
  163. const cmTarget& target,
  164. const std::vector<std::string>& objects,
  165. const std::vector<std::string>& external_objects,
  166. const std::vector<std::string>& provides_requires);
  167. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  168. const char* ruleFileName,
  169. const cmTarget& target,
  170. const std::vector<std::string>& objects,
  171. const std::vector<std::string>& external_objects,
  172. const std::vector<std::string>& provides_requires);
  173. // the main code for writing the Executable target rules
  174. void WriteExecutableRule(std::ostream& ruleFileStream,
  175. const char* ruleFileName,
  176. const cmTarget& target,
  177. const std::vector<std::string>& objects,
  178. const std::vector<std::string>& external_objects,
  179. const std::vector<std::string>& provides_requires);
  180. // the main method for writing library rules
  181. void WriteLibraryRule(std::ostream& ruleFileStream,
  182. const char* ruleFileName,
  183. const cmTarget& target,
  184. const std::vector<std::string>& objects,
  185. const std::vector<std::string>& external_objects,
  186. const char* linkRuleVar,
  187. const char* extraLinkFlags,
  188. const std::vector<std::string>& provides_requires);
  189. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  190. const char* dependency);
  191. void WriteConvenienceRule(std::ostream& ruleFileStream,
  192. const char* realTarget,
  193. const char* helpTarget);
  194. void WriteObjectsVariable(std::ostream& ruleFileStream,
  195. const cmTarget& target,
  196. const std::vector<std::string>& objects,
  197. const std::vector<std::string>& external_objects,
  198. std::string& variableName,
  199. std::string& variableNameExternal);
  200. void WriteTargetDependRule(const char* ruleFileName,
  201. const cmTarget& target,
  202. const std::vector<std::string>& objects);
  203. void WriteTargetCleanRule(const char *ruleFileName,
  204. const cmTarget& target,
  205. const std::vector<std::string>& files,
  206. const std::vector<std::string>& objects,
  207. const std::vector<std::string>& external_objects);
  208. std::string GetTargetDirectory(const cmTarget& target);
  209. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  210. std::string GetObjectFileName(const cmTarget& target,
  211. const cmSourceFile& source);
  212. const char* GetSourceFileLanguage(const cmSourceFile& source);
  213. std::string ConvertToQuotedOutputPath(const char* p);
  214. void AppendTargetDepends(std::vector<std::string>& depends,
  215. const cmTarget& target);
  216. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  217. bool assume_unknown_is_file=false);
  218. void AppendRuleDepend(std::vector<std::string>& depends,
  219. const char* ruleFileName);
  220. void AppendCustomDepends(std::vector<std::string>& depends,
  221. const std::vector<cmCustomCommand>& ccs);
  222. void AppendCustomDepend(std::vector<std::string>& depends,
  223. const cmCustomCommand& cc);
  224. void AppendCustomCommands(std::vector<std::string>& commands,
  225. const std::vector<cmCustomCommand>& ccs);
  226. void AppendCustomCommand(std::vector<std::string>& commands,
  227. const cmCustomCommand& cc);
  228. void AppendCleanCommand(std::vector<std::string>& commands,
  229. const std::vector<std::string>& files);
  230. void AppendEcho(std::vector<std::string>& commands,
  231. const char* text);
  232. //==========================================================================
  233. bool SamePath(const char* path1, const char* path2);
  234. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  235. std::string CreateMakeVariable(const char* sin, const char* s2in);
  236. //==========================================================================
  237. private:
  238. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  239. //==========================================================================
  240. // Configuration settings.
  241. int m_MakefileVariableSize;
  242. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  243. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  244. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  245. std::string m_IncludeDirective;
  246. std::string m_MakeSilentFlag;
  247. std::string m_ExecutableOutputPath;
  248. std::string m_LibraryOutputPath;
  249. bool m_PassMakeflags;
  250. //==========================================================================
  251. // Flag for whether echo command needs quotes.
  252. bool m_EchoNeedsQuote;
  253. // Set of custom rule files that have been generated.
  254. std::set<cmStdString> m_CustomRuleFiles;
  255. // Set of object file names that will be built in this directory.
  256. std::set<cmStdString> m_ObjectFiles;
  257. };
  258. #endif