cmInstallProgramsCommand.cxx 4.3 KB

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