cmAddDependenciesCommand.cxx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <sstream>
  5. #include "cmMakefile.h"
  6. #include "cmMessageType.h"
  7. #include "cmRange.h"
  8. #include "cmTarget.h"
  9. class cmExecutionStatus;
  10. // cmDependenciesCommand
  11. bool cmAddDependenciesCommand::InitialPass(
  12. std::vector<std::string> const& args, cmExecutionStatus&)
  13. {
  14. if (args.size() < 2) {
  15. this->SetError("called with incorrect number of arguments");
  16. return false;
  17. }
  18. std::string const& target_name = args[0];
  19. if (this->Makefile->IsAlias(target_name)) {
  20. std::ostringstream e;
  21. e << "Cannot add target-level dependencies to alias target \""
  22. << target_name << "\".\n";
  23. this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  24. }
  25. if (cmTarget* target = this->Makefile->FindTargetToUse(target_name)) {
  26. // skip over target_name
  27. for (std::string const& arg : cmMakeRange(args).advance(1)) {
  28. target->AddUtility(arg, this->Makefile);
  29. }
  30. } else {
  31. std::ostringstream e;
  32. e << "Cannot add target-level dependencies to non-existent target \""
  33. << target_name << "\".\n"
  34. << "The add_dependencies works for top-level logical targets created "
  35. << "by the add_executable, add_library, or add_custom_target commands. "
  36. << "If you want to add file-level dependencies see the DEPENDS option "
  37. << "of the add_custom_target and add_custom_command commands.";
  38. this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  39. }
  40. return true;
  41. }