cmInstallProgramsCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmInstallProgramsCommand.h"
  14. // cmExecutableCommand
  15. bool cmInstallProgramsCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 2)
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // Create an INSTALL_PROGRAMS target specifically for this path.
  23. this->TargetName = "INSTALL_PROGRAMS_"+args[0];
  24. cmTarget& target = this->Makefile->GetTargets()[this->TargetName];
  25. target.SetInAll(false);
  26. target.SetType(cmTarget::INSTALL_PROGRAMS, this->TargetName.c_str());
  27. target.SetInstallPath(args[0].c_str());
  28. std::vector<std::string>::const_iterator s = args.begin();
  29. for (++s;s != args.end(); ++s)
  30. {
  31. this->FinalArgs.push_back(*s);
  32. }
  33. return true;
  34. }
  35. void cmInstallProgramsCommand::FinalPass()
  36. {
  37. std::vector<std::string>& targetSourceLists =
  38. this->Makefile->GetTargets()[this->TargetName].GetSourceLists();
  39. bool files_mode = false;
  40. if(!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES")
  41. {
  42. files_mode = true;
  43. }
  44. // two different options
  45. if (this->FinalArgs.size() > 1 || files_mode)
  46. {
  47. // for each argument, get the programs
  48. std::vector<std::string>::iterator s = this->FinalArgs.begin();
  49. if(files_mode)
  50. {
  51. // Skip the FILES argument in files mode.
  52. ++s;
  53. }
  54. for(;s != this->FinalArgs.end(); ++s)
  55. {
  56. // add to the result
  57. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  58. }
  59. }
  60. else // reg exp list
  61. {
  62. std::vector<std::string> programs;
  63. cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
  64. this->FinalArgs[0].c_str(), programs);
  65. std::vector<std::string>::iterator s = programs.begin();
  66. // for each argument, get the programs
  67. for (;s != programs.end(); ++s)
  68. {
  69. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  70. }
  71. }
  72. }
  73. /**
  74. * Find a file in the build or source tree for installation given a
  75. * relative path from the CMakeLists.txt file. This will favor files
  76. * present in the build tree. If a full path is given, it is just
  77. * returned.
  78. */
  79. std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const
  80. {
  81. if(cmSystemTools::FileIsFullPath(name))
  82. {
  83. // This is a full path.
  84. return name;
  85. }
  86. // This is a relative path.
  87. std::string tb = this->Makefile->GetCurrentOutputDirectory();
  88. tb += "/";
  89. tb += name;
  90. std::string ts = this->Makefile->GetCurrentDirectory();
  91. ts += "/";
  92. ts += name;
  93. if(cmSystemTools::FileExists(tb.c_str()))
  94. {
  95. // The file exists in the binary tree. Use it.
  96. return tb;
  97. }
  98. else if(cmSystemTools::FileExists(ts.c_str()))
  99. {
  100. // The file exists in the source tree. Use it.
  101. return ts;
  102. }
  103. else
  104. {
  105. // The file doesn't exist. Assume it will be present in the
  106. // binary tree when the install occurs.
  107. return tb;
  108. }
  109. }