cmNinjaTargetGenerator.h 4.8 KB

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