Merge branch 'release-3.31'
[kiteware-cmake.git] / Source / cmExportInstallFileGenerator.h
blobf33ecc112b5be3ad7b3e7864622b64f1e53b7133
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <functional>
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include <cm/string_view>
15 #include "cmExportFileGenerator.h"
16 #include "cmGeneratorExpression.h"
17 #include "cmInstallExportGenerator.h"
18 #include "cmStateTypes.h"
20 class cmExportSet;
21 class cmGeneratorTarget;
22 class cmInstallTargetGenerator;
23 class cmTargetExport;
25 /** \class cmExportInstallFileGenerator
26 * \brief Generate a file exporting targets from an install tree.
28 * cmExportInstallFileGenerator is the generic interface class for generating
29 * export files for an install tree.
31 class cmExportInstallFileGenerator : virtual public cmExportFileGenerator
33 public:
34 /** Construct with the export installer that will install the
35 files. */
36 cmExportInstallFileGenerator(cmInstallExportGenerator* iegen);
38 /** Get the per-config file generated for each configuration. This
39 maps from the configuration name to the file temporary location
40 for installation. */
41 std::map<std::string, std::string> const& GetConfigImportFiles()
43 return this->ConfigImportFiles;
46 /** Get the temporary location of the config-agnostic C++ module file. */
47 std::string GetCxxModuleFile() const;
49 /** Get the per-config C++ module file generated for each configuration.
50 This maps from the configuration name to the file temporary location
51 for installation. */
52 std::map<std::string, std::string> const& GetConfigCxxModuleFiles()
54 return this->ConfigCxxModuleFiles;
57 /** Get the per-config C++ module file generated for each configuration.
58 This maps from the configuration name to the file temporary location
59 for installation for each target in the export set. */
60 std::map<std::string, std::vector<std::string>> const&
61 GetConfigCxxModuleTargetFiles()
63 return this->ConfigCxxModuleTargetFiles;
66 /** Compute the globbing expression used to load per-config import
67 files from the main file. */
68 virtual std::string GetConfigImportFileGlob() const = 0;
70 protected:
71 cmStateEnums::TargetType GetExportTargetType(
72 cmTargetExport const* targetExport) const;
74 virtual std::string const& GetExportName() const;
76 std::string GetInstallPrefix() const
78 cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash();
79 return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1);
81 virtual char GetConfigFileNameSeparator() const = 0;
83 void HandleMissingTarget(std::string& link_libs,
84 cmGeneratorTarget const* depender,
85 cmGeneratorTarget* dependee) override;
87 void ReplaceInstallPrefix(std::string& input) const override;
89 void ComplainAboutMissingTarget(
90 cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
91 std::vector<std::string> const& exportFiles) const;
93 void ComplainAboutDuplicateTarget(
94 std::string const& targetName) const override;
96 ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
98 void ReportError(std::string const& errorMessage) const override;
100 /** Generate a per-configuration file for the targets. */
101 virtual bool GenerateImportFileConfig(std::string const& config);
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);
110 std::string InstallNameDir(cmGeneratorTarget const* target,
111 std::string const& config) override;
113 using cmExportFileGenerator::GetCxxModuleFile;
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);
120 cmExportSet* GetExportSet() const override
122 return this->IEGen->GetExportSet();
125 std::string GetImportXcFrameworkLocation(
126 std::string const& config, cmTargetExport const* targetExport) const;
128 using cmExportFileGenerator::PopulateInterfaceProperties;
129 bool PopulateInterfaceProperties(cmTargetExport const* targetExport,
130 ImportPropertyMap& properties);
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);
138 cmInstallExportGenerator* IEGen;
140 // The import file generated for each configuration.
141 std::map<std::string, std::string> ConfigImportFiles;
142 // The C++ module property file generated for each configuration.
143 std::map<std::string, std::string> ConfigCxxModuleFiles;
144 // The C++ module property target files generated for each configuration.
145 std::map<std::string, std::vector<std::string>> ConfigCxxModuleTargetFiles;
147 private:
148 bool CheckInterfaceDirs(std::string const& prepro,
149 cmGeneratorTarget const* target,
150 std::string const& prop) const;
151 void PopulateCompatibleInterfaceProperties(cmGeneratorTarget const* target,
152 ImportPropertyMap& properties);
153 void PopulateCustomTransitiveInterfaceProperties(
154 cmGeneratorTarget const* target,
155 cmGeneratorExpression::PreprocessContext preprocessRule,
156 ImportPropertyMap& properties);
157 void PopulateIncludeDirectoriesInterface(
158 cmGeneratorTarget const* target,
159 cmGeneratorExpression::PreprocessContext preprocessRule,
160 ImportPropertyMap& properties, cmTargetExport const& te,
161 std::string& includesDestinationDirs);
162 void PopulateSourcesInterface(
163 cmGeneratorTarget const* target,
164 cmGeneratorExpression::PreprocessContext preprocessRule,
165 ImportPropertyMap& properties);
166 void PopulateLinkDirectoriesInterface(
167 cmGeneratorTarget const* target,
168 cmGeneratorExpression::PreprocessContext preprocessRule,
169 ImportPropertyMap& properties);
170 void PopulateLinkDependsInterface(
171 cmGeneratorTarget const* target,
172 cmGeneratorExpression::PreprocessContext preprocessRule,
173 ImportPropertyMap& properties);