cmNinjaTargetGenerator.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. void ExportObjectCompileCommand(
  85. std::string const& language,
  86. std::string const& sourceFileName,
  87. std::string const& objectDir,
  88. std::string const& objectFileName,
  89. std::string const& objectFileDir,
  90. std::string const& flags,
  91. std::string const& defines,
  92. std::string const& includes
  93. );
  94. cmNinjaDeps GetObjects() const
  95. { 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. void operator()(cmSourceFile const& source, const char* pkgloc);
  105. private:
  106. cmNinjaTargetGenerator* Generator;
  107. };
  108. friend struct MacOSXContentGeneratorType;
  109. MacOSXContentGeneratorType* MacOSXContentGenerator;
  110. // Properly initialized by sub-classes.
  111. cmOSXBundleGenerator* OSXBundleGenerator;
  112. std::set<std::string> MacContentFolders;
  113. void addPoolNinjaVariable(const std::string& pool_property,
  114. cmTarget* target,
  115. cmNinjaVars& vars);
  116. private:
  117. cmLocalNinjaGenerator* LocalGenerator;
  118. /// List of object files for this target.
  119. cmNinjaDeps Objects;
  120. std::vector<cmCustomCommand const*> CustomCommands;
  121. };
  122. #endif // ! cmNinjaTargetGenerator_h