cmMakefileTargetGenerator.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. virtual void CloseFileStreams();
  117. void RemoveForbiddenFlags(const char* flagVar, const char* linkLang,
  118. std::string& linkFlags);
  119. cmTarget *Target;
  120. cmLocalUnixMakefileGenerator3 *LocalGenerator;
  121. cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
  122. cmMakefile *Makefile;
  123. const char *ConfigName;
  124. enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
  125. CustomCommandDriveType CustomCommandDriver;
  126. // the full path to the build file
  127. std::string BuildFileName;
  128. std::string BuildFileNameFull;
  129. // the full path to the progress file
  130. std::string ProgressFileNameFull;
  131. unsigned long NumberOfProgressActions;
  132. bool NoRuleMessages;
  133. // the path to the directory the build file is in
  134. std::string TargetBuildDirectory;
  135. std::string TargetBuildDirectoryFull;
  136. // the stream for the build file
  137. cmGeneratedFileStream *BuildFileStream;
  138. // the stream for the flag file
  139. std::string FlagFileNameFull;
  140. cmGeneratedFileStream *FlagFileStream;
  141. // the stream for the info file
  142. std::string InfoFileNameFull;
  143. cmGeneratedFileStream *InfoFileStream;
  144. // files to clean
  145. std::vector<std::string> CleanFiles;
  146. // objects used by this target
  147. std::vector<std::string> Objects;
  148. std::vector<std::string> ExternalObjects;
  149. // The windows module definition source file (.def), if any.
  150. std::string ModuleDefinitionFile;
  151. // Set of object file names that will be built in this directory.
  152. std::set<cmStdString> ObjectFiles;
  153. // Set of extra output files to be driven by the build.
  154. std::set<cmStdString> ExtraFiles;
  155. typedef std::map<cmStdString, cmStdString> MultipleOutputPairsType;
  156. MultipleOutputPairsType MultipleOutputPairs;
  157. // Target name info.
  158. std::string TargetNameOut;
  159. std::string TargetNameSO;
  160. std::string TargetNameReal;
  161. std::string TargetNameImport;
  162. std::string TargetNamePDB;
  163. // Mac OS X content info.
  164. std::string MacContentDirectory;
  165. std::set<cmStdString> MacContentFolders;
  166. // Target-wide Fortran module output directory.
  167. bool FortranModuleDirectoryComputed;
  168. std::string FortranModuleDirectory;
  169. const char* GetFortranModuleDirectory();
  170. // Compute target-specific Fortran language flags.
  171. void AddFortranFlags(std::string& flags);
  172. // Helper to add flag for windows .def file.
  173. void AddModuleDefinitionFlag(std::string& flags);
  174. // Add language feature flags.
  175. void AddFeatureFlags(std::string& flags, const char* lang);
  176. // Feature query methods.
  177. const char* GetFeature(const char* feature);
  178. bool GetFeatureAsBool(const char* feature);
  179. //==================================================================
  180. // Convenience routines that do nothing more than forward to
  181. // implementaitons
  182. std::string Convert(const char* source,
  183. cmLocalGenerator::RelativeRoot relative,
  184. cmLocalGenerator::OutputFormat output =
  185. cmLocalGenerator::UNCHANGED,
  186. bool optional = false)
  187. {
  188. return this->LocalGenerator->Convert(source, relative, output, optional);
  189. }
  190. };
  191. #endif