cmNinjaTargetGenerator.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmNinjaTargetGenerator_h
  4. #define cmNinjaTargetGenerator_h
  5. #include <cmConfigure.h>
  6. #include "cmCommonTargetGenerator.h"
  7. #include "cmGlobalNinjaGenerator.h"
  8. #include "cmNinjaTypes.h"
  9. #include "cmOSXBundleGenerator.h"
  10. #include <set>
  11. #include <string>
  12. #include <vector>
  13. class cmCustomCommand;
  14. class cmGeneratedFileStream;
  15. class cmGeneratorTarget;
  16. class cmLocalNinjaGenerator;
  17. class cmMakefile;
  18. class cmSourceFile;
  19. class cmNinjaTargetGenerator : public cmCommonTargetGenerator
  20. {
  21. public:
  22. /// Create a cmNinjaTargetGenerator according to the @a target's type.
  23. static cmNinjaTargetGenerator* New(cmGeneratorTarget* target);
  24. /// Build a NinjaTargetGenerator.
  25. cmNinjaTargetGenerator(cmGeneratorTarget* target);
  26. /// Destructor.
  27. ~cmNinjaTargetGenerator() CM_OVERRIDE;
  28. virtual void Generate() = 0;
  29. std::string GetTargetName() const;
  30. bool NeedDepTypeMSVC(const std::string& lang) const;
  31. protected:
  32. bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
  33. cmGeneratedFileStream& GetBuildFileStream() const;
  34. cmGeneratedFileStream& GetRulesFileStream() const;
  35. cmGeneratorTarget* GetGeneratorTarget() const
  36. {
  37. return this->GeneratorTarget;
  38. }
  39. cmLocalNinjaGenerator* GetLocalGenerator() const
  40. {
  41. return this->LocalGenerator;
  42. }
  43. cmGlobalNinjaGenerator* GetGlobalGenerator() const;
  44. cmMakefile* GetMakefile() const { return this->Makefile; }
  45. std::string LanguageCompilerRule(const std::string& lang) const;
  46. std::string LanguagePreprocessRule(std::string const& lang) const;
  47. bool NeedExplicitPreprocessing(std::string const& lang) const;
  48. std::string LanguageDyndepRule(std::string const& lang) const;
  49. bool NeedDyndep(std::string const& lang) const;
  50. std::string OrderDependsTargetForTarget();
  51. std::string ComputeOrderDependsForTarget();
  52. /**
  53. * Compute the flags for compilation of object files for a given @a language.
  54. * @note Generally it is the value of the variable whose name is computed
  55. * by LanguageFlagsVarName().
  56. */
  57. std::string ComputeFlagsForObject(cmSourceFile const* source,
  58. const std::string& language);
  59. void AddIncludeFlags(std::string& flags,
  60. std::string const& lang) CM_OVERRIDE;
  61. std::string ComputeDefines(cmSourceFile const* source,
  62. const std::string& language);
  63. std::string ConvertToNinjaPath(const std::string& path) const
  64. {
  65. return this->GetGlobalGenerator()->ConvertToNinjaPath(path);
  66. }
  67. cmGlobalNinjaGenerator::MapToNinjaPathImpl MapToNinjaPath() const
  68. {
  69. return this->GetGlobalGenerator()->MapToNinjaPath();
  70. }
  71. /// @return the list of link dependency for the given target @a target.
  72. cmNinjaDeps ComputeLinkDeps() const;
  73. /// @return the source file path for the given @a source.
  74. std::string GetSourceFilePath(cmSourceFile const* source) const;
  75. /// @return the object file path for the given @a source.
  76. std::string GetObjectFilePath(cmSourceFile const* source) const;
  77. /// @return the preprocessed source file path for the given @a source.
  78. std::string GetPreprocessedFilePath(cmSourceFile const* source) const;
  79. /// @return the dyndep file path for this target.
  80. std::string GetDyndepFilePath(std::string const& lang) const;
  81. /// @return the target dependency scanner info file path
  82. std::string GetTargetDependInfoPath(std::string const& lang) const;
  83. /// @return the file path where the target named @a name is generated.
  84. std::string GetTargetFilePath(const std::string& name) const;
  85. /// @return the output path for the target.
  86. virtual std::string GetTargetOutputDir() const;
  87. void WriteLanguageRules(const std::string& language);
  88. void WriteCompileRule(const std::string& language);
  89. void WriteObjectBuildStatements();
  90. void WriteObjectBuildStatement(cmSourceFile const* source,
  91. bool writeOrderDependsTargetForTarget);
  92. void WriteTargetDependInfo(std::string const& lang);
  93. void ExportObjectCompileCommand(
  94. std::string const& language, std::string const& sourceFileName,
  95. std::string const& objectDir, std::string const& objectFileName,
  96. std::string const& objectFileDir, std::string const& flags,
  97. std::string const& defines, std::string const& includes);
  98. cmNinjaDeps GetObjects() const { return this->Objects; }
  99. void EnsureDirectoryExists(const std::string& dir) const;
  100. void EnsureParentDirectoryExists(const std::string& path) const;
  101. // write rules for Mac OS X Application Bundle content.
  102. struct MacOSXContentGeneratorType
  103. : cmOSXBundleGenerator::MacOSXContentGeneratorType
  104. {
  105. MacOSXContentGeneratorType(cmNinjaTargetGenerator* g)
  106. : Generator(g)
  107. {
  108. }
  109. void operator()(cmSourceFile const& source,
  110. const char* pkgloc) CM_OVERRIDE;
  111. private:
  112. cmNinjaTargetGenerator* Generator;
  113. };
  114. friend struct MacOSXContentGeneratorType;
  115. MacOSXContentGeneratorType* MacOSXContentGenerator;
  116. // Properly initialized by sub-classes.
  117. cmOSXBundleGenerator* OSXBundleGenerator;
  118. std::set<std::string> MacContentFolders;
  119. void addPoolNinjaVariable(const std::string& pool_property,
  120. cmGeneratorTarget* target, cmNinjaVars& vars);
  121. bool ForceResponseFile();
  122. private:
  123. cmLocalNinjaGenerator* LocalGenerator;
  124. /// List of object files for this target.
  125. cmNinjaDeps Objects;
  126. cmNinjaDeps DDIFiles; // TODO: Make per-language.
  127. std::vector<cmCustomCommand const*> CustomCommands;
  128. cmNinjaDeps ExtraFiles;
  129. };
  130. #endif // ! cmNinjaTargetGenerator_h