cmInstallFilesGenerator.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "cmListFileCache.h"
  8. #include "cmStringAlgorithms.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. , LocalGenerator(nullptr)
  19. , Files(files)
  20. , FilePermissions(std::move(file_permissions))
  21. , Rename(std::move(rename))
  22. , Programs(programs)
  23. , Optional(optional)
  24. {
  25. // We need per-config actions if the destination and rename have generator
  26. // expressions.
  27. if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
  28. this->ActionsPerConfig = true;
  29. }
  30. if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
  31. this->ActionsPerConfig = true;
  32. }
  33. // We need per-config actions if any directories have generator expressions.
  34. if (!this->ActionsPerConfig) {
  35. for (std::string const& file : files) {
  36. if (cmGeneratorExpression::Find(file) != std::string::npos) {
  37. this->ActionsPerConfig = true;
  38. break;
  39. }
  40. }
  41. }
  42. }
  43. cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
  44. bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
  45. {
  46. this->LocalGenerator = lg;
  47. return true;
  48. }
  49. std::string cmInstallFilesGenerator::GetDestination(
  50. std::string const& config) const
  51. {
  52. return cmGeneratorExpression::Evaluate(this->Destination,
  53. this->LocalGenerator, config);
  54. }
  55. std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
  56. {
  57. return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
  58. config);
  59. }
  60. std::vector<std::string> cmInstallFilesGenerator::GetFiles(
  61. std::string const& config) const
  62. {
  63. std::vector<std::string> files;
  64. if (this->ActionsPerConfig) {
  65. for (std::string const& f : this->Files) {
  66. cmExpandList(
  67. cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config),
  68. files);
  69. }
  70. } else {
  71. files = this->Files;
  72. }
  73. return files;
  74. }
  75. void cmInstallFilesGenerator::AddFilesInstallRule(
  76. std::ostream& os, std::string const& config, Indent indent,
  77. std::vector<std::string> const& files)
  78. {
  79. // Write code to install the files.
  80. const char* no_dir_permissions = nullptr;
  81. this->AddInstallRule(
  82. os, this->GetDestination(config),
  83. (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
  84. this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
  85. this->GetRename(config).c_str(), nullptr, indent);
  86. }
  87. void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
  88. Indent indent)
  89. {
  90. if (this->ActionsPerConfig) {
  91. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  92. } else {
  93. this->AddFilesInstallRule(os, "", indent, this->Files);
  94. }
  95. }
  96. void cmInstallFilesGenerator::GenerateScriptForConfig(
  97. std::ostream& os, const std::string& config, Indent indent)
  98. {
  99. std::vector<std::string> files = this->GetFiles(config);
  100. this->AddFilesInstallRule(os, config, indent, files);
  101. }