cmNinjaTargetGenerator.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. const char* GetConfigName() const;
  50. std::string LanguageCompilerRule(const std::string& lang) const
  51. { return lang + "_COMPILER"; }
  52. const char* GetFeature(const char* feature);
  53. bool GetFeatureAsBool(const char* feature);
  54. void AddFeatureFlags(std::string& flags, const char* lang);
  55. /**
  56. * Compute the flags for compilation of object files for a given @a language.
  57. * @note Generally it is the value of the variable whose name is computed
  58. * by LanguageFlagsVarName().
  59. */
  60. std::string ComputeFlagsForObject(cmSourceFile *source,
  61. const std::string& language);
  62. std::string ComputeDefines(cmSourceFile *source,
  63. const std::string& language);
  64. std::string ConvertToNinjaPath(const char *path) const {
  65. return this->GetLocalGenerator()->ConvertToNinjaPath(path);
  66. }
  67. cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
  68. return this->GetLocalGenerator()->MapToNinjaPath();
  69. }
  70. /// @return the list of link dependency for the given target @a target.
  71. cmNinjaDeps ComputeLinkDeps() const;
  72. /// @return the source file path for the given @a source.
  73. std::string GetSourceFilePath(cmSourceFile* source) const;
  74. /// @return the object file path for the given @a source.
  75. std::string GetObjectFilePath(cmSourceFile* source) const;
  76. /// @return the file path where the target named @a name is generated.
  77. std::string GetTargetFilePath(const std::string& name) const;
  78. /// @return the output path for the target.
  79. virtual std::string GetTargetOutputDir() const;
  80. void WriteLanguageRules(const std::string& language);
  81. void WriteCompileRule(const std::string& language);
  82. void WriteObjectBuildStatements();
  83. void WriteObjectBuildStatement(cmSourceFile* source);
  84. void WriteCustomCommandBuildStatement(cmCustomCommand *cc);
  85. cmNinjaDeps GetObjects() const
  86. { return this->Objects; }
  87. // Helper to add flag for windows .def file.
  88. void AddModuleDefinitionFlag(std::string& flags);
  89. void EnsureDirectoryExists(const std::string& dir) const;
  90. void EnsureParentDirectoryExists(const std::string& path) const;
  91. // write rules for Mac OS X Application Bundle content.
  92. struct MacOSXContentGeneratorType :
  93. cmOSXBundleGenerator::MacOSXContentGeneratorType
  94. {
  95. MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
  96. Generator(g) {}
  97. void operator()(cmSourceFile& source, const char* pkgloc);
  98. private:
  99. cmNinjaTargetGenerator* Generator;
  100. };
  101. friend struct MacOSXContentGeneratorType;
  102. MacOSXContentGeneratorType* MacOSXContentGenerator;
  103. // Properly initialized by sub-classes.
  104. cmOSXBundleGenerator* OSXBundleGenerator;
  105. std::set<cmStdString> MacContentFolders;
  106. void addPoolNinjaVariable(const char* pool_property,
  107. cmTarget* target,
  108. cmNinjaVars& vars);
  109. private:
  110. cmTarget* Target;
  111. cmGeneratorTarget* GeneratorTarget;
  112. cmMakefile* Makefile;
  113. cmLocalNinjaGenerator* LocalGenerator;
  114. /// List of object files for this target.
  115. cmNinjaDeps Objects;
  116. // The windows module definition source file (.def), if any.
  117. std::string ModuleDefinitionFile;
  118. };
  119. #endif // ! cmNinjaTargetGenerator_h