1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmLinkItem.h"
5 #include <utility> // IWYU pragma: keep
8 #include <cm/string_view>
9 #include <cmext/string_view>
11 #include "cmGeneratorTarget.h"
12 #include "cmStringAlgorithms.h"
14 const std::string
cmLinkItem::DEFAULT
= "DEFAULT";
16 cmLinkItem::cmLinkItem() = default;
18 cmLinkItem::cmLinkItem(std::string n
, bool c
, cmListFileBacktrace bt
,
20 : String(std::move(n
))
21 , Feature(std::move(feature
))
23 , Backtrace(std::move(bt
))
27 cmLinkItem::cmLinkItem(cmGeneratorTarget
const* t
, bool c
,
28 cmListFileBacktrace bt
, std::string feature
)
30 , Feature(std::move(feature
))
32 , Backtrace(std::move(bt
))
36 std::string
const& cmLinkItem::AsStr() const
38 return this->Target
? this->Target
->GetName() : this->String
;
41 bool operator<(cmLinkItem
const& l
, cmLinkItem
const& r
)
43 // Order among targets.
44 if (l
.Target
&& r
.Target
) {
45 if (l
.Target
!= r
.Target
) {
46 return l
.Target
< r
.Target
;
48 // Order identical targets via cross-config.
49 return l
.Cross
< r
.Cross
;
51 // Order targets before strings.
58 // Order among strings.
59 if (l
.String
!= r
.String
) {
60 return l
.String
< r
.String
;
62 // Order identical strings via cross-config.
63 return l
.Cross
< r
.Cross
;
66 bool operator==(cmLinkItem
const& l
, cmLinkItem
const& r
)
68 return l
.Target
== r
.Target
&& l
.String
== r
.String
&& l
.Cross
== r
.Cross
;
71 std::ostream
& operator<<(std::ostream
& os
, cmLinkItem
const& item
)
73 return os
<< item
.AsStr();
76 cmLinkImplItem::cmLinkImplItem()
81 cmLinkImplItem::cmLinkImplItem(cmLinkItem item
, bool checkCMP0027
)
82 : cmLinkItem(std::move(item
))
83 , CheckCMP0027(checkCMP0027
)
88 const cm::string_view LL_BEGIN
= "<LINK_LIBRARY:"_s
;
89 const cm::string_view LL_END
= "</LINK_LIBRARY:"_s
;
91 cm::optional
<std::string
> ParseLinkFeature(std::string
const& item
)
93 if (cmHasPrefix(item
, LL_BEGIN
) && cmHasSuffix(item
, '>')) {
94 return item
.substr(LL_BEGIN
.length(),
95 item
.find('>', LL_BEGIN
.length()) - LL_BEGIN
.length());
97 if (cmHasPrefix(item
, LL_END
) && cmHasSuffix(item
, '>')) {
98 return cmLinkItem::DEFAULT
;