You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.9 KiB

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