cmMakefileTargetGenerator.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 "cmLocalUnixMakefileGenerator3.h"
  13. #include "cmOSXBundleGenerator.h"
  14. class cmCustomCommandGenerator;
  15. class cmDependInformation;
  16. class cmDepends;
  17. class cmGeneratorTarget;
  18. class cmGeneratedFileStream;
  19. class cmGlobalUnixMakefileGenerator3;
  20. class cmLocalUnixMakefileGenerator3;
  21. class cmMakefile;
  22. class cmTarget;
  23. class cmSourceFile;
  24. /** \class cmMakefileTargetGenerator
  25. * \brief Support Routines for writing makefiles
  26. *
  27. */
  28. class cmMakefileTargetGenerator
  29. {
  30. public:
  31. // constructor to set the ivars
  32. cmMakefileTargetGenerator(cmGeneratorTarget* target);
  33. virtual ~cmMakefileTargetGenerator();
  34. // construct using this factory call
  35. static cmMakefileTargetGenerator *New(cmGeneratorTarget *tgt);
  36. /* the main entry point for this class. Writes the Makefiles associated
  37. with this target */
  38. virtual void WriteRuleFiles() = 0;
  39. /* return the number of actions that have progress reporting on them */
  40. virtual unsigned long GetNumberOfProgressActions() {
  41. return this->NumberOfProgressActions;}
  42. std::string GetProgressFileNameFull()
  43. { return this->ProgressFileNameFull; }
  44. cmTarget* GetTarget() { return this->Target;}
  45. protected:
  46. // create the file and directory etc
  47. void CreateRuleFile();
  48. // outputs the rules for object files and custom commands used by
  49. // this target
  50. void WriteTargetBuildRules();
  51. // write some common code at the top of build.make
  52. void WriteCommonCodeRules();
  53. void WriteTargetLanguageFlags();
  54. // write the provide require rules for this target
  55. void WriteTargetRequiresRules();
  56. // write the clean rules for this target
  57. void WriteTargetCleanRules();
  58. // write the depend rules for this target
  59. void WriteTargetDependRules();
  60. // write rules for Mac OS X Application Bundle content.
  61. struct MacOSXContentGeneratorType :
  62. cmOSXBundleGenerator::MacOSXContentGeneratorType
  63. {
  64. MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen) :
  65. Generator(gen) {}
  66. void operator()(cmSourceFile const& source, const char* pkgloc);
  67. private:
  68. cmMakefileTargetGenerator* Generator;
  69. };
  70. friend struct MacOSXContentGeneratorType;
  71. // write the rules for an object
  72. void WriteObjectRuleFiles(cmSourceFile const& source);
  73. // write the build rule for an object
  74. void WriteObjectBuildFile(std::string &obj,
  75. const std::string& lang,
  76. cmSourceFile const& source,
  77. std::vector<std::string>& depends);
  78. // write the depend.make file for an object
  79. void WriteObjectDependRules(cmSourceFile const& source,
  80. std::vector<std::string>& depends);
  81. // write the build rule for a custom command
  82. void GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg);
  83. // write a rule to drive building of more than one output from
  84. // another rule
  85. void GenerateExtraOutput(const char* out, const char* in,
  86. bool symbolic = false);
  87. void MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress&) const;
  88. // write out the variable that lists the objects for this target
  89. void WriteObjectsVariable(std::string& variableName,
  90. std::string& variableNameExternal,
  91. bool useWatcomQuote);
  92. void WriteObjectsString(std::string& buildObjs);
  93. void WriteObjectsStrings(std::vector<std::string>& objStrings,
  94. std::string::size_type limit = std::string::npos);
  95. // write the driver rule to build target outputs
  96. void WriteTargetDriverRule(const std::string& main_output, bool relink);
  97. void DriveCustomCommands(std::vector<std::string>& depends);
  98. // Return the a string with -F flags on apple
  99. std::string GetFrameworkFlags(std::string const& l);
  100. void AppendFortranFormatFlags(std::string& flags,
  101. cmSourceFile const& source);
  102. // append intertarget dependencies
  103. void AppendTargetDepends(std::vector<std::string>& depends);
  104. // Append object file dependencies.
  105. void AppendObjectDepends(std::vector<std::string>& depends);
  106. // Append link rule dependencies (objects, etc.).
  107. void AppendLinkDepends(std::vector<std::string>& depends);
  108. // Lookup the link rule for this target.
  109. std::string GetLinkRule(const std::string& linkRuleVar);
  110. /** Create a script to hold link rules and a command to invoke the
  111. script at build time. */
  112. void CreateLinkScript(const char* name,
  113. std::vector<std::string> const& link_commands,
  114. std::vector<std::string>& makefile_commands,
  115. std::vector<std::string>& makefile_depends);
  116. /** Create a response file with the given set of options. Returns
  117. the relative path from the target build working directory to the
  118. response file name. */
  119. std::string CreateResponseFile(const char* name,
  120. std::string const& options,
  121. std::vector<std::string>& makefile_depends);
  122. /** Create list of flags for link libraries. */
  123. void CreateLinkLibs(std::string& linkLibs, bool relink,
  124. bool useResponseFile,
  125. std::vector<std::string>& makefile_depends,
  126. bool useWatcomQuote);
  127. /** Create lists of object files for linking and cleaning. */
  128. void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  129. bool useResponseFile, std::string& buildObjs,
  130. std::vector<std::string>& makefile_depends,
  131. bool useWatcomQuote);
  132. void AddIncludeFlags(std::string& flags, const std::string& lang);
  133. virtual void CloseFileStreams();
  134. void RemoveForbiddenFlags(const char* flagVar, const std::string& linkLang,
  135. std::string& linkFlags);
  136. cmTarget *Target;
  137. cmGeneratorTarget* GeneratorTarget;
  138. cmLocalUnixMakefileGenerator3 *LocalGenerator;
  139. cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
  140. cmMakefile *Makefile;
  141. std::string ConfigName;
  142. enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
  143. CustomCommandDriveType CustomCommandDriver;
  144. // the full path to the build file
  145. std::string BuildFileName;
  146. std::string BuildFileNameFull;
  147. // the full path to the progress file
  148. std::string ProgressFileNameFull;
  149. unsigned long NumberOfProgressActions;
  150. bool NoRuleMessages;
  151. // the path to the directory the build file is in
  152. std::string TargetBuildDirectory;
  153. std::string TargetBuildDirectoryFull;
  154. // the stream for the build file
  155. cmGeneratedFileStream *BuildFileStream;
  156. // the stream for the flag file
  157. std::string FlagFileNameFull;
  158. cmGeneratedFileStream *FlagFileStream;
  159. class StringList: public std::vector<std::string> {};
  160. std::map<std::string, StringList> FlagFileDepends;
  161. // the stream for the info file
  162. std::string InfoFileNameFull;
  163. cmGeneratedFileStream *InfoFileStream;
  164. // files to clean
  165. std::vector<std::string> CleanFiles;
  166. // objects used by this target
  167. std::vector<std::string> Objects;
  168. std::vector<std::string> ExternalObjects;
  169. // Set of object file names that will be built in this directory.
  170. std::set<std::string> ObjectFiles;
  171. // Set of extra output files to be driven by the build.
  172. std::set<std::string> ExtraFiles;
  173. typedef std::map<std::string, std::string> MultipleOutputPairsType;
  174. MultipleOutputPairsType MultipleOutputPairs;
  175. bool WriteMakeRule(std::ostream& os,
  176. const char* comment,
  177. const std::vector<std::string>& outputs,
  178. const std::vector<std::string>& depends,
  179. const std::vector<std::string>& commands,
  180. bool in_help = false);
  181. // Target name info.
  182. std::string TargetNameOut;
  183. std::string TargetNameSO;
  184. std::string TargetNameReal;
  185. std::string TargetNameImport;
  186. std::string TargetNamePDB;
  187. // Mac OS X content info.
  188. std::set<std::string> MacContentFolders;
  189. cmOSXBundleGenerator* OSXBundleGenerator;
  190. MacOSXContentGeneratorType* MacOSXContentGenerator;
  191. typedef std::map<std::string, std::string> ByLanguageMap;
  192. std::string GetFlags(const std::string &l);
  193. ByLanguageMap FlagsByLanguage;
  194. std::string GetDefines(const std::string &l);
  195. ByLanguageMap DefinesByLanguage;
  196. // Target-wide Fortran module output directory.
  197. bool FortranModuleDirectoryComputed;
  198. std::string FortranModuleDirectory;
  199. const char* GetFortranModuleDirectory();
  200. // Compute target-specific Fortran language flags.
  201. void AddFortranFlags(std::string& flags);
  202. // Helper to add flag for windows .def file.
  203. void AddModuleDefinitionFlag(std::string& flags);
  204. // Add language feature flags.
  205. void AddFeatureFlags(std::string& flags, const std::string& lang);
  206. // Feature query methods.
  207. const char* GetFeature(const std::string& feature);
  208. bool GetFeatureAsBool(const std::string& feature);
  209. //==================================================================
  210. // Convenience routines that do nothing more than forward to
  211. // implementaitons
  212. std::string Convert(const std::string& source,
  213. cmLocalGenerator::RelativeRoot relative,
  214. cmLocalGenerator::OutputFormat output =
  215. cmLocalGenerator::UNCHANGED)
  216. {
  217. return this->LocalGenerator->Convert(source, relative, output);
  218. }
  219. };
  220. #endif