/src/CMake/Source/cmExportSbomGenerator.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 "cmExportFileGenerator.h" |
13 | | #include "cmFindPackageStack.h" |
14 | | #include "cmGeneratorExpression.h" |
15 | | #include "cmSbomArguments.h" |
16 | | |
17 | | class cmGeneratorTarget; |
18 | | struct cmSbomDocument; |
19 | | struct cmSpdxDocument; |
20 | | struct cmSpdxPackage; |
21 | | |
22 | | class cmExportSbomGenerator : virtual public cmExportFileGenerator |
23 | | { |
24 | | public: |
25 | | cmExportSbomGenerator(cmSbomArguments args); |
26 | | using cmExportFileGenerator::GenerateImportFile; |
27 | | |
28 | | protected: |
29 | | using ImportPropertyMap = std::map<std::string, std::string>; |
30 | | |
31 | | struct TargetProperties |
32 | | { |
33 | | cmSpdxPackage const* Package; |
34 | | cmGeneratorTarget const* Target; |
35 | | ImportPropertyMap Properties; |
36 | | }; |
37 | | |
38 | | void WriteSbom(cmSbomDocument& doc, std::ostream& os) const; |
39 | | |
40 | | cmSpdxDocument GenerateSbom() const; |
41 | | cmSpdxPackage GenerateImportTarget(cmGeneratorTarget const* target) const; |
42 | | |
43 | 0 | std::string const& GetPackageName() const { return this->PackageName; } |
44 | | |
45 | | bool GenerateImportFile(std::ostream& os) override; |
46 | | bool AddPackageInformation(cmSpdxPackage& artifact, std::string const& name, |
47 | | cmPackageInformation const& package) const; |
48 | | |
49 | | bool GenerateProperties( |
50 | | cmSbomDocument& doc, cmSpdxDocument* project, |
51 | | TargetProperties const& current, |
52 | | std::vector<TargetProperties> const& allTargets) const; |
53 | | |
54 | | void GenerateLinkProperties( |
55 | | cmSbomDocument& doc, cmSpdxDocument* project, std::string const& libraries, |
56 | | TargetProperties const& current, |
57 | | std::vector<TargetProperties> const& allTargets) const; |
58 | | |
59 | | bool NoteLinkedTarget(cmGeneratorTarget const* target, |
60 | | std::string const& linkedName, |
61 | | cmGeneratorTarget const* linkedTarget) override; |
62 | | |
63 | | bool PopulateLinkLibrariesProperty(cmGeneratorTarget const* target, |
64 | | cmGeneratorExpression::PreprocessContext, |
65 | | ImportPropertyMap& properties); |
66 | | |
67 | | private: |
68 | | struct LinkInfo |
69 | | { |
70 | | std::string Package; |
71 | | std::string Component; |
72 | | }; |
73 | | |
74 | | std::string const PackageName; |
75 | | std::string const PackageVersion; |
76 | | std::string const PackageDescription; |
77 | | std::string const PackageWebsite; |
78 | | std::string const PackageLicense; |
79 | | std::string const PackageUrl; |
80 | | cmSbomArguments::SbomFormat const PackageFormat; |
81 | | std::map<std::string, LinkInfo> LinkTargets; |
82 | | std::map<std::string, cmPackageInformation> Requirements; |
83 | | }; |