cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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::ostream &filestr);
  159. // write the depend.make file for an object
  160. void WriteObjectDependRules(cmSourceFile& source,
  161. std::vector<std::string>& depends);
  162. // this is used only by WriteObjectDependFile
  163. bool GenerateDependsMakeFile(const std::string& lang,
  164. const char* objFile);
  165. // return the appropriate depends checker
  166. cmDepends* GetDependsChecker(const std::string& lang,
  167. bool verbose);
  168. void GenerateCustomRuleFile(const cmCustomCommand& cc,
  169. const char *dir,
  170. std::ostream &ruleStream);
  171. // these three make some simple changes and then call WriteLibraryRule
  172. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  173. const char* ruleFileName,
  174. cmTarget& target,
  175. const std::vector<std::string>& objects,
  176. const std::vector<std::string>& external_objects,
  177. std::vector<std::string>& cleanFiles);
  178. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  179. const char* ruleFileName,
  180. cmTarget& target,
  181. const std::vector<std::string>& objects,
  182. const std::vector<std::string>& external_objects,
  183. std::vector<std::string>& cleanFiles);
  184. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  185. const char* ruleFileName,
  186. cmTarget& target,
  187. const std::vector<std::string>& objects,
  188. const std::vector<std::string>& external_objects,
  189. std::vector<std::string>& cleanFiles);
  190. // the main code for writing the Executable target rules
  191. void WriteExecutableRule(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 method for writing library rules
  198. void WriteLibraryRule(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. const char* linkRuleVar,
  204. const char* extraLinkFlags,
  205. std::vector<std::string>& cleanFiles);
  206. void WriteLocalMakefile();
  207. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  208. const char* dependency);
  209. void WriteConvenienceRule(std::ostream& ruleFileStream,
  210. const char* realTarget,
  211. const char* helpTarget);
  212. void WriteObjectsVariable(std::ostream& ruleFileStream,
  213. cmTarget& target,
  214. const std::vector<std::string>& objects,
  215. const std::vector<std::string>& external_objects,
  216. std::string& variableName,
  217. std::string& variableNameExternal);
  218. void WriteTargetDependRule(std::ostream& ruleFileStream,
  219. cmTarget& target,
  220. const std::vector<std::string>& objects);
  221. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  222. cmTarget& target,
  223. const std::vector<std::string>& files);
  224. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  225. cmTarget& target,
  226. const std::vector<std::string>& objects);
  227. std::string GetTargetDirectory(cmTarget& target);
  228. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  229. std::string GetObjectFileName(cmTarget& target,
  230. const cmSourceFile& source);
  231. const char* GetSourceFileLanguage(const cmSourceFile& source);
  232. std::string ConvertToQuotedOutputPath(const char* p);
  233. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  234. bool assume_unknown_is_file=false);
  235. void AppendRuleDepend(std::vector<std::string>& depends,
  236. const char* ruleFileName);
  237. void AppendCustomDepends(std::vector<std::string>& depends,
  238. const std::vector<cmCustomCommand>& ccs);
  239. void AppendCustomDepend(std::vector<std::string>& depends,
  240. const cmCustomCommand& cc);
  241. void AppendCustomCommands(std::vector<std::string>& commands,
  242. const std::vector<cmCustomCommand>& ccs);
  243. void AppendCustomCommand(std::vector<std::string>& commands,
  244. const cmCustomCommand& cc);
  245. void AppendCleanCommand(std::vector<std::string>& commands,
  246. const std::vector<std::string>& files);
  247. //==========================================================================
  248. bool SamePath(const char* path1, const char* path2);
  249. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  250. std::string CreateMakeVariable(const char* sin, const char* s2in);
  251. //==========================================================================
  252. void ComputeHomeRelativeOutputPath();
  253. private:
  254. std::map<cmStdString, IntegrityCheckSetMap> m_CheckDependFiles;
  255. //==========================================================================
  256. // Configuration settings.
  257. int m_MakefileVariableSize;
  258. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  259. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  260. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  261. std::string m_IncludeDirective;
  262. std::string m_MakeSilentFlag;
  263. std::string m_ExecutableOutputPath;
  264. std::string m_LibraryOutputPath;
  265. bool m_PassMakeflags;
  266. //==========================================================================
  267. // Flag for whether echo command needs quotes.
  268. bool m_EchoNeedsQuote;
  269. std::string m_HomeRelativeOutputPath;
  270. // Set of object file names that will be built in this directory.
  271. std::set<cmStdString> m_ObjectFiles;
  272. std::map<cmStdString,std::vector<cmTarget *> > m_LocalObjectFiles;
  273. };
  274. #endif