cmMakefileTargetGenerator.h 8.9 KB

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