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