cmInstallProgramsCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. m_TargetName = "INSTALL_PROGRAMS_"+args[0];
  24. cmTarget& target = m_Makefile->GetTargets()[m_TargetName];
  25. target.SetInAll(false);
  26. target.SetType(cmTarget::INSTALL_PROGRAMS, m_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. m_FinalArgs.push_back(*s);
  32. }
  33. return true;
  34. }
  35. void cmInstallProgramsCommand::FinalPass()
  36. {
  37. std::vector<std::string>& targetSourceLists =
  38. m_Makefile->GetTargets()[m_TargetName].GetSourceLists();
  39. // two different options
  40. if (m_FinalArgs.size() > 1)
  41. {
  42. // for each argument, get the programs
  43. for (std::vector<std::string>::iterator s = m_FinalArgs.begin();
  44. s != m_FinalArgs.end(); ++s)
  45. {
  46. // add to the result
  47. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  48. }
  49. }
  50. else // reg exp list
  51. {
  52. std::vector<std::string> programs;
  53. cmSystemTools::Glob(m_Makefile->GetCurrentDirectory(),
  54. m_FinalArgs[0].c_str(), programs);
  55. std::vector<std::string>::iterator s = programs.begin();
  56. // for each argument, get the programs
  57. for (;s != programs.end(); ++s)
  58. {
  59. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  60. }
  61. }
  62. }
  63. /**
  64. * Find a file in the build or source tree for installation given a
  65. * relative path from the CMakeLists.txt file. This will favor files
  66. * present in the build tree. If a full path is given, it is just
  67. * returned.
  68. */
  69. std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const
  70. {
  71. if(cmSystemTools::FileIsFullPath(name))
  72. {
  73. // This is a full path.
  74. return name;
  75. }
  76. // This is a relative path.
  77. std::string tb = m_Makefile->GetCurrentOutputDirectory();
  78. tb += "/";
  79. tb += name;
  80. std::string ts = m_Makefile->GetCurrentDirectory();
  81. ts += "/";
  82. ts += name;
  83. if(cmSystemTools::FileExists(tb.c_str()))
  84. {
  85. // The file exists in the binary tree. Use it.
  86. return tb;
  87. }
  88. else if(cmSystemTools::FileExists(ts.c_str()))
  89. {
  90. // The file exists in the source tree. Use it.
  91. return ts;
  92. }
  93. else
  94. {
  95. // The file doesn't exist. Assume it will be present in the
  96. // binary tree when the install occurs.
  97. return tb;
  98. }
  99. }