/src/CMake/Source/cmExportPackageInfoGenerator.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 <iosfwd> |
8 | | #include <map> |
9 | | #include <string> |
10 | | #include <vector> |
11 | | |
12 | | #include <cm/string_view> |
13 | | |
14 | | #include "cmExportFileGenerator.h" |
15 | | #include "cmFindPackageStack.h" |
16 | | |
17 | | namespace cm { |
18 | | enum class TargetType; |
19 | | } // namespace cm |
20 | | |
21 | | namespace Json { |
22 | | class Value; |
23 | | } |
24 | | |
25 | | class cmGeneratorFileSet; |
26 | | class cmGeneratorTarget; |
27 | | class cmPackageInfoArguments; |
28 | | class cmTargetExport; |
29 | | |
30 | | /** \class cmExportPackageInfoGenerator |
31 | | * \brief Generate Common Package Specification package information files |
32 | | * exporting targets from a build or install tree. |
33 | | * |
34 | | * cmExportPackageInfoGenerator is the superclass for |
35 | | * cmExportBuildPackageInfoGenerator and cmExportInstallPackageInfoGenerator. |
36 | | * It contains common code generation routines for the two kinds of export |
37 | | * implementations. |
38 | | */ |
39 | | class cmExportPackageInfoGenerator : virtual public cmExportFileGenerator |
40 | | { |
41 | | public: |
42 | | cmExportPackageInfoGenerator(cmPackageInfoArguments arguments); |
43 | | |
44 | | using cmExportFileGenerator::GenerateImportFile; |
45 | | |
46 | | protected: |
47 | 0 | std::string const& GetPackageName() const { return this->PackageName; } |
48 | | |
49 | | void WritePackageInfo(Json::Value const& packageInfo, |
50 | | std::ostream& os) const; |
51 | | |
52 | | // Methods to implement export file code generation. |
53 | | bool GenerateImportFile(std::ostream& os) override; |
54 | | |
55 | | bool CheckPackage() const |
56 | 0 | { |
57 | 0 | return this->CheckVersion() && this->CheckDefaultTargets(); |
58 | 0 | } |
59 | | |
60 | | Json::Value GeneratePackageInfo() const; |
61 | | Json::Value* GenerateImportTarget(Json::Value& components, |
62 | | cmGeneratorTarget const* target, |
63 | | cm::TargetType targetType) const; |
64 | | |
65 | | void GeneratePackageRequires(Json::Value& package) const; |
66 | | |
67 | | using ImportPropertyMap = std::map<std::string, std::string>; |
68 | | bool GenerateInterfaceProperties(Json::Value& component, |
69 | | cmGeneratorTarget const* target, |
70 | | ImportPropertyMap const& properties) const; |
71 | | Json::Value GenerateInterfaceConfigProperties( |
72 | | std::string const& suffix, ImportPropertyMap const& properties) const; |
73 | | |
74 | | void GenerateTargetFileSets( |
75 | | Json::Value& component, cmGeneratorTarget const* target, |
76 | | cmTargetExport const* targetExport = nullptr) const; |
77 | | virtual void GenerateTargetFileSets(Json::Value& fileSets, |
78 | | cmGeneratorTarget const* target, |
79 | | cmGeneratorFileSet const* fileSet, |
80 | | cmTargetExport const* targetExport, |
81 | | std::string const& type) const = 0; |
82 | | static void GenerateTargetFileSet(Json::Value& fileSets, |
83 | | cmGeneratorFileSet const* fileSet, |
84 | | std::string const& type, |
85 | | std::string const& root, |
86 | | std::vector<std::string> const& files); |
87 | | |
88 | | cm::string_view GetImportPrefixWithSlash() const override; |
89 | | |
90 | | std::string GetCxxModuleFile(std::string const& /*name*/) const override |
91 | 0 | { |
92 | | // CPS does not have a general CxxModuleFile, we use the config-specific |
93 | | // manifests directly |
94 | 0 | return {}; |
95 | 0 | } |
96 | | |
97 | | void GenerateCxxModuleConfigInformation(std::string const& /*name*/, |
98 | | std::ostream& /*os*/) const override |
99 | 0 | { |
100 | | // We embed this directly in the CPS json |
101 | 0 | } |
102 | | |
103 | | std::string GenerateCxxModules(Json::Value& component, |
104 | | cmGeneratorTarget* target, |
105 | | std::string const& packagePath, |
106 | | std::string const& config); |
107 | | |
108 | | bool NoteLinkedTarget(cmGeneratorTarget const* target, |
109 | | std::string const& linkedName, |
110 | | cmGeneratorTarget const* linkedTarget) override; |
111 | | |
112 | | private: |
113 | | bool CheckVersion() const; |
114 | | bool CheckDefaultTargets() const; |
115 | | |
116 | | std::vector<std::string> ExtractRequirements( |
117 | | std::vector<std::string> const& names, bool& result, |
118 | | std::vector<std::string>& libraryPaths) const; |
119 | | |
120 | | void GenerateInterfaceLinkProperties( |
121 | | bool& result, Json::Value& component, cmGeneratorTarget const* target, |
122 | | ImportPropertyMap const& properties) const; |
123 | | |
124 | | void GenerateInterfaceCompileFeatures( |
125 | | bool& result, Json::Value& component, cmGeneratorTarget const* target, |
126 | | ImportPropertyMap const& properties) const; |
127 | | |
128 | | void GenerateInterfaceCompileDefines( |
129 | | bool& result, Json::Value& component, cmGeneratorTarget const* target, |
130 | | ImportPropertyMap const& properties) const; |
131 | | |
132 | | void GenerateInterfaceListProperty( |
133 | | bool& result, Json::Value& component, cmGeneratorTarget const* target, |
134 | | std::string const& outName, cm::string_view inName, |
135 | | ImportPropertyMap const& properties) const; |
136 | | |
137 | | void GenerateProperty(bool& result, Json::Value& component, |
138 | | cmGeneratorTarget const* target, |
139 | | std::string const& outName, std::string const& inName, |
140 | | ImportPropertyMap const& properties) const; |
141 | | |
142 | | std::string const PackageName; |
143 | | std::string const PackageVersion; |
144 | | std::string const PackageVersionCompat; |
145 | | std::string const PackageVersionSchema; |
146 | | std::string const PackageDescription; |
147 | | std::string const PackageWebsite; |
148 | | std::string const PackageLicense; |
149 | | std::string const DefaultLicense; |
150 | | |
151 | | std::vector<std::string> DefaultTargets; |
152 | | std::vector<std::string> DefaultConfigurations; |
153 | | |
154 | | std::map<std::string, std::string> LinkTargets; |
155 | | std::map<std::string, cmPackageInformation> Requirements; |
156 | | }; |