cmInstallFilesCommand.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 = m_Makefile->GetTargets()[m_TargetName];
  28. target.SetInAll(false);
  29. target.SetType(cmTarget::INSTALL_FILES);
  30. target.SetInstallPath(args[0].c_str());
  31. if((args.size() > 1) && (args[1] == "FILES"))
  32. {
  33. m_IsFilesForm = true;
  34. for(std::vector<std::string>::const_iterator s = args.begin()+2;
  35. s != args.end(); ++s)
  36. {
  37. // Find the source location for each file listed.
  38. std::string f = this->FindInstallSource(s->c_str());
  39. target.GetSourceLists().push_back(f);
  40. }
  41. }
  42. else
  43. {
  44. m_IsFilesForm = false;
  45. std::vector<std::string>::const_iterator s = args.begin();
  46. for (++s;s != args.end(); ++s)
  47. {
  48. m_FinalArgs.push_back(*s);
  49. }
  50. }
  51. return true;
  52. }
  53. void cmInstallFilesCommand::FinalPass()
  54. {
  55. // No final pass for "FILES" form of arguments.
  56. if(m_IsFilesForm)
  57. {
  58. return;
  59. }
  60. std::string testf;
  61. std::string ext = m_FinalArgs[0];
  62. std::vector<std::string>& targetSourceLists =
  63. m_Makefile->GetTargets()[m_TargetName].GetSourceLists();
  64. // two different options
  65. if (m_FinalArgs.size() > 1)
  66. {
  67. // now put the files into the list
  68. std::vector<std::string>::iterator s = m_FinalArgs.begin();
  69. ++s;
  70. // for each argument, get the files
  71. for (;s != m_FinalArgs.end(); ++s)
  72. {
  73. // replace any variables
  74. std::string temps = *s;
  75. if (cmSystemTools::GetFilenamePath(temps).size() > 0)
  76. {
  77. testf = cmSystemTools::GetFilenamePath(temps) + "/" +
  78. cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
  79. }
  80. else
  81. {
  82. testf = cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
  83. }
  84. // add to the result
  85. targetSourceLists.push_back(this->FindInstallSource(testf.c_str()));
  86. }
  87. }
  88. else // reg exp list
  89. {
  90. std::vector<std::string> files;
  91. std::string regex = m_FinalArgs[0].c_str();
  92. cmSystemTools::Glob(m_Makefile->GetCurrentDirectory(),
  93. regex.c_str(), files);
  94. std::vector<std::string>::iterator s = files.begin();
  95. // for each argument, get the files
  96. for (;s != files.end(); ++s)
  97. {
  98. targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
  99. }
  100. }
  101. }
  102. /**
  103. * Find a file in the build or source tree for installation given a
  104. * relative path from the CMakeLists.txt file. This will favor files
  105. * present in the build tree. If a full path is given, it is just
  106. * returned.
  107. */
  108. std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
  109. {
  110. if(cmSystemTools::FileIsFullPath(name))
  111. {
  112. // This is a full path.
  113. return name;
  114. }
  115. // This is a relative path.
  116. std::string tb = m_Makefile->GetCurrentOutputDirectory();
  117. tb += "/";
  118. tb += name;
  119. std::string ts = m_Makefile->GetCurrentDirectory();
  120. ts += "/";
  121. ts += name;
  122. if(cmSystemTools::FileExists(tb.c_str()))
  123. {
  124. // The file exists in the binary tree. Use it.
  125. return tb;
  126. }
  127. else if(cmSystemTools::FileExists(ts.c_str()))
  128. {
  129. // The file exists in the source tree. Use it.
  130. return ts;
  131. }
  132. else
  133. {
  134. // The file doesn't exist. Assume it will be present in the
  135. // binary tree when the install occurs.
  136. return tb;
  137. }
  138. }