cmInstallFilesGenerator.cxx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "cmGeneratorExpression.h"
  5. #include "cmInstallType.h"
  6. #include "cmSystemTools.h"
  7. #include <memory>
  8. class cmLocalGenerator;
  9. cmInstallFilesGenerator::cmInstallFilesGenerator(
  10. std::vector<std::string> const& files, const char* dest, bool programs,
  11. const char* file_permissions, std::vector<std::string> const& configurations,
  12. const char* component, MessageLevel message, bool exclude_from_all,
  13. const char* rename, bool optional)
  14. : cmInstallGenerator(dest, configurations, component, message,
  15. exclude_from_all)
  16. , LocalGenerator(nullptr)
  17. , Files(files)
  18. , FilePermissions(file_permissions)
  19. , Rename(rename)
  20. , Programs(programs)
  21. , Optional(optional)
  22. {
  23. // We need per-config actions if the destination has generator expressions.
  24. if (cmGeneratorExpression::Find(Destination) != std::string::npos) {
  25. this->ActionsPerConfig = true;
  26. }
  27. // We need per-config actions if any directories have generator expressions.
  28. if (!this->ActionsPerConfig) {
  29. for (std::string const& file : files) {
  30. if (cmGeneratorExpression::Find(file) != std::string::npos) {
  31. this->ActionsPerConfig = true;
  32. break;
  33. }
  34. }
  35. }
  36. }
  37. cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
  38. bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
  39. {
  40. this->LocalGenerator = lg;
  41. return true;
  42. }
  43. std::string cmInstallFilesGenerator::GetDestination(
  44. std::string const& config) const
  45. {
  46. cmGeneratorExpression ge;
  47. return ge.Parse(this->Destination)->Evaluate(this->LocalGenerator, config);
  48. }
  49. void cmInstallFilesGenerator::AddFilesInstallRule(
  50. std::ostream& os, std::string const& config, Indent indent,
  51. std::vector<std::string> const& files)
  52. {
  53. // Write code to install the files.
  54. const char* no_dir_permissions = nullptr;
  55. this->AddInstallRule(
  56. os, this->GetDestination(config),
  57. (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
  58. this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
  59. this->Rename.c_str(), nullptr, indent);
  60. }
  61. void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
  62. Indent indent)
  63. {
  64. if (this->ActionsPerConfig) {
  65. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  66. } else {
  67. this->AddFilesInstallRule(os, "", indent, this->Files);
  68. }
  69. }
  70. void cmInstallFilesGenerator::GenerateScriptForConfig(
  71. std::ostream& os, const std::string& config, Indent indent)
  72. {
  73. std::vector<std::string> files;
  74. cmGeneratorExpression ge;
  75. for (std::string const& f : this->Files) {
  76. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(f);
  77. cmSystemTools::ExpandListArgument(
  78. cge->Evaluate(this->LocalGenerator, config), files);
  79. }
  80. this->AddFilesInstallRule(os, config, indent, files);
  81. }