resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmAddDependenciesCommand.cxx
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"
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 {
15   if (args.size() < 2) {
16     status.SetError("called with incorrect number of arguments");
17     return false;
18   }
19
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"));
27   }
28   if (cmTarget* target = mf.FindTargetToUse(target_name)) {
29
30     // skip over target_name
31     for (std::string const& arg : cmMakeRange(args).advance(1)) {
32       target->AddUtility(arg, false, &mf);
33     }
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."));
46   }
47
48   return true;
49 }