Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
134k
  : String(std::move(n))
19
134k
  , Feature(std::move(feature))
20
134k
  , Cross(c)
21
134k
  , Backtrace(std::move(bt))
22
134k
{
23
134k
}
24
25
cmLinkItem::cmLinkItem(cmGeneratorTarget const* t, bool c,
26
                       cmListFileBacktrace bt, std::string feature)
27
19.2k
  : Target(t)
28
19.2k
  , Feature(std::move(feature))
29
19.2k
  , Cross(c)
30
19.2k
  , Backtrace(std::move(bt))
31
19.2k
{
32
19.2k
}
33
34
std::string const& cmLinkItem::AsStr() const
35
139k
{
36
139k
  return this->Target ? this->Target->GetName() : this->String;
37
139k
}
38
39
bool operator<(cmLinkItem const& l, cmLinkItem const& r)
40
523k
{
41
  // Order among targets.
42
523k
  if (l.Target && r.Target) {
43
13.5k
    if (l.Target != r.Target) {
44
7.96k
      return l.Target < r.Target;
45
7.96k
    }
46
    // Order identical targets via cross-config.
47
5.56k
    return l.Cross < r.Cross;
48
13.5k
  }
49
  // Order targets before strings.
50
509k
  if (l.Target) {
51
5.31k
    return true;
52
5.31k
  }
53
504k
  if (r.Target) {
54
4.96k
    return false;
55
4.96k
  }
56
  // Order among strings.
57
499k
  if (l.String != r.String) {
58
337k
    return l.String < r.String;
59
337k
  }
60
  // Order identical strings via cross-config.
61
161k
  return l.Cross < r.Cross;
62
499k
}
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
164k
{
80
164k
  if (cmHasPrefix(item, LL_BEGIN) && cmHasSuffix(item, '>')) {
81
1.47k
    return item.substr(LL_BEGIN.length(),
82
1.47k
                       item.find('>', LL_BEGIN.length()) - LL_BEGIN.length());
83
1.47k
  }
84
163k
  if (cmHasPrefix(item, LL_END) && cmHasSuffix(item, '>')) {
85
1.16k
    return cmLinkItem::DEFAULT;
86
1.16k
  }
87
162k
  return cm::nullopt;
88
163k
}