Coverage Report

Created: 2026-04-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmExportInstallFileGenerator.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 <map>
9
#include <set>
10
#include <string>
11
#include <vector>
12
13
#include <cm/string_view>
14
15
#include "cmDiagnostics.h"
16
#include "cmExportFileGenerator.h"
17
#include "cmGeneratorExpression.h"
18
#include "cmInstallExportGenerator.h"
19
#include "cmStateTypes.h"
20
21
class cmGeneratorTarget;
22
class cmGeneratorFileSet;
23
class cmInstallTargetGenerator;
24
class cmTargetExport;
25
26
/** \class cmExportInstallFileGenerator
27
 * \brief Generate a file exporting targets from an install tree.
28
 *
29
 * cmExportInstallFileGenerator is the generic interface class for generating
30
 * export files for an install tree.
31
 */
32
class cmExportInstallFileGenerator : virtual public cmExportFileGenerator
33
{
34
public:
35
  /** Construct with the export installer that will install the
36
      files.  */
37
  cmExportInstallFileGenerator(cmInstallExportGenerator* iegen);
38
39
  /** Get the per-config file generated for each configuration.  This
40
      maps from the configuration name to the file temporary location
41
      for installation.  */
42
  std::map<std::string, std::string> const& GetConfigImportFiles()
43
0
  {
44
0
    return this->ConfigImportFiles;
45
0
  }
46
47
  /** Get the temporary location of the config-agnostic C++ module file.  */
48
  std::string GetCxxModuleFile() const;
49
50
  /** Get the per-config C++ module file generated for each configuration.
51
      This maps from the configuration name to the file temporary location
52
      for installation.  */
53
  std::map<std::string, std::string> const& GetConfigCxxModuleFiles()
54
0
  {
55
0
    return this->ConfigCxxModuleFiles;
56
0
  }
57
58
  /** Get the per-config C++ module file generated for each configuration.
59
      This maps from the configuration name to the file temporary location
60
      for installation for each target in the export set.  */
61
  std::map<std::string, std::vector<std::string>> const&
62
  GetConfigCxxModuleTargetFiles()
63
0
  {
64
0
    return this->ConfigCxxModuleTargetFiles;
65
0
  }
66
67
  /** Compute the globbing expression used to load per-config import
68
      files from the main file.  */
69
  virtual std::string GetConfigImportFileGlob() const = 0;
70
71
protected:
72
  cmStateEnums::TargetType GetExportTargetType(
73
    cmTargetExport const* targetExport) const;
74
75
  virtual std::string const& GetExportName() const;
76
77
  std::string GetInstallPrefix() const
78
0
  {
79
0
    cm::string_view const prefixWithSlash = this->GetImportPrefixWithSlash();
80
0
    return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1);
81
0
  }
82
  virtual char GetConfigFileNameSeparator() const = 0;
83
84
  void HandleMissingTarget(std::string& link_libs,
85
                           cmGeneratorTarget const* depender,
86
                           cmGeneratorTarget* dependee) override;
87
88
  void ReplaceInstallPrefix(std::string& input) const override;
89
90
  void ComplainAboutMissingTarget(cmGeneratorTarget const* depender,
91
                                  cmGeneratorTarget const* dependee,
92
                                  ExportInfo const& exportInfo) const;
93
94
  void ComplainAboutDuplicateTarget(
95
    std::string const& targetName) const override;
96
97
  ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
98
99
  void IssueMessage(MessageType type,
100
                    std::string const& message) const override;
101
  void IssueDiagnostic(cmDiagnosticCategory category,
102
                       std::string const& message) const override;
103
104
  /** Generate a per-configuration file for the targets.  */
105
  virtual bool GenerateImportFileConfig(std::string const& config);
106
107
  /** Fill in properties indicating installed file locations.  */
108
  void SetImportLocationProperty(std::string const& config,
109
                                 std::string const& suffix,
110
                                 cmInstallTargetGenerator* itgen,
111
                                 ImportPropertyMap& properties,
112
                                 std::set<std::string>& importedLocations);
