/src/CMake/Source/cmFileSetMetadata.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 <cstdint> |
6 | | #include <set> |
7 | | #include <utility> |
8 | | #include <vector> |
9 | | |
10 | | #include <cm/optional> |
11 | | #include <cm/string_view> |
12 | | #include <cmext/enum_set> |
13 | | |
14 | | class cmMakefile; |
15 | | |
16 | | namespace cm { |
17 | | namespace FileSetMetadata { |
18 | | enum class Visibility |
19 | | { |
20 | | Private, |
21 | | Public, |
22 | | Interface |
23 | | }; |
24 | | |
25 | | cm::string_view VisibilityToName(Visibility vis); |
26 | | Visibility VisibilityFromName(cm::string_view name, cmMakefile* mf); |
27 | | |
28 | | bool VisibilityIsForSelf(Visibility vis); |
29 | | bool VisibilityIsForInterface(Visibility vis); |
30 | | |
31 | | // Pre-defined FileSet types |
32 | | extern cm::string_view const HEADERS; |
33 | | extern cm::string_view const SOURCES; |
34 | | extern cm::string_view const CXX_MODULES; |
35 | | |
36 | | enum class FileSetLookup |
37 | | { |
38 | | // Search for file sets attached to the target |
39 | | Target, |
40 | | // Search also file sets inherited from link libraries |
41 | | Dependencies |
42 | | }; |
43 | | |
44 | | // Define the various modes regarding graph dependency for |
45 | | // the generated files (Ninja specific) |
46 | | // items must be kept in this order: "Lower" modes are "stronger" in that they |
47 | | // have more restrictions (and therefore allow for more build graph |
48 | | // optimization). |
49 | | // std::set rely on it. |
50 | | enum class DependencyMode |
51 | | { |
52 | | IndependentFiles, // files in the file set are independent from each other |
53 | | Includables // files can be used by another source during compilation |
54 | | }; |
55 | | using DependencySet = std::set<DependencyMode>; |
56 | | |
57 | | enum class FileSetAttributes : std::uint16_t |
58 | | { |
59 | | FrameworkCompatible, // Can be part of an Apple framework |
60 | | FilesInMultipleFileSets, // Files of this file set type can be part of other |
61 | | // file sets |
62 | | UnityBuild // Can be part of a unity build |
63 | | }; |
64 | | using AttributeSet = cm::enum_set<FileSetAttributes, 3>; |
65 | | |
66 | | struct FileSetDescriptor |
67 | | { |
68 | | FileSetDescriptor(cm::string_view type, FileSetLookup lookup, |
69 | | DependencySet dependencies, |
70 | | DependencyMode defaultDependency, AttributeSet attributes) |
71 | 12 | : Type(type) |
72 | 12 | , Lookup(lookup) |
73 | 12 | , SupportedDependencies(std::move(dependencies)) |
74 | 12 | , DefaultDependency(defaultDependency) |
75 | 12 | , Attributes(attributes) |
76 | 12 | { |
77 | 12 | } |
78 | | |
79 | | FileSetDescriptor(FileSetLookup lookup) |
80 | | : Type() |
81 | | , Lookup(lookup) |
82 | | , SupportedDependencies({ DependencyMode::Includables }) |
83 | | , DefaultDependency(DependencyMode::Includables) |
84 | 0 | { |
85 | 0 | } |
86 | | |
87 | | cm::string_view const Type; |
88 | | FileSetLookup const Lookup; |
89 | | DependencySet const SupportedDependencies; |
90 | | DependencyMode const DefaultDependency; |
91 | | AttributeSet const Attributes; |
92 | | }; |
93 | | |
94 | | cm::optional<FileSetDescriptor> GetFileSetDescriptor(cm::string_view type); |
95 | | DependencyMode GetDependencyMode(cm::string_view type); |
96 | | DependencyMode GetDependencyMode(cm::string_view type, |
97 | | DependencyMode requestedMode); |
98 | | |
99 | | AttributeSet GetAttributes(cm::string_view type); |
100 | | bool IsFrameworkSupported(cm::string_view type); |
101 | | |
102 | | std::vector<cm::string_view> const& GetKnownTypes(); |
103 | | bool IsKnownType(cm::string_view type); |
104 | | |
105 | | // check validity of a user's file set name |
106 | | bool IsValidName(cm::string_view type); |
107 | | } |
108 | | } |
109 | | |
110 | | CM_ENUM_SET_TRAITS(cm::FileSetMetadata::AttributeSet) |