1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
13 #include <cm/string_view>
15 #include "cmExportFileGenerator.h"
16 #include "cmGeneratorExpression.h"
17 #include "cmInstallExportGenerator.h"
18 #include "cmStateTypes.h"
21 class cmGeneratorTarget
;
22 class cmInstallTargetGenerator
;
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
34 /** Construct with the export installer that will install the
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
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
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;
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
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
;
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
);