cmake/Source/cmAddDependenciesCommand.cxx

48 lines
1.6 KiB
C++
Raw Normal View History

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. */
#include "cmAddDependenciesCommand.h"
2016-07-09 11:21:54 +02:00
2017-04-14 19:02:05 +02:00
#include <sstream>
#include "cmMakefile.h"
#include "cmTarget.h"
#include "cmake.h"
class cmExecutionStatus;
// cmDependenciesCommand
2016-07-09 11:21:54 +02:00
bool cmAddDependenciesCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
this->SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
std::string const& target_name = args[0];
2016-07-09 11:21:54 +02:00
if (this->Makefile->IsAlias(target_name)) {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2013-11-03 12:27:13 +02:00
e << "Cannot add target-level dependencies to alias target \""
<< target_name << "\".\n";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
2016-07-09 11:21:54 +02:00
}
if (cmTarget* target = this->Makefile->FindTargetToUse(target_name)) {
std::vector<std::string>::const_iterator s = args.begin();
++s; // skip over target_name
2016-07-09 11:21:54 +02:00
for (; s != args.end(); ++s) {
2015-04-27 22:25:09 +02:00
target->AddUtility(*s, this->Makefile);
}
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2013-04-21 10:33:41 +03:00
e << "Cannot add target-level dependencies to non-existent target \""
<< target_name << "\".\n"
<< "The 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.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
2016-07-09 11:21:54 +02:00
}
return true;
}