cmNinjaTargetGenerator.h 5.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*============================================================================
  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

16
17
#include "cmCommonTargetGenerator.h"

18
#include "cmGlobalNinjaGenerator.h"
19
#include "cmLocalNinjaGenerator.h"
20
#include "cmNinjaTypes.h"
21
#include "cmOSXBundleGenerator.h"
22
23
24

class cmTarget;
class cmGeneratedFileStream;
25
class cmGeneratorTarget;
26
27
28
29
class cmMakefile;
class cmSourceFile;
class cmCustomCommand;

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

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

  /// Destructor.
  virtual ~cmNinjaTargetGenerator();

  virtual void Generate() = 0;

  std::string GetTargetName() const;

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

48
protected:
49
50
  bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;

51
52
53
  cmGeneratedFileStream& GetBuildFileStream() const;
  cmGeneratedFileStream& GetRulesFileStream() const;

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

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

  cmGlobalNinjaGenerator* GetGlobalGenerator() const;

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

68
  std::string LanguageCompilerRule(const std::string& lang) const;
69

70
71
72
73
  std::string OrderDependsTargetForTarget();

  std::string ComputeOrderDependsForTarget();

74
75
76
77
78
  /**
   * 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().
   */
79
  std::string ComputeFlagsForObject(cmSourceFile const* source,
80
81
                                    const std::string& language);

82
83
  void AddIncludeFlags(std::string& flags, std::string const& lang);

84
  std::string ComputeDefines(cmSourceFile const* source,
85
86
                             const std::string& language);

87
88
  std::string ConvertToNinjaPath(const std::string& path) const
  {
89
    return this->GetGlobalGenerator()->ConvertToNinjaPath(path);
90
  }
91
92
  cmGlobalNinjaGenerator::MapToNinjaPathImpl MapToNinjaPath() const
  {
93
    return this->GetGlobalGenerator()->MapToNinjaPath();
94
95
96
97
98
99
  }

  /// @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.
100
  std::string GetSourceFilePath(cmSourceFile const* source) const;
101
102

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

  /// @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();
114
115
  void WriteObjectBuildStatement(cmSourceFile const* source,
                                 bool writeOrderDependsTargetForTarget);
116

117
  void ExportObjectCompileCommand(
118
119
120
121
122
123
    std::string const& language, std::string const& sourceFileName,
    std::string const& objectDir, std::string const& objectFileName,
    std::string const& objectFileDir, std::string const& flags,
    std::string const& defines, std::string const& includes);

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

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.
129
130
  struct MacOSXContentGeneratorType
    : cmOSXBundleGenerator::MacOSXContentGeneratorType
131
  {
132
133
134
135
    MacOSXContentGeneratorType(cmNinjaTargetGenerator* g)
      : Generator(g)
    {
    }
Peter Kümmel's avatar
Peter Kümmel committed
136

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

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

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

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

152
153
  bool ForceResponseFile();

154
155
156
157
private:
  cmLocalNinjaGenerator* LocalGenerator;
  /// List of object files for this target.
  cmNinjaDeps Objects;
158
  std::vector<cmCustomCommand const*> CustomCommands;
159
  cmNinjaDeps ExtraFiles;
160
161
162
};

#endif // ! cmNinjaTargetGenerator_h