Coverage Report

Created: 2026-09-14 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
  std::vector<FastbuildExecNode> GetDepsCheckExecs(
107
    FastbuildExecNode const& depender);
108
109
  std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
110
111
  std::string GetCustomCommandTargetName(cmCustomCommand const& cc,
112
                                         FastbuildBuildStep step) const;
113
114
  void WriteScriptProlog(cmsys::ofstream& file) const;
115
  void WriteScriptEpilog(cmsys::ofstream& file) const;
116
117
  void AdditionalCleanFiles();
118
119
  // write rules for Mac OS X Application Bundle content.
120
  struct MacOSXContentGeneratorType
121
    : cmOSXBundleGenerator::MacOSXContentGeneratorType
122
  {
123
    MacOSXContentGeneratorType(cmFastbuildTargetGenerator* g, std::string cfg)
124
0
      : Generator(g)
125
0
      , Config(std::move(cfg))
126
0
    {
127
0
    }
128
129
    void operator()(cmSourceFile const& source, char const* pkgloc,
130
                    std::string const& config) override;
131
132
  private:
133
    cmFastbuildTargetGenerator* Generator;
134
    std::string const Config;
135
  };
136
  friend struct MacOSXContentGeneratorType;
137
138
  // "MacOSXContentGenerator" has to be per-config once multiconfig generator
139
  // is implemented.
140
  std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
141
  std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator;
142
  std::set<std::string> MacContentFolders;
143
144
  std::vector<FastbuildCopyNode> CopyNodes;
145
146
  cmLocalFastbuildGenerator* LocalGenerator;
147
  cmGlobalGenerator::TargetDependSet const TargetDirectDependencies;
148
  std::string const Config;
149
150
  // Sometimes CMake adds equivalent custom commands to different targets.
151
  // Not really supported by FBuild (can't have different exec nodes producing
152
  // same output). So, in such cases we need to "re-map" the exec to produce a
153
  // "dummy" output (and update all deps within the target).
154
  // TODO: potentially 1 map should be enough?
155
  std::unordered_map<std::string, std::string> OutputsToReplace;
156
  std::unordered_map<std::string, std::string> OutputToExecName;
157
};