cmInstallProgramsCommand.cxx 4.3 KB

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