cmNinjaTargetGenerator.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. class cmTarget;
  17. class cmGlobalNinjaGenerator;
  18. class cmGeneratedFileStream;
  19. class cmGeneratorTarget;
  20. class cmMakefile;
  21. class cmSourceFile;
  22. class cmCustomCommand;
  23. class cmNinjaTargetGenerator
  24. {
  25. public:
  26. /// Create a cmNinjaTargetGenerator according to the @a target's type.
  27. static cmNinjaTargetGenerator* New(cmTarget* target);
  28. /// Build a NinjaTargetGenerator.
  29. cmNinjaTargetGenerator(cmTarget* target);
  30. /// Destructor.
  31. virtual ~cmNinjaTargetGenerator();
  32. virtual void Generate() = 0;
  33. std::string GetTargetPDB() const;
  34. std::string GetTargetName() const;
  35. protected:
  36. cmGeneratedFileStream& GetBuildFileStream() const;
  37. cmGeneratedFileStream& GetRulesFileStream() const;
  38. cmTarget* GetTarget() const
  39. { return this->Target; }
  40. cmLocalNinjaGenerator* GetLocalGenerator() const
  41. { return this->LocalGenerator; }
  42. cmGlobalNinjaGenerator* GetGlobalGenerator() const;
  43. cmMakefile* GetMakefile() const
  44. { return this->Makefile; }
  45. const char* GetConfigName() const;
  46. std::string LanguageCompilerRule(const std::string& lang) const
  47. { return lang + "_COMPILER"; }
  48. const char* GetFeature(const char* feature);
  49. bool GetFeatureAsBool(const char* feature);
  50. void AddFeatureFlags(std::string& flags, const char* lang);
  51. /**
  52. * Compute the flags for compilation of object files for a given @a language.
  53. * @note Generally it is the value of the variable whose name is computed
  54. * by LanguageFlagsVarName().
  55. */
  56. std::string ComputeFlagsForObject(cmSourceFile *source,
  57. const std::string& language);
  58. std::string ComputeDefines(cmSourceFile *source,
  59. const std::string& language);
  60. std::string ConvertToNinjaPath(const char *path) const {
  61. return this->GetLocalGenerator()->ConvertToNinjaPath(path);
  62. }
  63. cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
  64. return this->GetLocalGenerator()->MapToNinjaPath();
  65. }
  66. /// @return the list of link dependency for the given target @a target.
  67. cmNinjaDeps ComputeLinkDeps() const;
  68. /// @return the source file path for the given @a source.
  69. std::string GetSourceFilePath(cmSourceFile* source) const;
  70. /// @return the object file path for the given @a source.
  71. std::string GetObjectFilePath(cmSourceFile* source) const;
  72. /// @return the file path where the target named @a name is generated.
  73. std::string GetTargetFilePath(const std::string& name) const;
  74. /// @return the output path for the target.
  75. virtual std::string GetTargetOutputDir() const;
  76. void WriteLanguageRules(const std::string& language);
  77. void WriteCompileRule(const std::string& language);
  78. void WriteObjectBuildStatements();
  79. void WriteObjectBuildStatement(cmSourceFile* source);
  80. void WriteCustomCommandBuildStatement(cmCustomCommand *cc);
  81. cmNinjaDeps GetObjects() const
  82. { return this->Objects; }
  83. // Helper to add flag for windows .def file.
  84. void AddModuleDefinitionFlag(std::string& flags);
  85. void EnsureDirectoryExists(const std::string& dir);
  86. void EnsureParentDirectoryExists(const std::string& path);
  87. private:
  88. cmTarget* Target;
  89. cmGeneratorTarget* GeneratorTarget;
  90. cmMakefile* Makefile;
  91. cmLocalNinjaGenerator* LocalGenerator;
  92. /// List of object files for this target.
  93. cmNinjaDeps Objects;
  94. // The windows module definition source file (.def), if any.
  95. std::string ModuleDefinitionFile;
  96. };
  97. #endif // ! cmNinjaTargetGenerator_h