cmInstallProgramsCommand.cxx 3.3 KB

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