cmNinjaTargetGenerator.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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(cmTarget* 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. protected:
  36. bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
  37. cmGeneratedFileStream& GetBuildFileStream() const;
  38. cmGeneratedFileStream& GetRulesFileStream() const;
  39. cmTarget* GetTarget() const
  40. { return this->Target; }
  41. cmGeneratorTarget* GetGeneratorTarget() const
  42. { return this->GeneratorTarget; }
  43. cmLocalNinjaGenerator* GetLocalGenerator() const
  44. { return this->LocalGenerator; }
  45. cmGlobalNinjaGenerator* GetGlobalGenerator() const;
  46. cmMakefile* GetMakefile() const
  47. { return this->Makefile; }
  48. const char* GetConfigName() const;
  49. std::string LanguageCompilerRule(const std::string& lang) const
  50. { return lang + "_COMPILER"; }
  51. const char* GetFeature(const char* feature);
  52. bool GetFeatureAsBool(const char* feature);
  53. void AddFeatureFlags(std::string& flags, const char* lang);
  54. /**
  55. * Compute the flags for compilation of object files for a given @a language.
  56. * @note Generally it is the value of the variable whose name is computed
  57. * by LanguageFlagsVarName().
  58. */
  59. std::string ComputeFlagsForObject(cmSourceFile *source,
  60. const std::string& language);
  61. std::string ComputeDefines(cmSourceFile *source,
  62. const std::string& language);
  63. std::string ConvertToNinjaPath(const char *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* source) const;
  73. /// @return the object file path for the given @a source.
  74. std::string GetObjectFilePath(cmSourceFile* 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* source);
  83. void WriteCustomCommandBuildStatement(cmCustomCommand *cc);
  84. cmNinjaDeps GetObjects() const
  85. { return this->Objects; }
  86. // Helper to add flag for windows .def file.
  87. void AddModuleDefinitionFlag(std::string& flags);
  88. void EnsureDirectoryExists(const std::string& dir) const;
  89. void EnsureParentDirectoryExists(const std::string& path) const;
  90. // write rules for Mac OS X Application Bundle content.
  91. struct MacOSXContentGeneratorType :
  92. cmOSXBundleGenerator::MacOSXContentGeneratorType
  93. {
  94. MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
  95. Generator(g) {}
  96. void operator()(cmSourceFile& source, const char* pkgloc);
  97. private:
  98. cmNinjaTargetGenerator* Generator;
  99. };
  100. friend struct MacOSXContentGeneratorType;
  101. protected:
  102. MacOSXContentGeneratorType* MacOSXContentGenerator;
  103. // Properly initialized by sub-classes.
  104. cmOSXBundleGenerator* OSXBundleGenerator;
  105. std::set<cmStdString> MacContentFolders;
  106. private:
  107. cmTarget* Target;
  108. cmGeneratorTarget* GeneratorTarget;
  109. cmMakefile* Makefile;
  110. cmLocalNinjaGenerator* LocalGenerator;
  111. /// List of object files for this target.
  112. cmNinjaDeps Objects;
  113. // The windows module definition source file (.def), if any.
  114. std::string ModuleDefinitionFile;
  115. };
  116. #endif // ! cmNinjaTargetGenerator_h