cmInstallDirectoryGenerator.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "cmInstallDirectoryGenerator.h"
  4. #include "cmGeneratorExpression.h"
  5. #include "cmInstallType.h"
  6. #include "cmLocalGenerator.h"
  7. #include "cmMakefile.h"
  8. #include "cmSystemTools.h"
  9. #include "cm_auto_ptr.hxx"
  10. cmInstallDirectoryGenerator::cmInstallDirectoryGenerator(
  11. std::vector<std::string> const& dirs, const char* dest,
  12. const char* file_permissions, const char* dir_permissions,
  13. std::vector<std::string> const& configurations, const char* component,
  14. MessageLevel message, bool exclude_from_all, const char* literal_args,
  15. bool optional)
  16. : cmInstallGenerator(dest, configurations, component, message,
  17. exclude_from_all)
  18. , LocalGenerator(CM_NULLPTR)
  19. , Directories(dirs)
  20. , FilePermissions(file_permissions)
  21. , DirPermissions(dir_permissions)
  22. , LiteralArguments(literal_args)
  23. , Optional(optional)
  24. {
  25. // We need per-config actions if destination have generator expressions.
  26. if (cmGeneratorExpression::Find(Destination) != std::string::npos) {
  27. this->ActionsPerConfig = true;
  28. }
  29. // We need per-config actions if any directories have generator expressions.
  30. for (std::vector<std::string>::const_iterator i = dirs.begin();
  31. !this->ActionsPerConfig && i != dirs.end(); ++i) {
  32. if (cmGeneratorExpression::Find(*i) != std::string::npos) {
  33. this->ActionsPerConfig = true;
  34. }
  35. }
  36. }
  37. cmInstallDirectoryGenerator::~cmInstallDirectoryGenerator()
  38. {
  39. }
  40. void cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg)
  41. {
  42. LocalGenerator = lg;
  43. }
  44. void cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
  45. Indent const& indent)
  46. {
  47. if (this->ActionsPerConfig) {
  48. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  49. } else {
  50. this->AddDirectoryInstallRule(os, "", indent, this->Directories);
  51. }
  52. }
  53. void cmInstallDirectoryGenerator::GenerateScriptForConfig(
  54. std::ostream& os, const std::string& config, Indent const& indent)
  55. {
  56. std::vector<std::string> dirs;
  57. cmGeneratorExpression ge;
  58. for (std::vector<std::string>::const_iterator i = this->Directories.begin();
  59. i != this->Directories.end(); ++i) {
  60. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
  61. cmSystemTools::ExpandListArgument(
  62. cge->Evaluate(this->LocalGenerator, config), dirs);
  63. }
  64. // Make sure all dirs have absolute paths.
  65. cmMakefile const& mf = *this->LocalGenerator->GetMakefile();
  66. for (std::vector<std::string>::iterator i = dirs.begin(); i != dirs.end();
  67. ++i) {
  68. if (!cmSystemTools::FileIsFullPath(i->c_str())) {
  69. *i = std::string(mf.GetCurrentSourceDirectory()) + "/" + *i;
  70. }
  71. }
  72. this->AddDirectoryInstallRule(os, config, indent, dirs);
  73. }
  74. void cmInstallDirectoryGenerator::AddDirectoryInstallRule(
  75. std::ostream& os, const std::string& config, Indent const& indent,
  76. std::vector<std::string> const& dirs)
  77. {
  78. // Write code to install the directories.
  79. const char* no_rename = CM_NULLPTR;
  80. this->AddInstallRule(os, this->GetDestination(config),
  81. cmInstallType_DIRECTORY, dirs, this->Optional,
  82. this->FilePermissions.c_str(),
  83. this->DirPermissions.c_str(), no_rename,
  84. this->LiteralArguments.c_str(), indent);
  85. }
  86. std::string cmInstallDirectoryGenerator::GetDestination(
  87. std::string const& config) const
  88. {
  89. cmGeneratorExpression ge;
  90. return ge.Parse(this->Destination)->Evaluate(this->LocalGenerator, config);
  91. }