Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmAddDependenciesCommand.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 "cmAddDependenciesCommand.h"
4
5
#include "cmExecutionStatus.h"
6
#include "cmMakefile.h"
7
#include "cmMessageType.h"
8
#include "cmRange.h"
9
#include "cmStringAlgorithms.h"
10
#include "cmTarget.h"
11
12
bool cmAddDependenciesCommand(std::vector<std::string> const& args,
13
                              cmExecutionStatus& status)
14
0
{
15
0
  if (args.empty()) {
16
0
    status.SetError("called with incorrect number of arguments");
17
0
    return false;
18
0
  }
19
20
0
  cmMakefile& mf = status.GetMakefile();
21
0
  std::string const& target_name = args[0];
22
0
  if (mf.IsAlias(target_name)) {
23
0
    mf.IssueMessage(
24
0
      MessageType::FATAL_ERROR,
25
0
      cmStrCat("Cannot add target-level dependencies to alias target \"",
26
0
               target_name, "\".\n"));
27
0
  }
28
0
  if (cmTarget* target = mf.FindTargetToUse(target_name)) {
29
30
    // skip over target_name
31
0
    for (std::string const& arg : cmMakeRange(args).advance(1)) {
32
0
      target->AddUtility(arg, false, &mf);
33
0
      target->AddCodegenDependency(arg);
34
0
    }
35
0
  } else {
36
0
    mf.IssueMessage(
37
0
      MessageType::FATAL_ERROR,
38
0
      cmStrCat(
39
0
        "Cannot add target-level dependencies to non-existent "
40
0
        "target \"",
41
0
        target_name,
42
0
        "\".\nThe add_dependencies works for "
43
0
        "top-level logical targets created by the add_executable, "
44
0
        "add_library, or add_custom_target commands.  If you want to add "
45
0
        "file-level dependencies see the DEPENDS option of the "
46
0
        "add_custom_target and add_custom_command commands."));
47
0
  }
48
49
0
  return true;
50
0
}