/src/CMake/Source/cmFastbuildTargetGenerator.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 <memory> |
6 | | #include <set> |
7 | | #include <string> |
8 | | #include <unordered_map> |
9 | | #include <utility> |
10 | | #include <vector> |
11 | | |
12 | | #include "cmsys/FStream.hxx" |
13 | | |
14 | | #include "cmCommonTargetGenerator.h" |
15 | | #include "cmGeneratorTarget.h" |
16 | | #include "cmGlobalFastbuildGenerator.h" |
17 | | #include "cmGlobalGenerator.h" |
18 | | #include "cmOSXBundleGenerator.h" |
19 | | |
20 | | class cmCustomCommand; |
21 | | class cmCustomCommandGenerator; |
22 | | class cmLocalFastbuildGenerator; |
23 | | class cmMakefile; |
24 | | |
25 | | enum class FastbuildBuildStep |
26 | | { |
27 | | PRE_BUILD, |
28 | | PRE_LINK, |
29 | | POST_BUILD, |
30 | | REST, |
31 | | }; |
32 | | |
33 | | class cmFastbuildTargetGenerator : public cmCommonTargetGenerator |
34 | | { |
35 | | public: |
36 | | /// Create a cmFastbuildTargetGenerator according to the @a target's type and |
37 | | /// config. |
38 | | static cmFastbuildTargetGenerator* New(cmGeneratorTarget* target, |
39 | | std::string config); |
40 | | |
41 | | cmFastbuildTargetGenerator(cmGeneratorTarget* target, std::string config); |
42 | | |
43 | 0 | virtual void Generate() {} |
44 | | |
45 | | std::string GetClangTidyReplacementsFilePath( |
46 | | std::string const& directory, cmSourceFile const& source, |
47 | | std::string const& Config) const override; |
48 | | |
49 | | void AddIncludeFlags(std::string& languageFlags, std::string const& language, |
50 | | std::string const&) override; |
51 | | |
52 | | cmGeneratorTarget::Names DetectOutput() const; |
53 | | |
54 | | void AddObjectDependencies(FastbuildTarget& fastbuildTarget, |
55 | | std::vector<std::string>& allObjectDepends) const; |
56 | | void AddLinkerNodeDependencies(FastbuildTarget& fastbuildTarget); |
57 | | |
58 | | std::string ConvertToFastbuildPath(std::string const& path) const; |
59 | | |
60 | | cmGlobalFastbuildGenerator* GetGlobalGenerator() const; |
61 | | |
62 | | std::string GetName(); |
63 | | |
64 | 0 | cmMakefile* GetMakefile() const { return this->Makefile; } |
65 | | |
66 | | cmGeneratorTarget* GetGeneratorTarget() const |
67 | 0 | { |
68 | 0 | return this->GeneratorTarget; |
69 | 0 | } |
70 | | |
71 | | void LogMessage(std::string const& m) const; |
72 | | |
73 | | private: |
74 | | std::string GetUtilityAliasFromBuildStep(FastbuildBuildStep step) const; |
75 | | |
76 | | protected: |
77 | | cmLocalFastbuildGenerator* GetLocalGenerator() const |
78 | 0 | { |
79 | 0 | return this->LocalGenerator; |
80 | 0 | } |
81 | | |
82 | | std::string GetTargetName() const; |
83 | | std::string GetCdCommand(cmCustomCommandGenerator const& ccg) const; |
84 | | std::string GetScriptWorkingDir(cmCustomCommandGenerator const& ccg) const; |
85 | | std::string GetScriptFilename(std::string const& utilityTargetName) const; |
86 | | void GetDepends(cmCustomCommandGenerator const& ccg, |
87 | | std::string const& currentCCName, |
88 | | std::vector<std::string>& fileLevelDeps, |
89 | | std::set<FastbuildTargetDep>& targetDep) const; |
90 | | |
91 | | void AddCommentPrinting(std::vector<std::string>& cmdLines, |
92 | | cmCustomCommandGenerator const& ccg) const; |
93 | | |
94 | | void WriteCmdsToFile(cmsys::ofstream& file, |
95 | | std::vector<std::string> const& cmds) const; |
96 | | |
97 | | void AddOutput(cmCustomCommandGenerator const& ccg, FastbuildExecNode& exec); |
98 | | |
99 | | void AddExecArguments(FastbuildExecNode& exec, |
100 | | std::string const& scriptFilename) const; |
101 | | |
102 | | void ReplaceProblematicMakeVars(std::string& command) const; |
103 | | |
104 | | FastbuildExecNodes GenerateCommands(FastbuildBuildStep buildStep); |
105 | | FastbuildExecNode GetAppleTextStubCommand() const; |
106 | | FastbuildExecNode GetDepsCheckExec(FastbuildExecNode const& depender); |
107 | | |
108 | | std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg); |
109 | | |
110 | | std::string GetCustomCommandTargetName(cmCustomCommand const& cc, |
111 | | FastbuildBuildStep step) const; |
112 | | |
113 | | void WriteScriptProlog(cmsys::ofstream& file) const; |
114 | | void WriteScriptEpilog(cmsys::ofstream& file) const; |
115 | | |
116 | | void AdditionalCleanFiles(); |
117 | | |
118 | | // write rules for Mac OS X Application Bundle content. |
119 | | struct MacOSXContentGeneratorType |
120 | | : cmOSXBundleGenerator::MacOSXContentGeneratorType |
121 | | { |
122 | | MacOSXContentGeneratorType(cmFastbuildTargetGenerator* g, std::string cfg) |
123 | 0 | : Generator(g) |
124 | 0 | , Config(std::move(cfg)) |
125 | 0 | { |
126 | 0 | } |
127 | | |
128 | | void operator()(cmSourceFile const& source, char const* pkgloc, |
129 | | std::string const& config) override; |
130 | | |
131 | | private: |
132 | | cmFastbuildTargetGenerator* Generator; |
133 | | std::string const Config; |
134 | | }; |
135 | | friend struct MacOSXContentGeneratorType; |
136 | | |
137 | | // "MacOSXContentGenerator" has to be per-config once multiconfig generator |
138 | | // is implemented. |
139 | | std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator; |
140 | | std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator; |
141 | | std::set<std::string> MacContentFolders; |
142 | | |
143 | | std::vector<FastbuildCopyNode> CopyNodes; |
144 | | |
145 | | cmLocalFastbuildGenerator* LocalGenerator; |
146 | | cmGlobalGenerator::TargetDependSet const TargetDirectDependencies; |
147 | | std::string const Config; |
148 | | |
149 | | // Sometimes CMake adds equivalent custom commands to different targets. |
150 | | // Not really supported by FBuild (can't have different exec nodes producing |
151 | | // same output). So, in such cases we need to "re-map" the exec to produce a |
152 | | // "dummy" output (and update all deps within the target). |
153 | | // TODO: potentially 1 map should be enough? |
154 | | std::unordered_map<std::string, std::string> OutputsToReplace; |
155 | | std::unordered_map<std::string, std::string> OutputToExecName; |
156 | | }; |