Coverage Report

Created: 2026-02-09 06:05

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