cmInstallFilesGenerator.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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)
  15. : cmInstallGenerator(dest, configurations, component, message,
  16. exclude_from_all)
  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. void cmInstallFilesGenerator::AddFilesInstallRule(
  60. std::ostream& os, std::string const& config, Indent indent,
  61. std::vector<std::string> const& files)
  62. {
  63. // Write code to install the files.
  64. const char* no_dir_permissions = nullptr;
  65. this->AddInstallRule(
  66. os, this->GetDestination(config),
  67. (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
  68. this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
  69. this->GetRename(config).c_str(), nullptr, indent);
  70. }
  71. void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
  72. Indent indent)
  73. {
  74. if (this->ActionsPerConfig) {
  75. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  76. } else {
  77. this->AddFilesInstallRule(os, "", indent, this->Files);
  78. }
  79. }
  80. void cmInstallFilesGenerator::GenerateScriptForConfig(
  81. std::ostream& os, const std::string& config, Indent indent)
  82. {
  83. std::vector<std::string> files;
  84. for (std::string const& f : this->Files) {
  85. cmExpandList(
  86. cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config), files);
  87. }
  88. this->AddFilesInstallRule(os, config, indent, files);
  89. }