/src/CMake/Source/cmLocalNinjaGenerator.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <iosfwd> |
8 | | #include <map> |
9 | | #include <set> |
10 | | #include <string> |
11 | | #include <vector> |
12 | | |
13 | | #include "cmGeneratorOptions.h" |
14 | | #include "cmLocalCommonGenerator.h" |
15 | | #include "cmNinjaTypes.h" |
16 | | #include "cmOutputConverter.h" |
17 | | #include "cmStateTypes.h" |
18 | | |
19 | | class cmCustomCommand; |
20 | | class cmCustomCommandGenerator; |
21 | | class cmGeneratedFileStream; |
22 | | class cmGeneratorTarget; |
23 | | class cmGlobalGenerator; |
24 | | class cmGlobalNinjaGenerator; |
25 | | class cmListFileBacktrace; |
26 | | class cmMakefile; |
27 | | class cmake; |
28 | | |
29 | | /** |
30 | | * \class cmLocalNinjaGenerator |
31 | | * \brief Write a local build.ninja file. |
32 | | * |
33 | | * cmLocalNinjaGenerator produces a local build.ninja file from its |
34 | | * member Makefile. |
35 | | */ |
36 | | class cmLocalNinjaGenerator : public cmLocalCommonGenerator |
37 | | { |
38 | | public: |
39 | | cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf); |
40 | | |
41 | | ~cmLocalNinjaGenerator() override; |
42 | | |
43 | | void Generate() override; |
44 | | |
45 | | std::unique_ptr<cmRulePlaceholderExpander> CreateRulePlaceholderExpander( |
46 | | cmBuildStep buildStep = cmBuildStep::Compile) const override; |
47 | | |
48 | | cmGlobalNinjaGenerator const* GetGlobalNinjaGenerator() const; |
49 | | cmGlobalNinjaGenerator* GetGlobalNinjaGenerator(); |
50 | | |
51 | | cmake const* GetCMakeInstance() const; |
52 | | cmake* GetCMakeInstance(); |
53 | | |
54 | | std::string const& GetWorkingDirectory() const override; |
55 | | |
56 | | std::string MaybeRelativeToWorkDir(std::string const& path) const override; |
57 | | |
58 | | /// @returns the relative path between the HomeOutputDirectory and this |
59 | | /// local generators StartOutputDirectory. |
60 | | std::string GetHomeRelativeOutputPath() const |
61 | 0 | { |
62 | 0 | return this->HomeRelativeOutputPath; |
63 | 0 | } |
64 | | std::string GetObjectOutputRoot( |
65 | | cmStateEnums::IntermediateDirKind kind = |
66 | | cmStateEnums::IntermediateDirKind::ObjectFiles) const override; |
67 | | |
68 | | std::string BuildCommandLine( |
69 | | std::vector<std::string> const& cmdLines, std::string const& outputConfig, |
70 | | std::string const& commandConfig, |
71 | | std::string const& customStep = std::string(), |
72 | | cmGeneratorTarget const* target = nullptr) const; |
73 | | |
74 | | void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs, |
75 | | std::string const& config); |
76 | | void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs, |
77 | | std::string const& config, |
78 | | std::string const& fileConfig, |
79 | | cmNinjaTargetDepends depends); |
80 | | |
81 | | std::string CreateUtilityOutput(std::string const& targetName, |
82 | | std::vector<std::string> const& byproducts, |
83 | | cmListFileBacktrace const& bt) override; |
84 | | |
85 | | std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators( |
86 | | cmCustomCommand const& cc, std::string const& config) override; |
87 | | |
88 | | void AddCustomCommandTarget(cmCustomCommand const* cc, |
89 | | cmGeneratorTarget* target); |
90 | | void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg, |
91 | | std::vector<std::string>& cmdLines); |
92 | | void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg, |
93 | | cmNinjaDeps& ninjaDeps, |
94 | | std::string const& config); |
95 | | |
96 | | bool HasUniqueByproducts(std::vector<std::string> const& byproducts, |
97 | | cmListFileBacktrace const& bt); |
98 | | |
99 | | std::string GetLinkDependencyFile(cmGeneratorTarget* target, |
100 | | std::string const& config) const override; |
101 | | |
102 | | protected: |
103 | | std::string ConvertToIncludeReference( |
104 | | std::string const& path, cmOutputConverter::OutputFormat format) override; |
105 | | |
106 | | private: |
107 | | cmGeneratedFileStream& GetImplFileStream(std::string const& config) const; |
108 | | cmGeneratedFileStream& GetCommonFileStream() const; |
109 | | cmGeneratedFileStream& GetRulesFileStream() const; |
110 | | |
111 | | void WriteBuildFileTop(); |
112 | | void WriteProjectHeader(std::ostream& os); |
113 | | void WriteNinjaRequiredVersion(std::ostream& os); |
114 | | void WriteNinjaConfigurationVariable(std::ostream& os, |
115 | | std::string const& config); |
116 | | void WriteNinjaFilesInclusionConfig(std::ostream& os); |
117 | | void WriteNinjaFilesInclusionCommon(std::ostream& os); |
118 | | void WriteNinjaWorkDir(std::ostream& os); |
119 | | void WriteProcessedMakefile(std::ostream& os); |
120 | | void WritePools(std::ostream& os); |
121 | | |
122 | | void WriteCustomCommandBuildStatement( |
123 | | cmCustomCommand const* cc, std::set<cmGeneratorTarget*> const& targets, |
124 | | std::string const& config); |
125 | | |
126 | | void WriteCustomCommandBuildStatements(std::string const& config); |
127 | | |
128 | | std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg); |
129 | | |
130 | | std::string WriteCommandScript(std::vector<std::string> const& cmdLines, |
131 | | std::string const& outputConfig, |
132 | | std::string const& commandConfig, |
133 | | std::string const& customStep, |
134 | | cmGeneratorTarget const* target) const; |
135 | | |
136 | | void AdditionalCleanFiles(std::string const& config); |
137 | | |
138 | | std::string HomeRelativeOutputPath; |
139 | | |
140 | | using CustomCommandTargetMap = |
141 | | std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*>>; |
142 | | CustomCommandTargetMap CustomCommandTargets; |
143 | | std::vector<cmCustomCommand const*> CustomCommands; |
144 | | }; |