cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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, RelativeRoot root);
  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<cmSourceFile *> {};
  107. struct IntegrityCheckSetMap: public std::map<cmStdString, IntegrityCheckSet> {};
  108. std::map<cmStdString, IntegrityCheckSetMap> &GetIntegrityCheckSet()
  109. { return m_CheckDependFiles;}
  110. void AppendTargetDepends(std::vector<std::string>& depends,
  111. cmTarget& target);
  112. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  113. cmTarget& target);
  114. void AppendEcho(std::vector<std::string>& commands,
  115. const char* text);
  116. protected:
  117. // write the depend info
  118. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  119. // write the target rules for the local Makefile into the stream
  120. void WriteLocalMakefileTargets(std::ostream& ruleFileStream);
  121. // write the local help rule
  122. void WriteHelpRule(std::ostream& ruleFileStream);
  123. // create the cd to home commands
  124. void CreateJumpCommand(std::vector<std::string>& commands,
  125. const char *MakefileName,
  126. std::string & localName);
  127. // these two methods just compute reasonable values for m_LibraryOutputPath and
  128. // m_ExecutableOutputPath
  129. void ConfigureOutputPaths();
  130. void FormatOutputPath(std::string& path, const char* name);
  131. // this converts a file name that is relative to the StartOuputDirectory
  132. // into a full path
  133. std::string ConvertToFullPath(const std::string& localPath);
  134. // this is responsible for writing all of the rules for all this
  135. // directories custom commands (but not utility targets)
  136. void WriteCustomCommands(cmTarget &target,std::ostream& os,
  137. std::vector<std::string>& cleanFiles);
  138. // this method Writes the Directory informaiton files
  139. void WriteDirectoryInformationFile();
  140. // cleanup the name of a potential target
  141. std::string ConvertToMakeTarget(const char* tgt);
  142. // used in writing out Cmake files such as WriteDirectoryInformation
  143. void WriteCMakeArgument(std::ostream& os, const char* s);
  144. // write out all the rules for this target
  145. void WriteTargetRuleFiles(cmTarget& target);
  146. void WriteUtilityRuleFiles(cmTarget& target);
  147. // create the rule files for an object
  148. void WriteObjectRuleFiles(cmTarget& target,
  149. cmSourceFile& source,
  150. std::vector<std::string>& objects,
  151. std::ostream &filestr);
  152. // write the build rule for an object
  153. void WriteObjectBuildFile(std::string &obj,
  154. const char *lang,
  155. cmTarget& target,
  156. cmSourceFile& source,
  157. std::vector<std::string>& depends,
  158. std::string &depMakeFile,
  159. std::ostream &filestr);
  160. // write the depend.make file for an object
  161. void WriteObjectDependRules(std::ostream& ruleFileStream,
  162. std::string& obj,
  163. const char *lang,
  164. cmSourceFile& source,
  165. std::vector<std::string>& depends,
  166. std::string& depMarkFile);
  167. // this is used only by WriteObjectDependFile
  168. bool GenerateDependsMakeFile(const std::string& lang,
  169. const char* objFile,
  170. std::string& depMakeFile,
  171. std::string& depMarkFile);
  172. // return the appropriate depends checker
  173. cmDepends* GetDependsChecker(const std::string& lang,
  174. bool verbose);
  175. void GenerateCustomRuleFile(const cmCustomCommand& cc,
  176. const char *dir,
  177. std::ostream &ruleStream);
  178. // these three make some simple changes and then call WriteLibraryRule
  179. void WriteStaticLibraryRule(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 WriteSharedLibraryRule(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. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  192. const char* ruleFileName,
  193. cmTarget& target,
  194. const std::vector<std::string>& objects,
  195. const std::vector<std::string>& external_objects,
  196. std::vector<std::string>& cleanFiles);
  197. // the main code for writing the Executable target rules
  198. void WriteExecutableRule(std::ostream& ruleFileStream,
  199. const char* ruleFileName,
  200. cmTarget& target,
  201. const std::vector<std::string>& objects,
  202. const std::vector<std::string>& external_objects,
  203. std::vector<std::string>& cleanFiles);
  204. // the main method for writing library rules
  205. void WriteLibraryRule(std::ostream& ruleFileStream,
  206. const char* ruleFileName,
  207. cmTarget& target,
  208. const std::vector<std::string>& objects,
  209. const std::vector<std::string>& external_objects,
  210. const char* linkRuleVar,
  211. const char* extraLinkFlags,
  212. std::vector<std::string>& cleanFiles);
  213. void WriteLocalMakefile();
  214. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  215. const char* dependency);
  216. void WriteConvenienceRule(std::ostream& ruleFileStream,
  217. const char* realTarget,
  218. const char* helpTarget);
  219. void WriteObjectsVariable(std::ostream& ruleFileStream,
  220. cmTarget& target,
  221. const std::vector<std::string>& objects,
  222. const std::vector<std::string>& external_objects,
  223. std::string& variableName,
  224. std::string& variableNameExternal);
  225. void WriteTargetDependRule(std::ostream& ruleFileStream,
  226. cmTarget& target,
  227. const std::vector<std::string>& objects);
  228. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  229. cmTarget& target,
  230. const std::vector<std::string>& files);
  231. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  232. cmTarget& target,
  233. const std::vector<std::string>& objects);
  234. std::string GetTargetDirectory(cmTarget& target);
  235. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  236. std::string GetObjectFileName(cmTarget& target,
  237. const cmSourceFile& source);
  238. const char* GetSourceFileLanguage(const cmSourceFile& source);
  239. std::string ConvertToQuotedOutputPath(const char* p);
  240. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  241. bool assume_unknown_is_file=false);
  242. void AppendRuleDepend(std::vector<std::string>& depends,
  243. const char* ruleFileName);
  244. void AppendCustomDepends(std::vector<std::string>& depends,
  245. const std::vector<cmCustomCommand>& ccs);
  246. void AppendCustomDepend(std::vector<std::string>& depends,
  247. const cmCustomCommand& cc);
  248. void AppendCustomCommands(std::vector<std::string>& commands,
  249. const std::vector<cmCustomCommand>& ccs);
  250. void AppendCustomCommand(std::vector<std::string>& commands,
  251. const cmCustomCommand& cc);
  252. void AppendCleanCommand(std::vector<std::string>& commands,
  253. const std::vector<std::string>& files);
  254. //==========================================================================
  255. bool SamePath(const char* path1, const char* path2);
  256. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  257. std::string CreateMakeVariable(const char* sin, const char* s2in);
  258. //==========================================================================
  259. void ComputeHomeRelativeOutputPath();
  260. private:
  261. std::map<cmStdString, IntegrityCheckSetMap> m_CheckDependFiles;
  262. //==========================================================================
  263. // Configuration settings.
  264. int m_MakefileVariableSize;
  265. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  266. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  267. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  268. std::string m_IncludeDirective;
  269. std::string m_MakeSilentFlag;
  270. std::string m_ExecutableOutputPath;
  271. std::string m_LibraryOutputPath;
  272. bool m_PassMakeflags;
  273. //==========================================================================
  274. // Flag for whether echo command needs quotes.
  275. bool m_EchoNeedsQuote;
  276. std::string m_HomeRelativeOutputPath;
  277. // Set of object file names that will be built in this directory.
  278. std::set<cmStdString> m_ObjectFiles;
  279. std::map<cmStdString,std::vector<cmTarget *> > m_LocalObjectFiles;
  280. };
  281. #endif