cmNinjaTargetGenerator.h 5.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
  Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#ifndef cmNinjaTargetGenerator_h
#define cmNinjaTargetGenerator_h

#include "cmStandardIncludes.h"
#include "cmNinjaTypes.h"
#include "cmLocalNinjaGenerator.h"
19
#include "cmOSXBundleGenerator.h"
20
21
22
23

class cmTarget;
class cmGlobalNinjaGenerator;
class cmGeneratedFileStream;
24
class cmGeneratorTarget;
25
26
27
28
29
30
31
32
class cmMakefile;
class cmSourceFile;
class cmCustomCommand;

class cmNinjaTargetGenerator
{
public:
  /// Create a cmNinjaTargetGenerator according to the @a target's type.
33
  static cmNinjaTargetGenerator* New(cmGeneratorTarget* target);
34
35

  /// Build a NinjaTargetGenerator.
36
  cmNinjaTargetGenerator(cmGeneratorTarget* target);
37
38
39
40
41
42
43
44

  /// Destructor.
  virtual ~cmNinjaTargetGenerator();

  virtual void Generate() = 0;

  std::string GetTargetName() const;

45
  bool NeedDepTypeMSVC(const std::string& lang) const;
46

47
protected:
48
49
50

  bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;

51
52
53
54
55
56
  cmGeneratedFileStream& GetBuildFileStream() const;
  cmGeneratedFileStream& GetRulesFileStream() const;

  cmTarget* GetTarget() const
  { return this->Target; }

57
58
59
  cmGeneratorTarget* GetGeneratorTarget() const
  { return this->GeneratorTarget; }

60
61
62
63
64
65
66
67
  cmLocalNinjaGenerator* GetLocalGenerator() const
  { return this->LocalGenerator; }

  cmGlobalNinjaGenerator* GetGlobalGenerator() const;

  cmMakefile* GetMakefile() const
  { return this->Makefile; }

68
  std::string const& GetConfigName() const;
69

70
  std::string LanguageCompilerRule(const std::string& lang) const;
71

72
73
  const char* GetFeature(const std::string& feature);
  bool GetFeatureAsBool(const std::string& feature);
74
  void AddFeatureFlags(std::string& flags, const std::string& lang);
75

76
77
78
79
  std::string OrderDependsTargetForTarget();

  std::string ComputeOrderDependsForTarget();

80
81
82
83
84
  /**
   * Compute the flags for compilation of object files for a given @a language.
   * @note Generally it is the value of the variable whose name is computed
   *       by LanguageFlagsVarName().
   */
85
  std::string ComputeFlagsForObject(cmSourceFile const* source,
86
87
                                    const std::string& language);

88
  std::string ComputeDefines(cmSourceFile const* source,
89
90
                             const std::string& language);

Ben Boeckel's avatar
Ben Boeckel committed
91
  std::string ConvertToNinjaPath(const std::string& path) const {
92
93
    return this->GetLocalGenerator()->ConvertToNinjaPath(path);
  }
94
95
96
97
98
99
100
101
  cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
    return this->GetLocalGenerator()->MapToNinjaPath();
  }

  /// @return the list of link dependency for the given target @a target.
  cmNinjaDeps ComputeLinkDeps() const;

  /// @return the source file path for the given @a source.
102
  std::string GetSourceFilePath(cmSourceFile const* source) const;
103
104

  /// @return the object file path for the given @a source.
105
  std::string GetObjectFilePath(cmSourceFile const* source) const;
106
107
108
109
110
111
112
113
114
115

  /// @return the file path where the target named @a name is generated.
  std::string GetTargetFilePath(const std::string& name) const;

  /// @return the output path for the target.
  virtual std::string GetTargetOutputDir() const;

  void WriteLanguageRules(const std::string& language);
  void WriteCompileRule(const std::string& language);
  void WriteObjectBuildStatements();
116
117
  void WriteObjectBuildStatement(cmSourceFile const* source,
                                 bool writeOrderDependsTargetForTarget);
118
119
120
121

  cmNinjaDeps GetObjects() const
  { return this->Objects; }

Peter Kuemmel's avatar
Peter Kuemmel committed
122
123
124
  // Helper to add flag for windows .def file.
  void AddModuleDefinitionFlag(std::string& flags);

125
126
  void EnsureDirectoryExists(const std::string& dir) const;
  void EnsureParentDirectoryExists(const std::string& path) const;
127

128
  // write rules for Mac OS X Application Bundle content.
Peter Kümmel's avatar
Peter Kümmel committed
129
130
  struct MacOSXContentGeneratorType :
    cmOSXBundleGenerator::MacOSXContentGeneratorType
131
  {
Peter Kümmel's avatar
Peter Kümmel committed
132
133
134
    MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
      Generator(g)  {}

135
    void operator()(cmSourceFile const& source, const char* pkgloc);
136
137
138
139

  private:
    cmNinjaTargetGenerator* Generator;
  };
Peter Kümmel's avatar
Peter Kümmel committed
140
  friend struct MacOSXContentGeneratorType;
141

142

Peter Kümmel's avatar
Peter Kümmel committed
143
  MacOSXContentGeneratorType* MacOSXContentGenerator;
144
145
  // Properly initialized by sub-classes.
  cmOSXBundleGenerator* OSXBundleGenerator;
146
  std::set<std::string> MacContentFolders;
147

Ben Boeckel's avatar
Ben Boeckel committed
148
  void addPoolNinjaVariable(const std::string& pool_property,
149
150
                            cmTarget* target,
                            cmNinjaVars& vars);
151

152
153
private:
  cmTarget* Target;
154
  cmGeneratorTarget* GeneratorTarget;
155
156
157
158
  cmMakefile* Makefile;
  cmLocalNinjaGenerator* LocalGenerator;
  /// List of object files for this target.
  cmNinjaDeps Objects;
159
  std::vector<cmCustomCommand const*> CustomCommands;
160

Ben Boeckel's avatar
Ben Boeckel committed
161
162
163
  typedef std::map<std::string, std::string> LanguageFlagMap;
  LanguageFlagMap LanguageFlags;

164
165
  // The windows module definition source file (.def), if any.
  std::string ModuleDefinitionFile;
166
167
168
};

#endif // ! cmNinjaTargetGenerator_h