/src/CMake/Source/cmCxxModuleMetadata.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 <string> |
6 | | #include <vector> |
7 | | |
8 | | #include <cm/optional> |
9 | | #include <cm/string_view> |
10 | | |
11 | | #include <cm3p/json/value.h> |
12 | | |
13 | | class cmTarget; |
14 | | |
15 | | class cmCxxModuleMetadata |
16 | | { |
17 | | public: |
18 | | struct PreprocessorDefineData |
19 | | { |
20 | | // definition["name"] |
21 | | std::string Name; |
22 | | // definition["value"] |
23 | | cm::optional<std::string> Value; |
24 | | // definition["undef"] |
25 | | bool Undef = false; |
26 | | }; |
27 | | |
28 | | struct LocalArgumentsData |
29 | | { |
30 | | // local-arguments["include-directories"] |
31 | | std::vector<std::string> IncludeDirectories; |
32 | | // local-arguments["system-include-directories"] |
33 | | std::vector<std::string> SystemIncludeDirectories; |
34 | | // local-arguments["definitions"] |
35 | | std::vector<PreprocessorDefineData> Definitions; |
36 | | |
37 | | // These are CMake vendor extensions |
38 | | // local-arguments["vendor"]["cmake"]["compile-options"] |
39 | | std::vector<std::string> CompileOptions; |
40 | | // local-arguments["vendor"]["cmake"]["compile-features"] |
41 | | std::vector<std::string> CompileFeatures; |
42 | | }; |
43 | | |
44 | | struct ModuleData |
45 | | { |
46 | | // module["logical-name"] |
47 | | std::string LogicalName; |
48 | | // module["source-path"] |
49 | | std::string SourcePath; |
50 | | // module["is-interface"] |
51 | | bool IsInterface = true; |
52 | | // module["is-std-library"] |
53 | | bool IsStdLibrary = false; |
54 | | // module["local-arguments"] |
55 | | cm::optional<LocalArgumentsData> LocalArguments; |
56 | | }; |
57 | | |
58 | | // root["version"] |
59 | | int Version = 1; |
60 | | // root["revision"] |
61 | | int Revision = 1; |
62 | | // root["modules"] |
63 | | std::vector<ModuleData> Modules; |
64 | | |
65 | | // The path to the manifest file, either absolute or relative to the |
66 | | // installation root |
67 | | std::string MetadataFilePath; |
68 | | |
69 | | struct ParseResult; |
70 | | |
71 | | struct SaveResult |
72 | | { |
73 | | bool Ok = false; |
74 | | std::string Error; |
75 | 0 | explicit operator bool() const { return Ok; } |
76 | | }; |
77 | | |
78 | | static ParseResult LoadFromFile(std::string const& path); |
79 | | static Json::Value ToJsonValue(cmCxxModuleMetadata const& meta); |
80 | | static SaveResult SaveToFile(std::string const& path, |
81 | | cmCxxModuleMetadata const& meta); |
82 | | static void PopulateTarget(cmTarget& target, cmCxxModuleMetadata const& meta, |
83 | | std::vector<std::string> const& configs); |
84 | | static void PopulateTarget(cmTarget& target, cmCxxModuleMetadata const& meta, |
85 | | cm::string_view config) |
86 | 0 | { |
87 | 0 | PopulateTarget(target, meta, |
88 | 0 | std::vector<std::string>{ std::string(config) }); |
89 | 0 | } |
90 | | static void PopulateTarget(cmTarget& target, cmCxxModuleMetadata const& meta) |
91 | 0 | { |
92 | 0 | PopulateTarget(target, meta, "NOCONFIG"); |
93 | 0 | } |
94 | | }; |
95 | | |
96 | | struct cmCxxModuleMetadata::ParseResult |
97 | | { |
98 | | cm::optional<cmCxxModuleMetadata> Meta; |
99 | | std::string Error; |
100 | 0 | explicit operator bool() const { return static_cast<bool>(Meta); } |
101 | | }; |