Coverage Report

Created: 2026-06-15 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmExportBuildFileGenerator.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 <functional>
8
#include <string>
9
#include <utility>
10
#include <vector>
11
12
#include <cm/optional>
13
#include <cmext/algorithm>
14
15
#include "cmDiagnostics.h"
16
#include "cmExportFileGenerator.h"
17
#include "cmStateTypes.h"
18
19
class cmExportSet;
20
class cmGeneratorTarget;
21
class cmLocalGenerator;
22
23
/** \class cmExportBuildCMakeConfigGenerator
24
 * \brief Generate a file exporting targets from a build tree.
25
 *
26
 * cmExportBuildCMakeConfigGenerator is the interface class for generating a
27
 * file exporting targets from a build tree.
28
 *
29
 * This is used to implement the export() command.
30
 */
31
class cmExportBuildFileGenerator : virtual public cmExportFileGenerator
32
{
33
public:
34
  struct TargetExport
35
  {
36
    TargetExport(std::string name, std::string xcFrameworkLocation)
37
0
      : Name(std::move(name))
38
0
      , XcFrameworkLocation(std::move(xcFrameworkLocation))
39
0
    {
40
0
    }
41
42
    std::string Name;
43
    std::string XcFrameworkLocation;
44
  };
45
46
  cmExportBuildFileGenerator();
47
48
  /** Set the list of targets to export.  */
49
  void SetTargets(std::vector<TargetExport> const& targets)
50
0
  {
51
0
    this->Targets = targets;
52
0
  }
53
  void GetTargets(std::vector<TargetExport>& targets) const;
54
  void AppendTargets(std::vector<TargetExport> const& targets)
55
0
  {
56
0
    cm::append(this->Targets, targets);
57
0
  }
58
  void SetExportSet(cmExportSet*);
59
60
  struct ExportRecord
61
  {
62
    std::string Name;      // export set name; empty for anonymous exports
63
    std::string Namespace; // export namespace
64
  };
65
66
  /** If this export contains `target`, return a record identifying it
67
   *  (export set name + namespace).  Used by cmGlobalGenerator to assemble
68
   *  a project-wide view of where targets are exported.  */
69
  cm::optional<ExportRecord> FindRecordForTarget(
70
    cmGeneratorTarget const* target) const;
71
72
  /** Set the name of the C++ module directory.  */
73
  void SetCxxModuleDirectory(std::string cxx_module_dir)
74
0
  {
75
0
    this->CxxModulesDirectory = std::move(cxx_module_dir);
76
0
  }
77
  std::string const& GetCxxModuleDirectory() const
78
0
  {
79
0
    return this->CxxModulesDirectory;
80
0
  }
81
82
  void Compute(cmLocalGenerator* lg);
83
84
protected:
85
  cmStateEnums::TargetType GetExportTargetType(
86
    cmGeneratorTarget const* target) const;
87
88
  /** Walk the list of targets to be exported.  Returns true iff no duplicates
89
      are found.  */
90
  bool CollectExports(std::function<void(cmGeneratorTarget const*)> visitor);
91
92
  void HandleMissingTarget(std::string& link_libs,
93
                           cmGeneratorTarget const* depender,
94
                           cmGeneratorTarget* dependee) override;
95
96
  void ComplainAboutMissingTarget(cmGeneratorTarget const* depender,
97
                                  cmGeneratorTarget const* dependee,
98
                                  ExportInfo const& exportInfo) const;
99
100
  void ComplainAboutDuplicateTarget(
101
    std::string const& targetName) const override;
102
103
  void IssueMessage(MessageType type,
104
                    std::string const& message) const override;
105
  void IssueDiagnostic(cmDiagnosticCategory category,
106
                       std::string const& message) const override;
107
108
  /** Fill in properties indicating built file locations.  */
109
  void SetImportLocationProperty(std::string const& config,
110
                                 std::string const& suffix,
111
                                 cmGeneratorTarget* target,
112
                                 ImportPropertyMap& properties);
113
114
  std::string InstallNameDir(cmGeneratorTarget const* target,
115
                             std::string const& config) override;
116
117
0
  cmExportSet* GetExportSet() const override { return this->ExportSet; }
118
119
  std::string GetCxxModulesDirectory() const override
120
0
  {
121
0
    return this->CxxModulesDirectory;
122
0
  }
123
124
  ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
125
126
  using cmExportFileGenerator::PopulateInterfaceProperties;
127
  bool PopulateInterfaceProperties(cmGeneratorTarget const* target,
128
                                   ImportPropertyMap& properties);
129
130
  using cmExportFileGenerator::PopulateFileSetInterfaceProperties;
131
  bool PopulateFileSetInterfaceProperties(
132
    cmGeneratorTarget const* target, ImportFileSetPropertyMap& properties);
133
134
  struct TargetExportPrivate
135
  {
136
    TargetExportPrivate(cmGeneratorTarget* target,
137
                        std::string xcFrameworkLocation)
138
0
      : Target(target)
139
0
      , XcFrameworkLocation(std::move(xcFrameworkLocation))
140
0
    {
141
0
    }
142
143
    cmGeneratorTarget* Target;
144
    std::string XcFrameworkLocation;
145
  };
146
147
  std::vector<TargetExport> Targets;
148
  cmExportSet* ExportSet;
149
  std::vector<TargetExportPrivate> Exports;
150
  cmLocalGenerator* LG;
151
  // The directory for C++ module information.
152
  std::string CxxModulesDirectory;
153
};