cmInstallFilesCommand.cxx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "cmInstallFilesCommand.h"
  14. #include "cmCacheManager.h"
  15. // cmExecutableCommand
  16. bool cmInstallFilesCommand::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. m_Makefile->ExpandSourceListArguments(argsIn, args, 2);
  25. // Create an INSTALL_FILES target specifically for this path.
  26. m_TargetName = "INSTALL_FILES_"+args[0];
  27. cmTarget target;
  28. target.SetInAll(false);
  29. target.SetType(cmTarget::INSTALL_FILES);
  30. target.SetInstallPath(args[0].c_str());
  31. m_Makefile->GetTargets().insert(cmTargets::value_type(m_TargetName, target));
  32. std::vector<std::string>::const_iterator s = args.begin();
  33. for (++s;s != args.end(); ++s)
  34. {
  35. m_FinalArgs.push_back(*s);
  36. }
  37. return true;
  38. }
  39. void cmInstallFilesCommand::FinalPass()
  40. {
  41. std::string testf;
  42. std::string ext = m_FinalArgs[0];
  43. std::vector<std::string>& targetSourceLists =
  44. m_Makefile->GetTargets()[m_TargetName].GetSourceLists();
  45. // two different options
  46. if (m_FinalArgs.size() > 1)
  47. {
  48. // now put the files into the list
  49. std::vector<std::string>::iterator s = m_FinalArgs.begin();
  50. ++s;
  51. // for each argument, get the files
  52. for (;s != m_FinalArgs.end(); ++s)
  53. {
  54. // replace any variables
  55. std::string temps = *s;
  56. if (cmSystemTools::GetFilenamePath(temps).size() > 0)
  57. {
  58. testf = cmSystemTools::GetFilenamePath(temps) + "/" +
  59. cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
  60. }
  61. else
  62. {
  63. testf = cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
  64. }
  65. // add to the result
  66. targetSourceLists.push_back(testf);
  67. }
  68. }
  69. else // reg exp list
  70. {
  71. std::vector<std::string> files;
  72. std::string regex = m_FinalArgs[0].c_str();
  73. cmSystemTools::Glob(m_Makefile->GetCurrentDirectory(),
  74. regex.c_str(), files);
  75. std::vector<std::string>::iterator s = files.begin();
  76. // for each argument, get the files
  77. for (;s != files.end(); ++s)
  78. {
  79. targetSourceLists.push_back(*s);
  80. }
  81. }
  82. }