CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmMakefileTargetGenerator.h
blob08d6945afb05ec8d6e8f3ce9b24b216321e45ba0
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <iosfwd>
8 #include <map>
9 #include <memory>
10 #include <set>
11 #include <string>
12 #include <vector>
14 #include "cmCommonTargetGenerator.h"
15 #include "cmGeneratorTarget.h"
16 #include "cmLocalUnixMakefileGenerator3.h"
17 #include "cmOSXBundleGenerator.h"
19 class cmCustomCommandGenerator;
20 class cmGeneratedFileStream;
21 class cmGlobalUnixMakefileGenerator3;
22 class cmLinkLineComputer;
23 class cmOutputConverter;
24 class cmSourceFile;
25 class cmStateDirectory;
27 /** \class cmMakefileTargetGenerator
28 * \brief Support Routines for writing makefiles
31 class cmMakefileTargetGenerator : public cmCommonTargetGenerator
33 public:
34 // constructor to set the ivars
35 cmMakefileTargetGenerator(cmGeneratorTarget* target);
36 cmMakefileTargetGenerator(const cmMakefileTargetGenerator&) = delete;
37 ~cmMakefileTargetGenerator() override;
39 cmMakefileTargetGenerator& operator=(const cmMakefileTargetGenerator&) =
40 delete;
42 // construct using this factory call
43 static std::unique_ptr<cmMakefileTargetGenerator> New(
44 cmGeneratorTarget* tgt);
46 /* the main entry point for this class. Writes the Makefiles associated
47 with this target */
48 virtual void WriteRuleFiles() = 0;
50 /* return the number of actions that have progress reporting on them */
51 virtual unsigned long GetNumberOfProgressActions()
53 return this->NumberOfProgressActions;
55 std::string GetProgressFileNameFull() { return this->ProgressFileNameFull; }
57 cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; }
59 std::string GetConfigName() const;
61 protected:
62 void GetDeviceLinkFlags(std::string& linkFlags,
63 const std::string& linkLanguage);
64 void GetTargetLinkFlags(std::string& flags, const std::string& linkLanguage);
66 // create the file and directory etc
67 void CreateRuleFile();
69 // outputs the rules for object files and custom commands used by
70 // this target
71 void WriteTargetBuildRules();
73 // write some common code at the top of build.make
74 void WriteCommonCodeRules();
75 void WriteTargetLanguageFlags();
77 // write the clean rules for this target
78 void WriteTargetCleanRules();
80 // write the linker depend rules for this target
81 void WriteTargetLinkDependRules();
82 // write the depend rules for this target
83 void WriteTargetDependRules();
85 std::string GetClangTidyReplacementsFilePath(
86 std::string const& directory, cmSourceFile const& source,
87 std::string const& config) const override;
89 // write rules for macOS Application Bundle content.
90 struct MacOSXContentGeneratorType
91 : cmOSXBundleGenerator::MacOSXContentGeneratorType
93 MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen)
94 : Generator(gen)
98 void operator()(cmSourceFile const& source, const char* pkgloc,
99 const std::string& config) override;
101 private:
102 cmMakefileTargetGenerator* Generator;
104 friend struct MacOSXContentGeneratorType;
106 // write the rules for an object
107 void WriteObjectRuleFiles(cmSourceFile const& source);
109 // write the depend.make file for an object
110 void WriteObjectDependRules(cmSourceFile const& source,
111 std::vector<std::string>& depends);
113 // CUDA device linking.
114 void WriteDeviceLinkRule(std::vector<std::string>& commands,
115 const std::string& output);
117 // write the build rule for a custom command
118 void GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg);
120 // write a rule to drive building of more than one output from
121 // another rule
122 void GenerateExtraOutput(const char* out, const char* in,
123 bool symbolic = false);
125 void MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress&) const;
127 // write out the variable that lists the objects for this target
128 void WriteObjectsVariable(std::string& variableName,
129 std::string& variableNameExternal,
130 bool useWatcomQuote);
131 void WriteObjectsStrings(std::vector<std::string>& objStrings,
132 bool useWatcomQuote,
133 std::string::size_type limit = std::string::npos);
135 // write the driver rule to build target outputs
136 void WriteTargetDriverRule(const std::string& main_output, bool relink);
138 void DriveCustomCommands(std::vector<std::string>& depends);
140 // append intertarget dependencies
141 void AppendTargetDepends(std::vector<std::string>& depends,
142 bool ignoreType = false);
144 // Append object file dependencies.
145 void AppendObjectDepends(std::vector<std::string>& depends);
147 // Append link rule dependencies (objects, etc.).
148 void AppendLinkDepends(std::vector<std::string>& depends,
149 const std::string& linkLanguage);
151 // Lookup the link rule for this target.
152 std::string GetLinkRule(const std::string& linkRuleVar);
154 /** Create a script to hold link rules and a command to invoke the
155 script at build time. */
156 void CreateLinkScript(const char* name,
157 std::vector<std::string> const& link_commands,
158 std::vector<std::string>& makefile_commands,
159 std::vector<std::string>& makefile_depends);
161 std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer(
162 cmOutputConverter* outputConverter, cmStateDirectory const& stateDir);
164 /** Create a response file with the given set of options. Returns
165 the relative path from the target build working directory to the
166 response file name. */
167 std::string CreateResponseFile(const std::string& name,
168 std::string const& options,
169 std::vector<std::string>& makefile_depends,
170 std::string const& language);
172 bool CheckUseResponseFileForObjects(std::string const& l) const;
173 bool CheckUseResponseFileForLibraries(std::string const& l) const;
175 enum ResponseFlagFor
177 Link,
178 DeviceLink
181 /** Create list of flags for link libraries. */
182 void CreateLinkLibs(cmLinkLineComputer* linkLineComputer,
183 std::string& linkLibs, bool useResponseFile,
184 std::vector<std::string>& makefile_depends,
185 std::string const& linkLanguage,
186 ResponseFlagFor responseMode = ResponseFlagFor::Link);
188 /** Create lists of object files for linking and cleaning. */
189 void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
190 bool useResponseFile, std::string& buildObjs,
191 std::vector<std::string>& makefile_depends,
192 bool useWatcomQuote, std::string const& linkLanguage,
193 ResponseFlagFor responseMode = ResponseFlagFor::Link);
195 /** Add commands for generate def files */
196 void GenDefFile(std::vector<std::string>& real_link_commands);
198 void AddIncludeFlags(std::string& flags, const std::string& lang,
199 const std::string& config) override;
201 /** Return the response flag for the given configuration */
202 std::string GetResponseFlag(ResponseFlagFor mode) const;
204 virtual void CloseFileStreams();
205 cmLocalUnixMakefileGenerator3* LocalGenerator;
206 cmGlobalUnixMakefileGenerator3* GlobalGenerator;
208 enum CustomCommandDriveType
210 OnBuild,
211 OnDepends,
212 OnUtility
214 CustomCommandDriveType CustomCommandDriver;
216 // the full path to the build file
217 std::string BuildFileName;
218 std::string BuildFileNameFull;
220 // the full path to the progress file
221 std::string ProgressFileNameFull;
222 unsigned long NumberOfProgressActions;
223 bool NoRuleMessages;
225 bool CMP0113New = false;
227 // the path to the directory the build file is in
228 std::string TargetBuildDirectory;
229 std::string TargetBuildDirectoryFull;
231 // the stream for the build file
232 std::unique_ptr<cmGeneratedFileStream> BuildFileStream;
234 // the stream for the flag file
235 std::string FlagFileNameFull;
236 std::unique_ptr<cmGeneratedFileStream> FlagFileStream;
237 class StringList : public std::vector<std::string>
240 std::map<std::string, StringList> FlagFileDepends;
242 // the stream for the info file
243 std::string InfoFileNameFull;
244 std::unique_ptr<cmGeneratedFileStream> InfoFileStream;
246 // files to clean
247 std::set<std::string> CleanFiles;
249 // objects used by this target
250 std::vector<std::string> Objects;
251 std::vector<std::string> ExternalObjects;
253 // Set of object file names that will be built in this directory.
254 std::set<std::string> ObjectFiles;
256 // Set of extra output files to be driven by the build.
257 std::set<std::string> ExtraFiles;
259 // Set of custom command output files to be driven by the build.
260 std::set<std::string> CustomCommandOutputs;
262 using MultipleOutputPairsType = std::map<std::string, std::string>;
263 MultipleOutputPairsType MultipleOutputPairs;
264 bool WriteMakeRule(std::ostream& os, const char* comment,
265 const std::vector<std::string>& outputs,
266 const std::vector<std::string>& depends,
267 const std::vector<std::string>& commands,
268 bool in_help = false);
270 // Target name info.
271 cmGeneratorTarget::Names TargetNames;
273 // macOS content info.
274 std::set<std::string> MacContentFolders;
275 std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator;
276 std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;