cmInstallTargetsCommand.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "cmInstallTargetsCommand.h"
  4. #include <unordered_map>
  5. #include <utility>
  6. #include "cmGlobalGenerator.h"
  7. #include "cmMakefile.h"
  8. #include "cmTarget.h"
  9. class cmExecutionStatus;
  10. // cmExecutableCommand
  11. bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args,
  12. cmExecutionStatus&)
  13. {
  14. if (args.size() < 2) {
  15. this->SetError("called with incorrect number of arguments");
  16. return false;
  17. }
  18. // Enable the install target.
  19. this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
  20. cmTargets& tgts = this->Makefile->GetTargets();
  21. std::vector<std::string>::const_iterator s = args.begin();
  22. ++s;
  23. std::string runtime_dir = "/bin";
  24. for (; s != args.end(); ++s) {
  25. if (*s == "RUNTIME_DIRECTORY") {
  26. ++s;
  27. if (s == args.end()) {
  28. this->SetError("called with RUNTIME_DIRECTORY but no actual "
  29. "directory");
  30. return false;
  31. }
  32. runtime_dir = *s;
  33. } else {
  34. cmTargets::iterator ti = tgts.find(*s);
  35. if (ti != tgts.end()) {
  36. ti->second.SetInstallPath(args[0].c_str());
  37. ti->second.SetRuntimeInstallPath(runtime_dir.c_str());
  38. ti->second.SetHaveInstallRule(true);
  39. } else {
  40. std::string str = "Cannot find target: \"" + *s + "\" to install.";
  41. this->SetError(str);
  42. return false;
  43. }
  44. }
  45. }
  46. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  47. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
  48. return true;
  49. }