cmInstallFilesGenerator.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "cmStringAlgorithms.h"
  8. class cmLocalGenerator;
  9. cmInstallFilesGenerator::cmInstallFilesGenerator(
  10. std::vector<std::string> const& files, std::string const& dest,
  11. bool programs, std::string file_permissions,
  12. std::vector<std::string> const& configurations, std::string const& component,
  13. MessageLevel message, bool exclude_from_all, std::string rename,
  14. bool optional, cmListFileBacktrace backtrace)
  15. : cmInstallGenerator(dest, configurations, component, message,
  16. exclude_from_all, false, std::move(backtrace))
  17. , LocalGenerator(nullptr)
  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. std::vector<std::string> files;
  63. if (this->ActionsPerConfig) {
  64. for (std::string const& f : this->Files) {
  65. cmExpandList(
  66. cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config),
  67. files);
  68. }
  69. } else {
  70. files = this->Files;
  71. }
  72. return files;
  73. }
  74. void cmInstallFilesGenerator::AddFilesInstallRule(
  75. std::ostream& os, std::string const& config, Indent indent,
  76. std::vector<std::string> const& files)
  77. {
  78. // Write code to install the files.
  79. const char* no_dir_permissions = nullptr;
  80. this->AddInstallRule(
  81. os, this->GetDestination(config),
  82. (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
  83. this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
  84. this->GetRename(config).c_str(), nullptr, indent);
  85. }
  86. void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
  87. Indent indent)
  88. {
  89. if (this->ActionsPerConfig) {
  90. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  91. } else {
  92. this->AddFilesInstallRule(os, "", indent, this->Files);
  93. }
  94. }
  95. void cmInstallFilesGenerator::GenerateScriptForConfig(
  96. std::ostream& os, const std::string& config, Indent indent)
  97. {
  98. std::vector<std::string> files = this->GetFiles(config);
  99. this->AddFilesInstallRule(os, config, indent, files);
  100. }