cmInstallProgramsCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #include "cmInstallFilesGenerator.h"
  15. // cmExecutableCommand
  16. bool cmInstallProgramsCommand
  17. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  18. {
  19. if(args.size() < 2)
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. // Enable the install target.
  25. this->Makefile->GetLocalGenerator()
  26. ->GetGlobalGenerator()->EnableInstallTarget();
  27. this->Destination = args[0];
  28. std::vector<std::string>::const_iterator s = args.begin();
  29. for (++s;s != args.end(); ++s)
  30. {
  31. this->FinalArgs.push_back(*s);
  32. }
  33. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  34. ->AddInstallComponent("Unspecified");
  35. return true;
  36. }
  37. void cmInstallProgramsCommand::FinalPass()
  38. {
  39. bool files_mode = false;
  40. if(!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES")
  41. {
  42. files_mode = true;
  43. }
  44. // two different options
  45. if (this->FinalArgs.size() > 1 || files_mode)
  46. {
  47. // for each argument, get the programs
  48. std::vector<std::string>::iterator s = this->FinalArgs.begin();
  49. if(files_mode)
  50. {
  51. // Skip the FILES argument in files mode.
  52. ++s;
  53. }
  54. for(;s != this->FinalArgs.end(); ++s)
  55. {
  56. // add to the result
  57. this->Files.push_back(this->FindInstallSource(s->c_str()));
  58. }
  59. }
  60. else // reg exp list
  61. {
  62. std::vector<std::string> programs;
  63. cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
  64. this->FinalArgs[0].c_str(), programs);
  65. std::vector<std::string>::iterator s = programs.begin();
  66. // for each argument, get the programs
  67. for (;s != programs.end(); ++s)
  68. {
  69. this->Files.push_back(this->FindInstallSource(s->c_str()));
  70. }
  71. }
  72. // Construct the destination. This command always installs under
  73. // the prefix. We skip the leading slash given by the user.
  74. std::string destination = this->Destination.substr(1);
  75. cmSystemTools::ConvertToUnixSlashes(destination);
  76. if(destination.empty())
  77. {
  78. destination = ".";
  79. }
  80. // Use a file install generator.
  81. const char* no_permissions = "";
  82. const char* no_rename = "";
  83. const char* no_component = "Unspecified";
  84. std::vector<std::string> no_configurations;
  85. this->Makefile->AddInstallGenerator(
  86. new cmInstallFilesGenerator(this->Files,
  87. destination.c_str(), true,
  88. no_permissions, no_configurations,
  89. no_component, no_rename));
  90. }
  91. /**
  92. * Find a file in the build or source tree for installation given a
  93. * relative path from the CMakeLists.txt file. This will favor files
  94. * present in the build tree. If a full path is given, it is just
  95. * returned.
  96. */
  97. std::string cmInstallProgramsCommand
  98. ::FindInstallSource(const char* name) const
  99. {
  100. if(cmSystemTools::FileIsFullPath(name))
  101. {
  102. // This is a full path.
  103. return name;
  104. }
  105. // This is a relative path.
  106. std::string tb = this->Makefile->GetCurrentOutputDirectory();
  107. tb += "/";
  108. tb += name;
  109. std::string ts = this->Makefile->GetCurrentDirectory();
  110. ts += "/";
  111. ts += name;
  112. if(cmSystemTools::FileExists(tb.c_str()))
  113. {
  114. // The file exists in the binary tree. Use it.
  115. return tb;
  116. }
  117. else if(cmSystemTools::FileExists(ts.c_str()))
  118. {
  119. // The file exists in the source tree. Use it.
  120. return ts;
  121. }
  122. else
  123. {
  124. // The file doesn't exist. Assume it will be present in the
  125. // binary tree when the install occurs.
  126. return tb;
  127. }
  128. }