cmLocalNinjaGenerator.h 4.3 KB
Newer Older
1
2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3
#pragma once
4

5
#include "cmConfigure.h" // IWYU pragma: keep
Brad King's avatar
Brad King committed
6

7
8
9
10
11
#include <iosfwd>
#include <map>
#include <set>
#include <string>
#include <vector>
12

13
14
15
16
#include "cmLocalCommonGenerator.h"
#include "cmNinjaTypes.h"
#include "cmOutputConverter.h"

17
class cmCustomCommand;
18
class cmCustomCommandGenerator;
19
class cmGeneratedFileStream;
20
21
22
23
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmGlobalNinjaGenerator;
class cmMakefile;
24
class cmRulePlaceholderExpander;
25
26
27
28
29
30
31
32
33
class cmake;

/**
 * \class cmLocalNinjaGenerator
 * \brief Write a local build.ninja file.
 *
 * cmLocalNinjaGenerator produces a local build.ninja file from its
 * member Makefile.
 */
34
class cmLocalNinjaGenerator : public cmLocalCommonGenerator
35
36
{
public:
37
  cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
38

39
  ~cmLocalNinjaGenerator() override;
40

41
  void Generate() override;
42

43
  cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const override;
44

45
46
  std::string GetTargetDirectory(
    cmGeneratorTarget const* target) const override;
47
48
49
50
51
52
53
54
55
56

  const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
  cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();

  const cmake* GetCMakeInstance() const;
  cmake* GetCMakeInstance();

  /// @returns the relative path between the HomeOutputDirectory and this
  /// local generators StartOutputDirectory.
  std::string GetHomeRelativeOutputPath() const
57
58
59
  {
    return this->HomeRelativeOutputPath;
  }
60

61
62
63
64
  std::string BuildCommandLine(
    std::vector<std::string> const& cmdLines,
    std::string const& customStep = std::string(),
    cmGeneratorTarget const* target = nullptr) const;
65

66
67
  void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs,
                           const std::string& config);
68
69
70
71
  void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs,
                           const std::string& config,
                           const std::string& fileConfig,
                           cmNinjaTargetDepends depends);
72

73
74
75
  std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
    cmCustomCommand const& cc, std::string const& config) override;

76
77
  void AddCustomCommandTarget(cmCustomCommand const* cc,
                              cmGeneratorTarget* target);
78
  void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
79
                                std::vector<std::string>& cmdLines);
80
  void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
81
82
                               cmNinjaDeps& ninjaDeps,
                               const std::string& config);
83
84

protected:
85
  std::string ConvertToIncludeReference(
86
87
    std::string const& path,
    cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
88
    bool forceFullPaths = false) override;
89
90

private:
91
  cmGeneratedFileStream& GetImplFileStream(const std::string& config) const;
Kyle Edwards's avatar
Kyle Edwards committed
92
  cmGeneratedFileStream& GetCommonFileStream() const;
93
94
95
96
  cmGeneratedFileStream& GetRulesFileStream() const;

  void WriteBuildFileTop();
  void WriteProjectHeader(std::ostream& os);
97
  void WriteNinjaRequiredVersion(std::ostream& os);
Kyle Edwards's avatar
Kyle Edwards committed
98
99
100
101
  void WriteNinjaConfigurationVariable(std::ostream& os,
                                       const std::string& config);
  void WriteNinjaFilesInclusionConfig(std::ostream& os);
  void WriteNinjaFilesInclusionCommon(std::ostream& os);
102
  void WriteProcessedMakefile(std::ostream& os);
103
  void WritePools(std::ostream& os);
104

105
  void WriteCustomCommandBuildStatement(cmCustomCommand const* cc,
106
107
                                        const cmNinjaDeps& orderOnlyDeps,
                                        const std::string& config);
108

109
  void WriteCustomCommandBuildStatements(const std::string& config);
110

111
  std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
112

113
114
115
116
  std::string WriteCommandScript(std::vector<std::string> const& cmdLines,
                                 std::string const& customStep,
                                 cmGeneratorTarget const* target) const;

117
  void AdditionalCleanFiles(const std::string& config);
118

119
120
  std::string HomeRelativeOutputPath;

121
122
  using CustomCommandTargetMap =
    std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*>>;
123
  CustomCommandTargetMap CustomCommandTargets;
124
  std::vector<cmCustomCommand const*> CustomCommands;
125
};