Coverage Report

Created: 2026-09-14 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmTargetPropertyComputer.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 "cmConfigure.h" // IWYU pragma: keep
6
7
#include <string>
8
#include <utility>
9
10
#include "cmStringAlgorithms.h"
11
#include "cmTargetTypes.h"
12
#include "cmValue.h"
13
14
class cmMakefile;
15
16
class cmTargetPropertyComputer
17
{
18
public:
19
  template <typename Target>
20
  static cmValue GetProperty(Target const* tgt, std::string const& prop,
21
                             cmMakefile const& mf)
22
0
  {
23
0
    if (cmValue loc = GetLocation(tgt, prop, mf)) {
24
0
      return loc;
25
0
    }
26
0
    if (prop == "SOURCES") {
27
0
      return GetSources(tgt);
28
0
    }
29
0
    return nullptr;
30
0
  }
Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetProperty<cmGeneratorTarget>(cmGeneratorTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&)
Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetProperty<cmTarget>(cmTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&)
31
32
  // True if `prop` is a *computed* location property for `type` -- i.e. one of
33
  // LOCATION, LOCATION_<CONFIG>, or <CONFIG>_LOCATION on a target type that
34
  // synthesizes a location.  Reading one of these from a non-imported target
35
  // is an error.  Excludes IMPORTED_LOCATION and XCODE_ATTRIBUTE_*.  If
36
  // non-null, `config` is filled with the requested configuration ("" for
37
  // plain LOCATION).
38
  static bool IsComputedLocationProperty(cm::TargetType type,
39
                                         std::string const& prop,
40
                                         std::string* config = nullptr)
41
0
  {
42
0
    switch (type) {
43
0
      case cm::TargetType::EXECUTABLE:
44
0
      case cm::TargetType::STATIC_LIBRARY:
45
0
      case cm::TargetType::SHARED_LIBRARY:
46
0
      case cm::TargetType::MODULE_LIBRARY:
47
0
      case cm::TargetType::UNKNOWN_LIBRARY:
48
0
        break;
49
0
      default:
50
0
        return false;
51
0
    }
52
0
    if (prop == "LOCATION") {
53
0
      if (config) {
54
0
        config->clear();
55
0
      }
56
0
      return true;
57
0
    }
58
0
    if (cmHasLiteralPrefix(prop, "LOCATION_")) {
59
0
      if (config) {
60
0
        *config = prop.substr(9);
61
0
      }
62
0
      return true;
63
0
    }
64
0
    if (cmHasLiteralSuffix(prop, "_LOCATION") &&
65
0
        !cmHasLiteralPrefix(prop, "XCODE_ATTRIBUTE_")) {
66
0
      std::string c(prop.c_str(), prop.size() - 9);
67
0
      if (c != "IMPORTED") {
68
0
        if (config) {
69
0
          *config = std::move(c);
70
0
        }
71
0
        return true;
72
0
      }
73
0
    }
74
0
    return false;
75
0
  }
76
77
private:
78
  static void IssueLocationPropertyError(std::string const& tgtName,
79
                                         cmMakefile const& mf);
80
81
  template <typename Target>
82
  static std::string const& ImportedLocation(Target const* tgt,
83
                                             std::string const& config);
84
85
  template <typename Target>
86
  static cmValue GetLocation(Target const* tgt, std::string const& prop,
87
                             cmMakefile const& mf)
88
0
  {
89
    // Watch for special "computed" properties that are dependent on
90
    // other properties or variables.  Always recompute them.
91
0
    std::string config;
92
0
    if (!IsComputedLocationProperty(tgt->GetType(), prop, &config)) {
93
0
      return nullptr;
94
0
    }
95
0
    if (!tgt->IsImported()) {
96
0
      IssueLocationPropertyError(tgt->GetName(), mf);
97
0
      return nullptr;
98
0
    }
99
0
    return cmValue(ImportedLocation(tgt, config));
100
0
  }
Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetLocation<cmGeneratorTarget>(cmGeneratorTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&)
Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetLocation<cmTarget>(cmTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&)
101
102
  template <typename Target>
103
  static cmValue GetSources(Target const* tgt);
104
};