cmMakefileTargetGenerator.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 cmGeneratorTarget;
  17. class cmGeneratedFileStream;
  18. class cmGlobalUnixMakefileGenerator3;
  19. class cmLocalUnixMakefileGenerator3;
  20. class cmMakefile;
  21. class cmTarget;
  22. class cmSourceFile;
  23. /** \class cmMakefileTargetGenerator
  24. * \brief Support Routines for writing makefiles
  25. *
  26. */
  27. class cmMakefileTargetGenerator
  28. {
  29. public:
  30. // constructor to set the ivars
  31. cmMakefileTargetGenerator(cmTarget* target);
  32. virtual ~cmMakefileTargetGenerator() {};
  33. // construct using this factory call
  34. static cmMakefileTargetGenerator *New(cmTarget *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. cmTarget* GetTarget() { return this->Target;}
  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. void WriteMacOSXContentRules(std::vector<cmSourceFile*> const& sources);
  61. void WriteMacOSXContentRules(cmSourceFile& source, const char* pkgloc);
  62. // write the rules for an object
  63. void WriteObjectRuleFiles(cmSourceFile& source);
  64. // write the build rule for an object
  65. void WriteObjectBuildFile(std::string &obj,
  66. const char *lang,
  67. cmSourceFile& source,
  68. std::vector<std::string>& depends);
  69. // write the depend.make file for an object
  70. void WriteObjectDependRules(cmSourceFile& source,
  71. std::vector<std::string>& depends);
  72. // write the build rule for a custom command
  73. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  74. // write a rule to drive building of more than one output from
  75. // another rule
  76. void GenerateExtraOutput(const char* out, const char* in,
  77. bool symbolic = false);
  78. void AppendProgress(std::vector<std::string>& commands);
  79. // write out the variable that lists the objects for this target
  80. void WriteObjectsVariable(std::string& variableName,
  81. std::string& variableNameExternal);
  82. void WriteObjectsString(std::string& buildObjs);
  83. void WriteObjectsStrings(std::vector<std::string>& objStrings,
  84. std::string::size_type limit = std::string::npos);
  85. // write the driver rule to build target outputs
  86. void WriteTargetDriverRule(const char* main_output, bool relink);
  87. void DriveCustomCommands(std::vector<std::string>& depends);
  88. // Return the a string with -F flags on apple
  89. std::string GetFrameworkFlags();
  90. void AppendFortranFormatFlags(std::string& flags, cmSourceFile& source);
  91. // append intertarget dependencies
  92. void AppendTargetDepends(std::vector<std::string>& depends);
  93. // Append object file dependencies.
  94. void AppendObjectDepends(std::vector<std::string>& depends);
  95. // Append link rule dependencies (objects, etc.).
  96. void AppendLinkDepends(std::vector<std::string>& depends);
  97. // Lookup the link rule for this target.
  98. std::string GetLinkRule(const char* linkRuleVar);
  99. /** In order to support parallel builds for custom commands with
  100. multiple outputs the outputs are given a serial order, and only
  101. the first output actually has the build rule. Other outputs
  102. just depend on the first one. The check-build-system step must
  103. remove a dependee if the depender is missing to make sure both
  104. are regenerated properly. This method is used by the local
  105. makefile generators to register such pairs. */
  106. void AddMultipleOutputPair(const char* depender, const char* dependee);
  107. /** Create a script to hold link rules and a command to invoke the
  108. script at build time. */
  109. void CreateLinkScript(const char* name,
  110. std::vector<std::string> const& link_commands,
  111. std::vector<std::string>& makefile_commands,
  112. std::vector<std::string>& makefile_depends);
  113. /** Create a response file with the given set of options. Returns
  114. the relative path from the target build working directory to the
  115. response file name. */
  116. std::string CreateResponseFile(const char* name,
  117. std::string const& options,
  118. std::vector<std::string>& makefile_depends);
  119. /** Create lists of object files for linking and cleaning. */
  120. void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  121. bool useResponseFile, std::string& buildObjs,
  122. std::vector<std::string>& makefile_depends);
  123. void AddIncludeFlags(std::string& flags, const char* lang);
  124. virtual void CloseFileStreams();
  125. void RemoveForbiddenFlags(const char* flagVar, const char* linkLang,
  126. std::string& linkFlags);
  127. cmTarget *Target;
  128. cmGeneratorTarget* GeneratorTarget;
  129. cmLocalUnixMakefileGenerator3 *LocalGenerator;
  130. cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
  131. cmMakefile *Makefile;
  132. const char *ConfigName;
  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<cmStdString, 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<cmStdString> ObjectFiles;
  162. // Set of extra output files to be driven by the build.
  163. std::set<cmStdString> ExtraFiles;
  164. typedef std::map<cmStdString, cmStdString> MultipleOutputPairsType;
  165. MultipleOutputPairsType MultipleOutputPairs;
  166. // Target name info.
  167. std::string TargetNameOut;
  168. std::string TargetNameSO;
  169. std::string TargetNameReal;
  170. std::string TargetNameImport;
  171. std::string TargetNamePDB;
  172. // Mac OS X content info.
  173. std::string MacContentDirectory;
  174. std::set<cmStdString> MacContentFolders;
  175. typedef std::map<cmStdString, cmStdString> ByLanguageMap;
  176. std::string GetFlags(const std::string &l);
  177. ByLanguageMap FlagsByLanguage;
  178. std::string GetDefines(const std::string &l);
  179. ByLanguageMap DefinesByLanguage;
  180. // Target-wide Fortran module output directory.
  181. bool FortranModuleDirectoryComputed;
  182. std::string FortranModuleDirectory;
  183. const char* GetFortranModuleDirectory();
  184. // Compute target-specific Fortran language flags.
  185. void AddFortranFlags(std::string& flags);
  186. // Helper to add flag for windows .def file.
  187. void AddModuleDefinitionFlag(std::string& flags);
  188. // Add language feature flags.
  189. void AddFeatureFlags(std::string& flags, const char* lang);
  190. // Feature query methods.
  191. const char* GetFeature(const char* feature);
  192. bool GetFeatureAsBool(const char* feature);
  193. //==================================================================
  194. // Convenience routines that do nothing more than forward to
  195. // implementaitons
  196. std::string Convert(const char* source,
  197. cmLocalGenerator::RelativeRoot relative,
  198. cmLocalGenerator::OutputFormat output =
  199. cmLocalGenerator::UNCHANGED,
  200. bool optional = false)
  201. {
  202. return this->LocalGenerator->Convert(source, relative, output, optional);
  203. }
  204. };
  205. #endif