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