/src/CMake/Source/cmLinkItem.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 "cmLinkItem.h" |
4 | | |
5 | | #include <utility> // IWYU pragma: keep |
6 | | |
7 | | #include <cm/optional> |
8 | | #include <cm/string_view> |
9 | | #include <cmext/string_view> |
10 | | |
11 | | #include "cmGeneratorTarget.h" |
12 | | #include "cmStringAlgorithms.h" |
13 | | |
14 | | std::string const cmLinkItem::DEFAULT = "DEFAULT"; |
15 | | |
16 | | cmLinkItem::cmLinkItem(std::string n, bool c, cmListFileBacktrace bt, |
17 | | std::string feature) |
18 | 0 | : String(std::move(n)) |
19 | 0 | , Feature(std::move(feature)) |
20 | 0 | , Cross(c) |
21 | 0 | , Backtrace(std::move(bt)) |
22 | 0 | { |
23 | 0 | } |
24 | | |
25 | | cmLinkItem::cmLinkItem(cmGeneratorTarget const* t, bool c, |
26 | | cmListFileBacktrace bt, std::string feature) |
27 | 0 | : Target(t) |
28 | 0 | , Feature(std::move(feature)) |
29 | 0 | , Cross(c) |
30 | 0 | , Backtrace(std::move(bt)) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | std::string const& cmLinkItem::AsStr() const |
35 | 0 | { |
36 | 0 | return this->Target ? this->Target->GetName() : this->String; |
37 | 0 | } |
38 | | |
39 | | bool operator<(cmLinkItem const& l, cmLinkItem const& r) |
40 | 0 | { |
41 | | // Order among targets. |
42 | 0 | if (l.Target && r.Target) { |
43 | 0 | if (l.Target != r.Target) { |
44 | 0 | return l.Target < r.Target; |
45 | 0 | } |
46 | | // Order identical targets via cross-config. |
47 | 0 | return l.Cross < r.Cross; |
48 | 0 | } |
49 | | // Order targets before strings. |
50 | 0 | if (l.Target) { |
51 | 0 | return true; |
52 | 0 | } |
53 | 0 | if (r.Target) { |
54 | 0 | return false; |
55 | 0 | } |
56 | | // Order among strings. |
57 | 0 | if (l.String != r.String) { |
58 | 0 | return l.String < r.String; |
59 | 0 | } |
60 | | // Order identical strings via cross-config. |
61 | 0 | return l.Cross < r.Cross; |
62 | 0 | } |
63 | | |
64 | | bool operator==(cmLinkItem const& l, cmLinkItem const& r) |
65 | 0 | { |
66 | 0 | return l.Target == r.Target && l.String == r.String && l.Cross == r.Cross; |
67 | 0 | } |
68 | | |
69 | | std::ostream& operator<<(std::ostream& os, cmLinkItem const& item) |
70 | 0 | { |
71 | 0 | return os << item.AsStr(); |
72 | 0 | } |
73 | | |
74 | | namespace { |
75 | | cm::string_view const LL_BEGIN = "<LINK_LIBRARY:"_s; |
76 | | cm::string_view const LL_END = "</LINK_LIBRARY:"_s; |
77 | | } |
78 | | cm::optional<std::string> ParseLinkFeature(std::string const& item) |
79 | 0 | { |
80 | 0 | if (cmHasPrefix(item, LL_BEGIN) && cmHasSuffix(item, '>')) { |
81 | 0 | return item.substr(LL_BEGIN.length(), |
82 | 0 | item.find('>', LL_BEGIN.length()) - LL_BEGIN.length()); |
83 | 0 | } |
84 | 0 | if (cmHasPrefix(item, LL_END) && cmHasSuffix(item, '>')) { |
85 | 0 | return cmLinkItem::DEFAULT; |
86 | 0 | } |
87 | 0 | return cm::nullopt; |
88 | 0 | } |