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