cmLocalUnixMakefileGenerator3.h 14 KB

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