cmInstallFilesGenerator.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmInstallFilesGenerator.h"
  4. #include <utility>
  5. #include "cmGeneratorExpression.h"
  6. #include "cmInstallType.h"
  7. #include "cmList.h"
  8. #include "cmListFileCache.h"
  9. class cmLocalGenerator;
  10. cmInstallFilesGenerator::cmInstallFilesGenerator(
  11. std::vector<std::string> const& files, std::string const& dest,
  12. bool programs, std::string file_permissions,
  13. std::vector<std::string> const& configurations, std::string const& component,
  14. MessageLevel message, bool exclude_from_all, std::string rename,
  15. bool optional, cmListFileBacktrace backtrace)
  16. : cmInstallGenerator(dest, configurations, component, message,
  17. exclude_from_all, false, std::move(backtrace))
  18. , Files(files)
  19. , FilePermissions(std::move(file_permissions))
  20. , Rename(std::move(rename))
  21. , Programs(programs)
  22. , Optional(optional)
  23. {
  24. // We need per-config actions if the destination and rename have generator
  25. // expressions.
  26. if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
  27. this->ActionsPerConfig = true;
  28. }
  29. if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
  30. this->ActionsPerConfig = true;
  31. }
  32. // We need per-config actions if any directories have generator expressions.
  33. if (!this->ActionsPerConfig) {
  34. for (std::string const& file : files) {
  35. if (cmGeneratorExpression::Find(file) != std::string::npos) {
  36. this->ActionsPerConfig = true;
  37. break;
  38. }
  39. }
  40. }
  41. }
  42. cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
  43. bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
  44. {
  45. this->LocalGenerator = lg;
  46. return true;
  47. }
  48. std::string cmInstallFilesGenerator::GetDestination(
  49. std::string const& config) const
  50. {
  51. return cmGeneratorExpression::Evaluate(this->Destination,
  52. this->LocalGenerator, config);
  53. }
  54. std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
  55. {
  56. return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
  57. config);
  58. }
  59. std::vector<std::string> cmInstallFilesGenerator::GetFiles(
  60. std::string const& config) const
  61. {
  62. if (this->ActionsPerConfig) {
  63. cmList files;
  64. for (std::string const& f : this->Files) {
  65. files.append(
  66. cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config));
  67. }
  68. return std::move(files.data());
  69. }
  70. return this->Files;
  71. }
  72. void cmInstallFilesGenerator::AddFilesInstallRule(
  73. std::ostream& os, std::string const& config, Indent indent,
  74. std::vector<std::string> const& files)
  75. {
  76. // Write code to install the files.
  77. const char* no_dir_permissions = nullptr;
  78. this->AddInstallRule(
  79. os, this->GetDestination(config),
  80. (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
  81. this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
  82. this->GetRename(config).c_str(), nullptr, indent);
  83. }
  84. void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
  85. Indent indent)
  86. {
  87. if (this->ActionsPerConfig) {
  88. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  89. } else {
  90. this->AddFilesInstallRule(os, "", indent, this->Files);
  91. }
  92. }
  93. void cmInstallFilesGenerator::GenerateScriptForConfig(
  94. std::ostream& os, const std::string& config, Indent indent)
  95. {
  96. std::vector<std::string> files = this->GetFiles(config);
  97. this->AddFilesInstallRule(os, config, indent, files);
  98. }