1
0

cmAddDependenciesCommand.cxx 1.6 KB

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