cmAddDependenciesCommand.cxx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmAddDependenciesCommand.h"
  11. #include "cmLocalGenerator.h"
  12. #include "cmGlobalGenerator.h"
  13. // cmDependenciesCommand
  14. bool cmAddDependenciesCommand
  15. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  16. {
  17. if(args.size() < 2 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. std::string target_name = args[0];
  23. if(this->Makefile->IsAlias(target_name.c_str()))
  24. {
  25. cmOStringStream e;
  26. e << "Cannot add target-level dependencies to alias target \""
  27. << target_name << "\".\n";
  28. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  29. }
  30. if(cmTarget* target = this->Makefile->FindTargetToUse(target_name.c_str()))
  31. {
  32. if (target->GetType() == cmTarget::INTERFACE_LIBRARY)
  33. {
  34. cmOStringStream e;
  35. e << "Cannot add target-level dependencies to INTERFACE library "
  36. "target \"" << target_name << "\".\n";
  37. this->SetError(e.str().c_str());
  38. return false;
  39. }
  40. std::vector<std::string>::const_iterator s = args.begin();
  41. ++s; // skip over target_name
  42. for (; s != args.end(); ++s)
  43. {
  44. target->AddUtility(s->c_str());
  45. }
  46. }
  47. else
  48. {
  49. cmOStringStream e;
  50. e << "Cannot add target-level dependencies to non-existent target \""
  51. << target_name << "\".\n"
  52. << "The add_dependencies works for top-level logical targets created "
  53. << "by the add_executable, add_library, or add_custom_target commands. "
  54. << "If you want to add file-level dependencies see the DEPENDS option "
  55. << "of the add_custom_target and add_custom_command commands.";
  56. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  57. }
  58. return true;
  59. }