cmInstallProgramsCommand.cxx 3.7 KB

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