Coverage Report

Created: 2026-07-14 07:09

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 "cmTargetTypes.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
  cm::TargetType GetExportTargetType(cmTargetExport const* targetExport) const;
73
74
  virtual std::string const& GetExportName() const;
75
76
  std::string GetInstallPrefix() const
77
0
  {
78
0
    cm::string_view const prefixWithSlash = this->GetImportPrefixWithSlash();
79
0
    return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1);
80
0
  }
81
  virtual char GetConfigFileNameSeparator() const = 0;
82
83
  void HandleMissingTarget(std::string& link_libs,
84
                           cmGeneratorTarget const* depender,
85
                           cmGeneratorTarget* dependee) override;
86
87
  void ReplaceInstallPrefix(std::string& input) const override;
88
89
  void ComplainAboutMissingTarget(cmGeneratorTarget const* depender,
90
                                  cmGeneratorTarget const* dependee,
91
                                  ExportInfo const& exportInfo) const;
92
93
  void ComplainAboutDuplicateTarget(
94
    std::string const& targetName) const override;
95
96
  ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
97
98
  void IssueMessage(MessageType type,
99
                    std::string const& message) const override;
100
  void IssueDiagnostic(cmDiagnosticCategory category,
101
                       std::string const& message) const override;
102
103
  /** Generate a per-configuration file for the targets.  */
104
  virtual bool GenerateImportFileConfig(std::string const& config);
105
106
  /** Fill in properties indicating installed file locations.  */
107
  void SetImportLocationProperty(std::string const& config,
108
                                 std::string const& suffix,
109
                                 cmInstallTargetGenerator* itgen,
110
                                 ImportPropertyMap& properties,
111
                                 std::set<std::string>& importedLocations);
112
113
  std::string InstallNameDir(cmGeneratorTarget const* target,
114
                             std::string const& config) override;
115
116
  using cmExportFileGenerator::GetCxxModuleFile;
117
118
  /** Walk the list of targets to be exported.  Returns true iff no duplicates
119
      are found.  */
120
  bool CollectExports(
121
    std::function<void(cmTargetExport const*)> const& visitor);
122
123
  cmExportSet* GetExportSet() const override
124
0
  {
125
0
    return this->IEGen->GetExportSet();
126
0
  }
127
128
  std::string GetImportXcFrameworkLocation(
129
    std::string const& config, cmTargetExport const* targetExport) const;
130
131
  using cmExportFileGenerator::PopulateInterfaceProperties;
132
  bool PopulateInterfaceProperties(cmTargetExport const* targetExport,
133
                                   ImportPropertyMap& properties);
134
135
  void PopulateImportProperties(std::string const& config,
136
                                std::string const& suffix,
137
                                cmTargetExport const* targetExport,
138
                                ImportPropertyMap& properties,
139
                                std::set<std::string>& importedLocations);
140
141
  using cmExportFileGenerator::PopulateFileSetInterfaceProperties;
142
  bool PopulateFileSetInterfaceProperties(
143
    cmTargetExport const* targetExport, ImportFileSetPropertyMap& properties);
144
145
  virtual bool CheckInterfaceDirs(std::string const& prepro,
146
                                  cmGeneratorTarget const* target,
147
                                  std::string const& prop) const;
148
149
  cmInstallExportGenerator* IEGen;
150
151
  // The import file generated for each configuration.
152
  std::map<std::string, std::string> ConfigImportFiles;
153
  // The C++ module property file generated for each configuration.
154
  std::map<std::string, std::string> ConfigCxxModuleFiles;
155
  // The C++ module property target files generated for each configuration.
156
  std::map<std::string, std::vector<std::string>> ConfigCxxModuleTargetFiles;
157
158
private:
159
  void PopulateCompatibleInterfaceProperties(cmGeneratorTarget const* target,
160
                                             ImportPropertyMap& properties);
161
  void PopulateCustomTransitiveInterfaceProperties(
162
    cmGeneratorTarget const* target,
163
    cmGeneratorExpression::PreprocessContext preprocessRule,
164
    ImportPropertyMap& properties);
165
  void PopulateIncludeDirectoriesInterface(
166
    cmGeneratorTarget const* target,
167
    cmGeneratorExpression::PreprocessContext preprocessRule,
168
    ImportPropertyMap& properties, cmTargetExport const& te,
169
    std::string& includesDestinationDirs);
170
  void PopulateSystemIncludeDirectoriesInterface(
171
    cmGeneratorTarget const* target,
172
    cmGeneratorExpression::PreprocessContext preprocessRule,
173
    ImportPropertyMap& properties);
174
  void PopulateSourcesInterface(
175
    cmGeneratorTarget const* target,
176
    cmGeneratorExpression::PreprocessContext preprocessRule,
177
    ImportPropertyMap& properties);
178
  void PopulateLinkDirectoriesInterface(
179
    cmGeneratorTarget const* target,
180
    cmGeneratorExpression::PreprocessContext preprocessRule,
181
    ImportPropertyMap& properties);
182
  void PopulateLinkDependsInterface(
183
    cmGeneratorTarget const* target,
184
    cmGeneratorExpression::PreprocessContext preprocessRule,
185
    ImportPropertyMap& properties);
186
187
  void PopulateFileSetIncludeDirectoriesInterface(
188
    cmGeneratorTarget const* target, cmGeneratorFileSet const* fileSet,
189
    cmGeneratorExpression::PreprocessContext preprocessRule,
190
    ImportPropertyMap& properties);
191
};