cmNinjaTargetGenerator.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "cmCommonTargetGenerator.h"
  14. #include "cmStandardIncludes.h"
  15. #include "cmNinjaTypes.h"
  16. #include "cmLocalNinjaGenerator.h"
  17. #include "cmOSXBundleGenerator.h"
  18. class cmTarget;
  19. class cmGlobalNinjaGenerator;
  20. class cmGeneratedFileStream;
  21. class cmGeneratorTarget;
  22. class cmMakefile;
  23. class cmSourceFile;
  24. class cmCustomCommand;
  25. class cmNinjaTargetGenerator: public cmCommonTargetGenerator
  26. {
  27. public:
  28. /// Create a cmNinjaTargetGenerator according to the @a target's type.
  29. static cmNinjaTargetGenerator* New(cmGeneratorTarget* target);
  30. /// Build a NinjaTargetGenerator.
  31. cmNinjaTargetGenerator(cmGeneratorTarget* target);
  32. /// Destructor.
  33. virtual ~cmNinjaTargetGenerator();
  34. virtual void Generate() = 0;
  35. std::string GetTargetName() const;
  36. bool NeedDepTypeMSVC(const std::string& lang) const;
  37. protected:
  38. bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
  39. cmGeneratedFileStream& GetBuildFileStream() const;
  40. cmGeneratedFileStream& GetRulesFileStream() const;
  41. cmTarget* GetTarget() const
  42. { return this->Target; }
  43. cmGeneratorTarget* GetGeneratorTarget() const
  44. { return this->GeneratorTarget; }
  45. cmLocalNinjaGenerator* GetLocalGenerator() const
  46. { return this->LocalGenerator; }
  47. cmGlobalNinjaGenerator* GetGlobalGenerator() const;
  48. cmMakefile* GetMakefile() const
  49. { return this->Makefile; }
  50. std::string LanguageCompilerRule(const std::string& lang) const;
  51. std::string OrderDependsTargetForTarget();
  52. std::string ComputeOrderDependsForTarget();
  53. /**
  54. * Compute the flags for compilation of object files for a given @a language.
  55. * @note Generally it is the value of the variable whose name is computed
  56. * by LanguageFlagsVarName().
  57. */
  58. std::string ComputeFlagsForObject(cmSourceFile const* source,
  59. const std::string& language);
  60. void AddIncludeFlags(std::string& flags, std::string const& lang);
  61. std::string ComputeDefines(cmSourceFile const* source,
  62. const std::string& language);
  63. std::string ConvertToNinjaPath(const std::string& path) const {
  64. return this->GetLocalGenerator()->ConvertToNinjaPath(path);
  65. }
  66. cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
  67. return this->GetLocalGenerator()->MapToNinjaPath();
  68. }
  69. /// @return the list of link dependency for the given target @a target.
  70. cmNinjaDeps ComputeLinkDeps() const;
  71. /// @return the source file path for the given @a source.
  72. std::string GetSourceFilePath(cmSourceFile const* source) const;
  73. /// @return the object file path for the given @a source.
  74. std::string GetObjectFilePath(cmSourceFile const* source) const;
  75. /// @return the file path where the target named @a name is generated.
  76. std::string GetTargetFilePath(const std::string& name) const;
  77. /// @return the output path for the target.
  78. virtual std::string GetTargetOutputDir() const;
  79. void WriteLanguageRules(const std::string& language);
  80. void WriteCompileRule(const std::string& language);
  81. void WriteObjectBuildStatements();
  82. void WriteObjectBuildStatement(cmSourceFile const* source,
  83. bool writeOrderDependsTargetForTarget);
  84. cmNinjaDeps GetObjects() const
  85. { return this->Objects; }
  86. void EnsureDirectoryExists(const std::string& dir) const;
  87. void EnsureParentDirectoryExists(const std::string& path) const;
  88. // write rules for Mac OS X Application Bundle content.
  89. struct MacOSXContentGeneratorType :
  90. cmOSXBundleGenerator::MacOSXContentGeneratorType
  91. {
  92. MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
  93. Generator(g) {}
  94. void operator()(cmSourceFile const& source, const char* pkgloc);
  95. private:
  96. cmNinjaTargetGenerator* Generator;
  97. };
  98. friend struct MacOSXContentGeneratorType;
  99. MacOSXContentGeneratorType* MacOSXContentGenerator;
  100. // Properly initialized by sub-classes.
  101. cmOSXBundleGenerator* OSXBundleGenerator;
  102. std::set<std::string> MacContentFolders;
  103. void addPoolNinjaVariable(const std::string& pool_property,
  104. cmTarget* target,
  105. cmNinjaVars& vars);
  106. private:
  107. cmLocalNinjaGenerator* LocalGenerator;
  108. /// List of object files for this target.
  109. cmNinjaDeps Objects;
  110. std::vector<cmCustomCommand const*> CustomCommands;
  111. typedef std::map<std::string, std::string> LanguageFlagMap;
  112. LanguageFlagMap LanguageFlags;
  113. };
  114. #endif // ! cmNinjaTargetGenerator_h