/src/CMake/Source/cmFileSetMetadata.cxx
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 | | #include "cmFileSetMetadata.h" |
4 | | |
5 | | #include <string> |
6 | | |
7 | | #include <cmext/algorithm> |
8 | | #include <cmext/string_view> |
9 | | |
10 | | #include "cmsys/RegularExpression.hxx" |
11 | | |
12 | | #include "cmMakefile.h" |
13 | | #include "cmMessageType.h" |
14 | | #include "cmStringAlgorithms.h" |
15 | | #include "cmSystemTools.h" |
16 | | |
17 | | namespace cm { |
18 | | namespace FileSetMetadata { |
19 | | cm::string_view VisibilityToName(Visibility vis) |
20 | 0 | { |
21 | 0 | switch (vis) { |
22 | 0 | case Visibility::Interface: |
23 | 0 | return "INTERFACE"_s; |
24 | 0 | case Visibility::Public: |
25 | 0 | return "PUBLIC"_s; |
26 | 0 | case Visibility::Private: |
27 | 0 | return "PRIVATE"_s; |
28 | 0 | } |
29 | 0 | return ""_s; |
30 | 0 | } |
31 | | |
32 | | Visibility VisibilityFromName(cm::string_view name, cmMakefile* mf) |
33 | 0 | { |
34 | 0 | if (name == "INTERFACE"_s) { |
35 | 0 | return Visibility::Interface; |
36 | 0 | } |
37 | 0 | if (name == "PUBLIC"_s) { |
38 | 0 | return Visibility::Public; |
39 | 0 | } |
40 | 0 | if (name == "PRIVATE"_s) { |
41 | 0 | return Visibility::Private; |
42 | 0 | } |
43 | 0 | auto msg = cmStrCat("File set visibility \"", name, "\" is not valid."); |
44 | 0 | if (mf) { |
45 | 0 | mf->IssueMessage(MessageType::FATAL_ERROR, msg); |
46 | 0 | } else { |
47 | 0 | cmSystemTools::Error(msg); |
48 | 0 | } |
49 | 0 | return Visibility::Private; |
50 | 0 | } |
51 | | |
52 | | bool VisibilityIsForSelf(Visibility vis) |
53 | 0 | { |
54 | 0 | switch (vis) { |
55 | 0 | case Visibility::Interface: |
56 | 0 | return false; |
57 | 0 | case Visibility::Public: |
58 | 0 | case Visibility::Private: |
59 | 0 | return true; |
60 | 0 | } |
61 | 0 | return false; |
62 | 0 | } |
63 | | |
64 | | bool VisibilityIsForInterface(Visibility vis) |
65 | 0 | { |
66 | 0 | switch (vis) { |
67 | 0 | case Visibility::Interface: |
68 | 0 | case Visibility::Public: |
69 | 0 | return true; |
70 | 0 | case Visibility::Private: |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | return false; |
74 | 0 | } |
75 | | |
76 | | cm::string_view const HEADERS = "HEADERS"_s; |
77 | | cm::string_view const CXX_MODULES = "CXX_MODULES"_s; |
78 | | |
79 | | namespace { |
80 | | std::vector<cm::string_view> KnownTypes{ HEADERS, CXX_MODULES }; |
81 | | |
82 | | cmsys::RegularExpression const ValidNameRegex("^[a-z0-9][a-zA-Z0-9_]*$"); |
83 | | } |
84 | | |
85 | | std::vector<cm::string_view> const& GetKnownTypes() |
86 | 0 | { |
87 | 0 | return KnownTypes; |
88 | 0 | } |
89 | | |
90 | | bool IsKnownType(cm::string_view type) |
91 | 0 | { |
92 | 0 | return cm::contains(GetKnownTypes(), type); |
93 | 0 | } |
94 | | |
95 | | bool IsValidName(cm::string_view name) |
96 | 0 | { |
97 | 0 | cmsys::RegularExpressionMatch match; |
98 | 0 | return ValidNameRegex.find(name.data(), match); |
99 | 0 | } |
100 | | |
101 | | } |
102 | | } |