Coverage Report

Created: 2026-09-14 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmGetDirectoryPropertyCommand.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 "cmGetDirectoryPropertyCommand.h"
4
5
#include "cmDirectoryPropertyHelper.h"
6
#include "cmExecutionStatus.h"
7
#include "cmMakefile.h"
8
#include "cmValue.h"
9
10
// cmGetDirectoryPropertyCommand
11
bool cmGetDirectoryPropertyCommand(std::vector<std::string> const& args,
12
                                   cmExecutionStatus& status)
13
0
{
14
0
  if (args.size() < 2) {
15
0
    status.SetError("called with incorrect number of arguments");
16
0
    return false;
17
0
  }
18
19
0
  auto i = args.begin();
20
0
  std::string const& variable = *i;
21
0
  ++i;
22
23
  // Get the directory argument if there is one.
24
0
  cmMakefile* mf = &status.GetMakefile();
25
0
  if (*i == "DIRECTORY") {
26
0
    ++i;
27
0
    if (i == args.end()) {
28
0
      status.SetError(
29
0
        "DIRECTORY argument provided without subsequent arguments");
30
0
      return false;
31
0
    }
32
0
    mf = cmResolveDirectoryMakefile(status.GetMakefile(), *i);
33
0
    if (!mf) {
34
0
      status.SetError(
35
0
        "DIRECTORY argument provided but requested directory not found. "
36
0
        "This could be because the directory argument was invalid or, "
37
0
        "it is valid but has not been processed yet.");
38
0
      return false;
39
0
    }
40
0
    ++i;
41
0
    if (i == args.end()) {
42
0
      status.SetError("called with incorrect number of arguments");
43
0
      return false;
44
0
    }
45
0
  }
46
47
0
  if (*i == "DEFINITION") {
48
0
    ++i;
49
0
    if (i == args.end()) {
50
0
      status.SetError("A request for a variable definition was made without "
51
0
                      "providing the name of the variable to get.");
52
0
      return false;
53
0
    }
54
0
    status.GetMakefile().AddDefinition(variable, mf->GetSafeDefinition(*i));
55
0
    return true;
56
0
  }
57
58
0
  if (i->empty()) {
59
0
    status.SetError("given empty string for the property name to get");
60
0
    return false;
61
0
  }
62
63
0
  cmValue prop;
64
0
  auto result = cmGetDirectoryProperty(*mf, *i, prop);
65
0
  if (result == cmGetDirectoryPropertyResult::Success) {
66
0
    status.GetMakefile().AddDefinition(variable, prop);
67
0
    return true;
68
0
  }
69
0
  status.SetError("unknown error retrieving directory property");
70
0
  return false;
71
0
}