cmNinjaTargetGenerator.h 5.3 KB

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