cmInstallProgramsCommand.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmInstallProgramsCommand.h"
  11. #include "cmInstallFilesGenerator.h"
  12. // cmExecutableCommand
  13. bool cmInstallProgramsCommand::InitialPass(
  14. std::vector<std::string> const& args, cmExecutionStatus&)
  15. {
  16. if (args.size() < 2) {
  17. this->SetError("called with incorrect number of arguments");
  18. return false;
  19. }
  20. // Enable the install target.
  21. this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
  22. this->Destination = args[0];
  23. this->FinalArgs.insert(this->FinalArgs.end(), args.begin() + 1, args.end());
  24. this->Makefile->GetGlobalGenerator()->AddInstallComponent(
  25. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
  26. return true;
  27. }
  28. void cmInstallProgramsCommand::FinalPass()
  29. {
  30. bool files_mode = false;
  31. if (!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES") {
  32. files_mode = true;
  33. }
  34. // two different options
  35. if (this->FinalArgs.size() > 1 || files_mode) {
  36. // for each argument, get the programs
  37. std::vector<std::string>::iterator s = this->FinalArgs.begin();
  38. if (files_mode) {
  39. // Skip the FILES argument in files mode.
  40. ++s;
  41. }
  42. for (; s != this->FinalArgs.end(); ++s) {
  43. // add to the result
  44. this->Files.push_back(this->FindInstallSource(s->c_str()));
  45. }
  46. } else // reg exp list
  47. {
  48. std::vector<std::string> programs;
  49. cmSystemTools::Glob(this->Makefile->GetCurrentSourceDirectory(),
  50. this->FinalArgs[0], programs);
  51. std::vector<std::string>::iterator s = programs.begin();
  52. // for each argument, get the programs
  53. for (; s != programs.end(); ++s) {
  54. this->Files.push_back(this->FindInstallSource(s->c_str()));
  55. }
  56. }
  57. // Construct the destination. This command always installs under
  58. // the prefix. We skip the leading slash given by the user.
  59. std::string destination = this->Destination.substr(1);
  60. cmSystemTools::ConvertToUnixSlashes(destination);
  61. if (destination.empty()) {
  62. destination = ".";
  63. }
  64. // Use a file install generator.
  65. const char* no_permissions = "";
  66. const char* no_rename = "";
  67. bool no_exclude_from_all = false;
  68. std::string no_component =
  69. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
  70. std::vector<std::string> no_configurations;
  71. cmInstallGenerator::MessageLevel message =
  72. cmInstallGenerator::SelectMessageLevel(this->Makefile);
  73. this->Makefile->AddInstallGenerator(new cmInstallFilesGenerator(
  74. this->Files, destination.c_str(), true, no_permissions, no_configurations,
  75. no_component.c_str(), message, no_exclude_from_all, no_rename));
  76. }
  77. /**
  78. * Find a file in the build or source tree for installation given a
  79. * relative path from the CMakeLists.txt file. This will favor files
  80. * present in the build tree. If a full path is given, it is just
  81. * returned.
  82. */
  83. std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const
  84. {
  85. if (cmSystemTools::FileIsFullPath(name) ||
  86. cmGeneratorExpression::Find(name) == 0) {
  87. // This is a full path.
  88. return name;
  89. }
  90. // This is a relative path.
  91. std::string tb = this->Makefile->GetCurrentBinaryDirectory();
  92. tb += "/";
  93. tb += name;
  94. std::string ts = this->Makefile->GetCurrentSourceDirectory();
  95. ts += "/";
  96. ts += name;
  97. if (cmSystemTools::FileExists(tb.c_str())) {
  98. // The file exists in the binary tree. Use it.
  99. return tb;
  100. }
  101. if (cmSystemTools::FileExists(ts.c_str())) {
  102. // The file exists in the source tree. Use it.
  103. return ts;
  104. }
  105. // The file doesn't exist. Assume it will be present in the
  106. // binary tree when the install occurs.
  107. return tb;
  108. }