cmAddDependenciesCommand.cxx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 "cmTarget.h"
  7. #include "cmake.h"
  8. class cmExecutionStatus;
  9. // cmDependenciesCommand
  10. bool cmAddDependenciesCommand::InitialPass(
  11. std::vector<std::string> const& args, cmExecutionStatus&)
  12. {
  13. if (args.size() < 2) {
  14. this->SetError("called with incorrect number of arguments");
  15. return false;
  16. }
  17. std::string const& target_name = args[0];
  18. if (this->Makefile->IsAlias(target_name)) {
  19. std::ostringstream e;
  20. e << "Cannot add target-level dependencies to alias target \""
  21. << target_name << "\".\n";
  22. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  23. }
  24. if (cmTarget* target = this->Makefile->FindTargetToUse(target_name)) {
  25. std::vector<std::string>::const_iterator s = args.begin();
  26. ++s; // skip over target_name
  27. for (; s != args.end(); ++s) {
  28. target->AddUtility(*s, 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(cmake::FATAL_ERROR, e.str());
  39. }
  40. return true;
  41. }