cmInstallProgramsCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. #include "cmCacheManager.h"
  15. // cmExecutableCommand
  16. bool cmInstallProgramsCommand::InitialPass(std::vector<std::string> const& argsIn)
  17. {
  18. if(argsIn.size() < 2)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::vector<std::string> args;
  24. cmSystemTools::ExpandListArguments(argsIn, args);
  25. // Create an INSTALL_PROGRAMS target specifically for this path.
  26. m_TargetName = "INSTALL_PROGRAMS_"+args[0];
  27. cmTarget& target = m_Makefile->GetTargets()[m_TargetName];
  28. target.SetInAll(false);
  29. target.SetType(cmTarget::INSTALL_PROGRAMS);
  30. target.SetInstallPath(args[0].c_str());
  31. std::vector<std::string>::const_iterator s = args.begin();
  32. for (++s;s != args.end(); ++s)
  33. {
  34. m_FinalArgs.push_back(*s);
  35. }
  36. return true;
  37. }
  38. void cmInstallProgramsCommand::FinalPass()
  39. {
  40. std::vector<std::string>& targetSourceLists =
  41. m_Makefile->GetTargets()[m_TargetName].GetSourceLists();
  42. // two different options
  43. if (m_FinalArgs.size() > 1)
  44. {
  45. // for each argument, get the programs
  46. for (std::vector<std::string>::iterator s = m_FinalArgs.begin();
  47. s != m_FinalArgs.end(); ++s)
  48. {
  49. // add to the result
  50. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  51. }
  52. }
  53. else // reg exp list
  54. {
  55. std::vector<std::string> programs;
  56. cmSystemTools::Glob(m_Makefile->GetCurrentDirectory(),
  57. m_FinalArgs[0].c_str(), programs);
  58. std::vector<std::string>::iterator s = programs.begin();
  59. // for each argument, get the programs
  60. for (;s != programs.end(); ++s)
  61. {
  62. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  63. }
  64. }
  65. }
  66. /**
  67. * Find a file in the build or source tree for installation given a
  68. * relative path from the CMakeLists.txt file. This will favor files
  69. * present in the build tree. If a full path is given, it is just
  70. * returned.
  71. */
  72. std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const
  73. {
  74. if(cmSystemTools::FileIsFullPath(name))
  75. {
  76. // This is a full path.
  77. return name;
  78. }
  79. // This is a relative path.
  80. std::string tb = m_Makefile->GetCurrentOutputDirectory();
  81. tb += "/";
  82. tb += name;
  83. std::string ts = m_Makefile->GetCurrentDirectory();
  84. ts += "/";
  85. ts += name;
  86. if(cmSystemTools::FileExists(tb.c_str()))
  87. {
  88. // The file exists in the binary tree. Use it.
  89. return tb;
  90. }
  91. else if(cmSystemTools::FileExists(ts.c_str()))
  92. {
  93. // The file exists in the source tree. Use it.
  94. return ts;
  95. }
  96. else
  97. {
  98. // The file doesn't exist. Assume it will be present in the
  99. // binary tree when the install occurs.
  100. return tb;
  101. }
  102. }