cmMakefileTargetGenerator.h 8.3 KB

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