Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Source / cmExportInstallFileGenerator.h
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
4
5 #include "cmConfigure.h" // IWYU pragma: keep
6
7 #include <iosfwd>
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 #include "cmExportFileGenerator.h"
15 #include "cmStateTypes.h"
16
17 class cmFileSet;
18 class cmGeneratorTarget;
19 class cmGlobalGenerator;
20 class cmInstallExportGenerator;
21 class cmInstallTargetGenerator;
22 class cmTargetExport;
23
24 /** \class cmExportInstallFileGenerator
25  * \brief Generate a file exporting targets from an install tree.
26  *
27  * cmExportInstallFileGenerator generates files exporting targets from
28  * install an installation tree.  The files are placed in a temporary
29  * location for installation by cmInstallExportGenerator.  One main
30  * file is generated that creates the imported targets and loads
31  * per-configuration files.  Target locations and settings for each
32  * configuration are written to these per-configuration files.  After
33  * installation the main file loads the configurations that have been
34  * installed.
35  *
36  * This is used to implement the INSTALL(EXPORT) command.
37  */
38 class cmExportInstallFileGenerator : public cmExportFileGenerator
39 {
40 public:
41   /** Construct with the export installer that will install the
42       files.  */
43   cmExportInstallFileGenerator(cmInstallExportGenerator* iegen);
44
45   /** Get the per-config file generated for each configuration.  This
46       maps from the configuration name to the file temporary location
47       for installation.  */
48   std::map<std::string, std::string> const& GetConfigImportFiles()
49   {
50     return this->ConfigImportFiles;
51   }
52
53   /** Get the per-config C++ module file generated for each configuration.
54       This maps from the configuration name to the file temporary location
55       for installation.  */
56   std::map<std::string, std::string> const& GetConfigCxxModuleFiles()
57   {
58     return this->ConfigCxxModuleFiles;
59   }
60
61   /** Get the per-config C++ module file generated for each configuration.
62       This maps from the configuration name to the file temporary location
63       for installation for each target in the export set.  */
64   std::map<std::string, std::vector<std::string>> const&
65   GetConfigCxxModuleTargetFiles()
66   {
67     return this->ConfigCxxModuleTargetFiles;
68   }
69
70   /** Compute the globbing expression used to load per-config import
71       files from the main file.  */
72   std::string GetConfigImportFileGlob();
73
74 protected:
75   // Implement virtual methods from the superclass.
76   bool GenerateMainFile(std::ostream& os) override;
77   void GenerateImportTargetsConfig(std::ostream& os, const std::string& config,
78                                    std::string const& suffix) override;
79   cmStateEnums::TargetType GetExportTargetType(
80     cmTargetExport const* targetExport) const;
81   void HandleMissingTarget(std::string& link_libs,
82                            cmGeneratorTarget const* depender,
83                            cmGeneratorTarget* dependee) override;
84
85   void ReplaceInstallPrefix(std::string& input) override;
86
87   void ComplainAboutMissingTarget(cmGeneratorTarget const* depender,
88                                   cmGeneratorTarget const* dependee,
89                                   std::vector<std::string> const& exportFiles);
90
91   std::pair<std::vector<std::string>, std::string> FindNamespaces(
92     cmGlobalGenerator* gg, const std::string& name);
93
94   /** Generate the relative import prefix.  */
95   virtual void GenerateImportPrefix(std::ostream&);
96
97   /** Generate the relative import prefix.  */
98   virtual void LoadConfigFiles(std::ostream&);
99
100   virtual void CleanupTemporaryVariables(std::ostream&);
101
102   /** Generate a per-configuration file for the targets.  */
103   virtual bool GenerateImportFileConfig(const std::string& config);
104
105   /** Fill in properties indicating installed file locations.  */
106   void SetImportLocationProperty(const std::string& config,
107                                  std::string const& suffix,
108                                  cmInstallTargetGenerator* itgen,
109                                  ImportPropertyMap& properties,
110                                  std::set<std::string>& importedLocations);
111
112   std::string InstallNameDir(cmGeneratorTarget const* target,
113                              const std::string& config) override;
114
115   std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet,
116                                     cmTargetExport* te) override;
117   std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,
118                               cmTargetExport* te) override;
119
120   std::string GetCxxModulesDirectory() const override;
121   void GenerateCxxModuleConfigInformation(std::ostream&) const override;
122   bool GenerateImportCxxModuleConfigTargetInclusion(std::string const&);
123
124   cmInstallExportGenerator* IEGen;
125
126   // The import file generated for each configuration.
127   std::map<std::string, std::string> ConfigImportFiles;
128   // The C++ module property file generated for each configuration.
129   std::map<std::string, std::string> ConfigCxxModuleFiles;
130   // The C++ module property target files generated for each configuration.
131   std::map<std::string, std::vector<std::string>> ConfigCxxModuleTargetFiles;
132 };