113
114
  std::string InstallNameDir(cmGeneratorTarget const* target,
115
                             std::string const& config) override;
116
117
  using cmExportFileGenerator::GetCxxModuleFile;
118
119
  /** Walk the list of targets to be exported.  Returns true iff no duplicates
120
      are found.  */
121
  bool CollectExports(
122
    std::function<void(cmTargetExport const*)> const& visitor);
123
124
  cmExportSet* GetExportSet() const override
125
0
  {
126
0
    return this->IEGen->GetExportSet();
127
0
  }
128
129
  std::string GetImportXcFrameworkLocation(
130
    std::string const& config, cmTargetExport const* targetExport) const;
131
132
  using cmExportFileGenerator::PopulateInterfaceProperties;
133
  bool PopulateInterfaceProperties(cmTargetExport const* targetExport,
134
                                   ImportPropertyMap& properties);
135
136
  void PopulateImportProperties(std::string const& config,
137
                                std::string const& suffix,
138
                                cmTargetExport const* targetExport,
139
                                ImportPropertyMap& properties,
140
                                std::set<std::string>& importedLocations);
141
142
  using cmExportFileGenerator::PopulateFileSetInterfaceProperties;
143
  bool PopulateFileSetInterfaceProperties(
144
    cmTargetExport const* targetExport, ImportFileSetPropertyMap& properties);
145
146
  virtual bool CheckInterfaceDirs(std::string const& prepro,
147
                                  cmGeneratorTarget const* target,
148
                                  std::string const& prop) const;
149
150
  cmInstallExportGenerator* IEGen;
151
152
  // The import file generated for each configuration.
153
  std::map<std::string, std::string> ConfigImportFiles;
154
  // The C++ module property file generated for each configuration.
155
  std::map<std::string, std::string> ConfigCxxModuleFiles;
156
  // The C++ module property target files generated for each configuration.
157
  std::map<std::string, std::vector<std::string>> ConfigCxxModuleTargetFiles;
158
159
private:
160
  void PopulateCompatibleInterfaceProperties(cmGeneratorTarget const* target,
161
                                             ImportPropertyMap& properties);
162
  void PopulateCustomTransitiveInterfaceProperties(
163
    cmGeneratorTarget const* target,
164
    cmGeneratorExpression::PreprocessContext preprocessRule,
165
    ImportPropertyMap& properties);
166
  void PopulateIncludeDirectoriesInterface(
167
    cmGeneratorTarget const* target,
168
    cmGeneratorExpression::PreprocessContext preprocessRule,
169
    ImportPropertyMap& properties, cmTargetExport const& te,
170
    std::string& includesDestinationDirs);
171
  void PopulateSystemIncludeDirectoriesInterface(
172
    cmGeneratorTarget const* target,
173
    cmGeneratorExpression::PreprocessContext preprocessRule,
174
    ImportPropertyMap& properties);
175
  void PopulateSourcesInterface(
176
    cmGeneratorTarget const* target,
177
    cmGeneratorExpression::PreprocessContext preprocessRule,
178
    ImportPropertyMap& properties);
179
  void PopulateLinkDirectoriesInterface(
180
    cmGeneratorTarget const* target,
181
    cmGeneratorExpression::PreprocessContext preprocessRule,
182
    ImportPropertyMap& properties);
183
  void PopulateLinkDependsInterface(
184
    cmGeneratorTarget const* target,
185
    cmGeneratorExpression::PreprocessContext preprocessRule,
186
    ImportPropertyMap& properties);
187
188
  void PopulateFileSetIncludeDirectoriesInterface(
189
    cmGeneratorTarget const* target, cmGeneratorFileSet const* fileSet,
190
    cmGeneratorExpression::PreprocessContext preprocessRule,
191
    ImportPropertyMap& properties);
192
};