cmInstallProgramsCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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
  16. ::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 2)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // Create an INSTALL_PROGRAMS target specifically for this path.
  24. this->TargetName = "INSTALL_PROGRAMS_"+args[0];
  25. cmTarget& target = this->Makefile->GetTargets()[this->TargetName];
  26. target.SetInAll(false);
  27. target.SetType(cmTarget::INSTALL_PROGRAMS, this->TargetName.c_str());
  28. target.SetInstallPath(args[0].c_str());
  29. std::vector<std::string>::const_iterator s = args.begin();
  30. for (++s;s != args.end(); ++s)
  31. {
  32. this->FinalArgs.push_back(*s);
  33. }
  34. return true;
  35. }
  36. void cmInstallProgramsCommand::FinalPass()
  37. {
  38. std::vector<std::string>& targetSourceLists =
  39. this->Makefile->GetTargets()[this->TargetName].GetSourceLists();
  40. bool files_mode = false;
  41. if(!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES")
  42. {
  43. files_mode = true;
  44. }
  45. // two different options
  46. if (this->FinalArgs.size() > 1 || files_mode)
  47. {
  48. // for each argument, get the programs
  49. std::vector<std::string>::iterator s = this->FinalArgs.begin();
  50. if(files_mode)
  51. {
  52. // Skip the FILES argument in files mode.
  53. ++s;
  54. }
  55. for(;s != this->FinalArgs.end(); ++s)
  56. {
  57. // add to the result
  58. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  59. }
  60. }
  61. else // reg exp list
  62. {
  63. std::vector<std::string> programs;
  64. cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
  65. this->FinalArgs[0].c_str(), programs);
  66. std::vector<std::string>::iterator s = programs.begin();
  67. // for each argument, get the programs
  68. for (;s != programs.end(); ++s)
  69. {
  70. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  71. }
  72. }
  73. }
  74. /**
  75. * Find a file in the build or source tree for installation given a
  76. * relative path from the CMakeLists.txt file. This will favor files
  77. * present in the build tree. If a full path is given, it is just
  78. * returned.
  79. */
  80. std::string cmInstallProgramsCommand
  81. ::FindInstallSource(const char* name) const
  82. {
  83. if(cmSystemTools::FileIsFullPath(name))
  84. {
  85. // This is a full path.
  86. return name;
  87. }
  88. // This is a relative path.
  89. std::string tb = this->Makefile->GetCurrentOutputDirectory();
  90. tb += "/";
  91. tb += name;
  92. std::string ts = this->Makefile->GetCurrentDirectory();
  93. ts += "/";
  94. ts += name;
  95. if(cmSystemTools::FileExists(tb.c_str()))
  96. {
  97. // The file exists in the binary tree. Use it.
  98. return tb;
  99. }
  100. else if(cmSystemTools::FileExists(ts.c_str()))
  101. {
  102. // The file exists in the source tree. Use it.
  103. return ts;
  104. }
  105. else
  106. {
  107. // The file doesn't exist. Assume it will be present in the
  108. // binary tree when the install occurs.
  109. return tb;
  110. }
  111. }