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 "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(cmGeneratorTarget* target);
  31. /// Destructor.
  32. virtual ~cmNinjaTargetGenerator();
  33. virtual void Generate() = 0;
  34. std::string GetTargetName() const;
  35. bool NeedDepTypeMSVC(const std::string& lang) const;
  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. const char* GetFeature(const std::string& feature);
  52. bool GetFeatureAsBool(const std::string& feature);
  53. void AddFeatureFlags(std::string& flags, const std::string& lang);
  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. std::string ComputeDefines(cmSourceFile const* source,
  64. const std::string& language);
  65. std::string ConvertToNinjaPath(const std::string& path) const {
  66. return this->GetLocalGenerator()->ConvertToNinjaPath(path);
  67. }
  68. cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
  69. return this->GetLocalGenerator()->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 file path where the target named @a name is generated.
  78. std::string GetTargetFilePath(const std::string& name) const;
  79. /// @return the output path for the target.
  80. virtual std::string GetTargetOutputDir() const;
  81. void WriteLanguageRules(const std::string& language);
  82. void WriteCompileRule(const std::string& language);
  83. void WriteObjectBuildStatements();
  84. void WriteObjectBuildStatement(cmSourceFile const* source,
  85. bool writeOrderDependsTargetForTarget);
  86. cmNinjaDeps GetObjects() const
  87. { return this->Objects; }
  88. // Helper to add flag for windows .def file.
  89. void AddModuleDefinitionFlag(std::string& flags);
  90. void EnsureDirectoryExists(const std::string& dir) const;
  91. void EnsureParentDirectoryExists(const std::string& path) const;
  92. // write rules for Mac OS X Application Bundle content.
  93. struct MacOSXContentGeneratorType :
  94. cmOSXBundleGenerator::MacOSXContentGeneratorType
  95. {
  96. MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
  97. Generator(g) {}
  98. void operator()(cmSourceFile const& source, const char* pkgloc);
  99. private:
  100. cmNinjaTargetGenerator* Generator;
  101. };
  102. friend struct MacOSXContentGeneratorType;
  103. MacOSXContentGeneratorType* MacOSXContentGenerator;
  104. // Properly initialized by sub-classes.
  105. cmOSXBundleGenerator* OSXBundleGenerator;
  106. std::set<std::string> MacContentFolders;
  107. void addPoolNinjaVariable(const std::string& pool_property,
  108. cmTarget* target,
  109. cmNinjaVars& vars);
  110. private:
  111. cmTarget* Target;
  112. cmGeneratorTarget* GeneratorTarget;
  113. cmMakefile* Makefile;
  114. cmLocalNinjaGenerator* LocalGenerator;
  115. /// List of object files for this target.
  116. cmNinjaDeps Objects;
  117. std::vector<cmCustomCommand const*> CustomCommands;
  118. typedef std::map<std::string, std::string> LanguageFlagMap;
  119. LanguageFlagMap LanguageFlags;
  120. // The windows module definition source file (.def), if any.
  121. std::string ModuleDefinitionFile;
  122. };
  123. #endif // ! cmNinjaTargetGenerator_h