cmNinjaTargetGenerator.h 5.3 KB

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