/src/CMake/Source/cmExportBuildFileGenerator.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 <string> |
9 | | #include <utility> |
10 | | #include <vector> |
11 | | |
12 | | #include <cm/optional> |
13 | | #include <cmext/algorithm> |
14 | | |
15 | | #include "cmDiagnosticContext.h" |
16 | | #include "cmDiagnostics.h" |
17 | | #include "cmExportFileGenerator.h" |
18 | | #include "cmTargetTypes.h" |
19 | | |
20 | | class cmExportSet; |
21 | | class cmGeneratorTarget; |
22 | | class cmLocalGenerator; |
23 | | class cmMakefile; |
24 | | |
25 | | /** \class cmExportBuildCMakeConfigGenerator |
26 | | * \brief Generate a file exporting targets from a build tree. |
27 | | * |
28 | | * cmExportBuildCMakeConfigGenerator is the interface class for generating a |
29 | | * file exporting targets from a build tree. |
30 | | * |
31 | | * This is used to implement the export() command. |
32 | | */ |
33 | | class cmExportBuildFileGenerator : virtual public cmExportFileGenerator |
34 | | { |
35 | | public: |
36 | | struct TargetExport |
37 | | { |
38 | | TargetExport(std::string name, std::string xcFrameworkLocation) |
39 | 0 | : Name(std::move(name)) |
40 | 0 | , XcFrameworkLocation(std::move(xcFrameworkLocation)) |
41 | 0 | { |
42 | 0 | } |
43 | | |
44 | | std::string Name; |
45 | | std::string XcFrameworkLocation; |
46 | | }; |
47 | | |
48 | | cmExportBuildFileGenerator(cmDiagnosticContext context); |
49 | | |
50 | | /** Set the list of targets to export. */ |
51 | | void SetTargets(std::vector<TargetExport> const& targets) |
52 | 0 | { |
53 | 0 | this->Targets = targets; |
54 | 0 | } |
55 | | void GetTargets(std::vector<TargetExport>& targets) const; |
56 | | void AppendTargets(std::vector<TargetExport> const& targets) |
57 | 0 | { |
58 | 0 | cm::append(this->Targets, targets); |
59 | 0 | } |
60 | | void SetExportSet(cmExportSet*); |
61 | | |
62 | | struct ExportRecord |
63 | | { |
64 | | std::string Name; // export set name; empty for anonymous exports |
65 | | std::string Namespace; // export namespace |
66 | | }; |
67 | | |
68 | | /** If this export contains `target`, return a record identifying it |
69 | | * (export set name + namespace). Used by cmGlobalGenerator to assemble |
70 | | * a project-wide view of where targets are exported. */ |
71 | | cm::optional<ExportRecord> FindRecordForTarget( |
72 | | cmGeneratorTarget const* target) const; |
73 | | |
74 | | /** Set the name of the C++ module directory. */ |
75 | | void SetCxxModuleDirectory(std::string cxx_module_dir) |
76 | 0 | { |
77 | 0 | this->CxxModulesDirectory = std::move(cxx_module_dir); |
78 | 0 | } |
79 | | std::string const& GetCxxModuleDirectory() const |
80 | 0 | { |
81 | 0 | return this->CxxModulesDirectory; |
82 | 0 | } |
83 | | |
84 | | void Compute(cmLocalGenerator* lg); |
85 | | |
86 | | /** Capture context for generator. */ |
87 | | static cmDiagnosticContext CaptureContext(cmMakefile const& mf); |
88 | | |
89 | | protected: |
90 | | cm::TargetType GetExportTargetType(cmGeneratorTarget const* target) const; |
91 | | |
92 | | /** Walk the list of targets to be exported. Returns true iff no duplicates |
93 | | are found. */ |
94 | | bool CollectExports(std::function<void(cmGeneratorTarget const*)> visitor); |
95 | | |
96 | | void HandleMissingTarget(std::string& link_libs, |
97 | | cmGeneratorTarget const* depender, |
98 | | cmGeneratorTarget* dependee) override; |
99 | | |
100 | | void ComplainAboutMissingTarget(cmGeneratorTarget const* depender, |
101 | | cmGeneratorTarget const* dependee, |
102 | | ExportInfo const& exportInfo) const; |
103 | | |
104 | | void ComplainAboutDuplicateTarget( |
105 | | std::string const& targetName) const override; |
106 | | |
107 | | void IssueMessage(MessageType type, |
108 | | std::string const& message) const override; |
109 | | void IssueDiagnostic(cmDiagnosticCategory category, |
110 | | std::string const& message) const override; |
111 | | |
112 | | /** Fill in properties indicating built file locations. */ |
113 | | void SetImportLocationProperty(std::string const& config, |
114 | | std::string const& suffix, |
115 | | cmGeneratorTarget* target, |
116 | | ImportPropertyMap& properties); |
117 | | |
118 | | std::string InstallNameDir(cmGeneratorTarget const* target, |
119 | | std::string const& config) override; |
120 | | |
121 | 0 | cmExportSet* GetExportSet() const override { return this->ExportSet; } |
122 | | |
123 | | std::string GetCxxModulesDirectory() const override |
124 | 0 | { |
125 | 0 | return this->CxxModulesDirectory; |
126 | 0 | } |
127 | | |
128 | | ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override; |
129 | | |
130 | | using cmExportFileGenerator::PopulateInterfaceProperties; |
131 | | bool PopulateInterfaceProperties(cmGeneratorTarget const* target, |
132 | | ImportPropertyMap& properties); |
133 | | |
134 | | using cmExportFileGenerator::PopulateFileSetInterfaceProperties; |
135 | | bool PopulateFileSetInterfaceProperties( |
136 | | cmGeneratorTarget const* target, ImportFileSetPropertyMap& properties); |
137 | | |
138 | | struct TargetExportPrivate |
139 | | { |
140 | | TargetExportPrivate(cmGeneratorTarget* target, |
141 | | std::string xcFrameworkLocation) |
142 | 0 | : Target(target) |
143 | 0 | , XcFrameworkLocation(std::move(xcFrameworkLocation)) |
144 | 0 | { |
145 | 0 | } |
146 | | |
147 | | cmGeneratorTarget* Target; |
148 | | std::string XcFrameworkLocation; |
149 | | }; |
150 | | |
151 | | cmDiagnosticContext Context; |
152 | | std::vector<TargetExport> Targets; |
153 | | cmExportSet* ExportSet; |
154 | | std::vector<TargetExportPrivate> Exports; |
155 | | cmLocalGenerator* LG; |
156 | | // The directory for C++ module information. |
157 | | std::string CxxModulesDirectory; |
158 | | }; |