2016-10-30 18:24:19 +01:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-10-12 18:41:06 +02:00
|
|
|
#include "cmAddDependenciesCommand.h"
|
2016-07-09 11:21:54 +02:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
#include "cmExecutionStatus.h"
|
2017-04-14 19:02:05 +02:00
|
|
|
#include "cmMakefile.h"
|
2019-11-11 23:01:05 +01:00
|
|
|
#include "cmMessageType.h"
|
|
|
|
#include "cmRange.h"
|
2020-02-01 23:06:01 +01:00
|
|
|
#include "cmStringAlgorithms.h"
|
2017-04-14 19:02:05 +02:00
|
|
|
#include "cmTarget.h"
|
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
bool cmAddDependenciesCommand(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus& status)
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
2016-07-09 11:21:54 +02:00
|
|
|
if (args.size() < 2) {
|
2020-02-01 23:06:01 +01:00
|
|
|
status.SetError("called with incorrect number of arguments");
|
2008-10-12 18:41:06 +02:00
|
|
|
return false;
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2008-10-12 18:41:06 +02:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
cmMakefile& mf = status.GetMakefile();
|
2017-07-20 19:35:53 +02:00
|
|
|
std::string const& target_name = args[0];
|
2020-02-01 23:06:01 +01:00
|
|
|
if (mf.IsAlias(target_name)) {
|
|
|
|
mf.IssueMessage(
|
|
|
|
MessageType::FATAL_ERROR,
|
|
|
|
cmStrCat("Cannot add target-level dependencies to alias target \"",
|
|
|
|
target_name, "\".\n"));
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2020-02-01 23:06:01 +01:00
|
|
|
if (cmTarget* target = mf.FindTargetToUse(target_name)) {
|
2019-11-11 23:01:05 +01:00
|
|
|
|
|
|
|
// skip over target_name
|
|
|
|
for (std::string const& arg : cmMakeRange(args).advance(1)) {
|
2020-08-30 11:54:41 +02:00
|
|
|
target->AddUtility(arg, false, &mf);
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|
2016-07-09 11:21:54 +02:00
|
|
|
} else {
|
2020-02-01 23:06:01 +01:00
|
|
|
mf.IssueMessage(
|
|
|
|
MessageType::FATAL_ERROR,
|
|
|
|
cmStrCat(
|
|
|
|
"Cannot add target-level dependencies to non-existent "
|
|
|
|
"target \"",
|
|
|
|
target_name,
|
|
|
|
"\".\nThe add_dependencies works for "
|
|
|
|
"top-level logical targets created by the add_executable, "
|
|
|
|
"add_library, or add_custom_target commands. If you want to add "
|
|
|
|
"file-level dependencies see the DEPENDS option of the "
|
|
|
|
"add_custom_target and add_custom_command commands."));
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2008-10-12 18:41:06 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|