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"
9 #include "cmStringAlgorithms.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");
20 cmMakefile
& mf
= status
.GetMakefile();
21 std::string
const& target_name
= args
[0];
22 if (mf
.IsAlias(target_name
)) {
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
);
36 MessageType::FATAL_ERROR
,
38 "Cannot add target-level dependencies to non-existent "
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."));