1
0

cmMakefileTargetGenerator.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmMakefileTargetGenerator_h
  4. #define cmMakefileTargetGenerator_h
  5. #include <cmConfigure.h>
  6. #include "cmCommonTargetGenerator.h"
  7. #include "cmLocalUnixMakefileGenerator3.h"
  8. #include "cmOSXBundleGenerator.h"
  9. #include <iosfwd>
  10. #include <map>
  11. #include <set>
  12. #include <string>
  13. #include <vector>
  14. class cmCustomCommandGenerator;
  15. class cmGeneratedFileStream;
  16. class cmGeneratorTarget;
  17. class cmGlobalUnixMakefileGenerator3;
  18. class cmSourceFile;
  19. /** \class cmMakefileTargetGenerator
  20. * \brief Support Routines for writing makefiles
  21. *
  22. */
  23. class cmMakefileTargetGenerator : public cmCommonTargetGenerator
  24. {
  25. public:
  26. // constructor to set the ivars
  27. cmMakefileTargetGenerator(cmGeneratorTarget* target);
  28. ~cmMakefileTargetGenerator() CM_OVERRIDE;
  29. // construct using this factory call
  30. static cmMakefileTargetGenerator* New(cmGeneratorTarget* tgt);
  31. /* the main entry point for this class. Writes the Makefiles associated
  32. with this target */
  33. virtual void WriteRuleFiles() = 0;
  34. /* return the number of actions that have progress reporting on them */
  35. virtual unsigned long GetNumberOfProgressActions()
  36. {
  37. return this->NumberOfProgressActions;
  38. }
  39. std::string GetProgressFileNameFull() { return this->ProgressFileNameFull; }
  40. cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; }
  41. protected:
  42. // create the file and directory etc
  43. void CreateRuleFile();
  44. // outputs the rules for object files and custom commands used by
  45. // this target
  46. void WriteTargetBuildRules();
  47. // write some common code at the top of build.make
  48. void WriteCommonCodeRules();
  49. void WriteTargetLanguageFlags();
  50. // write the provide require rules for this target
  51. void WriteTargetRequiresRules();
  52. // write the clean rules for this target
  53. void WriteTargetCleanRules();
  54. // write the depend rules for this target
  55. void WriteTargetDependRules();
  56. // write rules for Mac OS X Application Bundle content.
  57. struct MacOSXContentGeneratorType
  58. : cmOSXBundleGenerator::MacOSXContentGeneratorType
  59. {
  60. MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen)
  61. : Generator(gen)
  62. {
  63. }
  64. void operator()(cmSourceFile const& source,
  65. const char* pkgloc) CM_OVERRIDE;
  66. private:
  67. cmMakefileTargetGenerator* Generator;
  68. };
  69. friend struct MacOSXContentGeneratorType;
  70. // write the rules for an object
  71. void WriteObjectRuleFiles(cmSourceFile const& source);
  72. // write the build rule for an object
  73. void WriteObjectBuildFile(std::string& obj, const std::string& lang,
  74. cmSourceFile const& source,
  75. std::vector<std::string>& depends);
  76. // write the depend.make file for an object
  77. void WriteObjectDependRules(cmSourceFile const& source,
  78. std::vector<std::string>& depends);
  79. // write the build rule for a custom command
  80. void GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg);
  81. // write a rule to drive building of more than one output from
  82. // another rule
  83. void GenerateExtraOutput(const char* out, const char* in,
  84. bool symbolic = false);
  85. void MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress&) const;
  86. // write out the variable that lists the objects for this target
  87. void WriteObjectsVariable(std::string& variableName,
  88. std::string& variableNameExternal,
  89. bool useWatcomQuote);
  90. void WriteObjectsString(std::string& buildObjs);
  91. void WriteObjectsStrings(std::vector<std::string>& objStrings,
  92. std::string::size_type limit = std::string::npos);
  93. // write the driver rule to build target outputs
  94. void WriteTargetDriverRule(const std::string& main_output, bool relink);
  95. void DriveCustomCommands(std::vector<std::string>& depends);
  96. // append intertarget dependencies
  97. void AppendTargetDepends(std::vector<std::string>& depends);
  98. // Append object file dependencies.
  99. void AppendObjectDepends(std::vector<std::string>& depends);
  100. // Append link rule dependencies (objects, etc.).
  101. void AppendLinkDepends(std::vector<std::string>& depends);
  102. // Lookup the link rule for this target.
  103. std::string GetLinkRule(const std::string& linkRuleVar);
  104. /** Create a script to hold link rules and a command to invoke the
  105. script at build time. */
  106. void CreateLinkScript(const char* name,
  107. std::vector<std::string> const& link_commands,
  108. std::vector<std::string>& makefile_commands,
  109. std::vector<std::string>& makefile_depends);
  110. /** Create a response file with the given set of options. Returns
  111. the relative path from the target build working directory to the
  112. response file name. */
  113. std::string CreateResponseFile(const char* name, std::string const& options,
  114. std::vector<std::string>& makefile_depends);
  115. bool CheckUseResponseFileForObjects(std::string const& l) const;
  116. bool CheckUseResponseFileForLibraries(std::string const& l) const;
  117. /** Create list of flags for link libraries. */
  118. void CreateLinkLibs(std::string& linkLibs, bool relink, bool useResponseFile,
  119. std::vector<std::string>& makefile_depends,
  120. bool useWatcomQuote);
  121. /** Create lists of object files for linking and cleaning. */
  122. void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  123. bool useResponseFile, std::string& buildObjs,
  124. std::vector<std::string>& makefile_depends,
  125. bool useWatcomQuote);
  126. /** Add commands for generate def files */
  127. void GenDefFile(std::vector<std::string>& real_link_commands,
  128. std::string& linkFlags);
  129. void AddIncludeFlags(std::string& flags,
  130. const std::string& lang) CM_OVERRIDE;
  131. virtual void CloseFileStreams();
  132. cmLocalUnixMakefileGenerator3* LocalGenerator;
  133. cmGlobalUnixMakefileGenerator3* GlobalGenerator;
  134. enum CustomCommandDriveType
  135. {
  136. OnBuild,
  137. OnDepends,
  138. OnUtility
  139. };
  140. CustomCommandDriveType CustomCommandDriver;
  141. // the full path to the build file
  142. std::string BuildFileName;
  143. std::string BuildFileNameFull;
  144. // the full path to the progress file
  145. std::string ProgressFileNameFull;
  146. unsigned long NumberOfProgressActions;
  147. bool NoRuleMessages;
  148. // the path to the directory the build file is in
  149. std::string TargetBuildDirectory;
  150. std::string TargetBuildDirectoryFull;
  151. // the stream for the build file
  152. cmGeneratedFileStream* BuildFileStream;
  153. // the stream for the flag file
  154. std::string FlagFileNameFull;
  155. cmGeneratedFileStream* FlagFileStream;
  156. class StringList : public std::vector<std::string>
  157. {
  158. };
  159. std::map<std::string, StringList> FlagFileDepends;
  160. // the stream for the info file
  161. std::string InfoFileNameFull;
  162. cmGeneratedFileStream* InfoFileStream;
  163. // files to clean
  164. std::vector<std::string> CleanFiles;
  165. // objects used by this target
  166. std::vector<std::string> Objects;
  167. std::vector<std::string> ExternalObjects;
  168. // Set of object file names that will be built in this directory.
  169. std::set<std::string> ObjectFiles;
  170. // Set of extra output files to be driven by the build.
  171. std::set<std::string> ExtraFiles;
  172. typedef std::map<std::string, std::string> MultipleOutputPairsType;
  173. MultipleOutputPairsType MultipleOutputPairs;
  174. bool WriteMakeRule(std::ostream& os, const char* comment,
  175. const std::vector<std::string>& outputs,
  176. const std::vector<std::string>& depends,
  177. const std::vector<std::string>& commands,
  178. bool in_help = false);
  179. // Target name info.
  180. std::string TargetNameOut;
  181. std::string TargetNameSO;
  182. std::string TargetNameReal;
  183. std::string TargetNameImport;
  184. std::string TargetNamePDB;
  185. // Mac OS X content info.
  186. std::set<std::string> MacContentFolders;
  187. cmOSXBundleGenerator* OSXBundleGenerator;
  188. MacOSXContentGeneratorType* MacOSXContentGenerator;
  189. };
  190. #endif