cmInstallDirectoryGenerator.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmInstallDirectoryGenerator.h"
  11. #include "cmGeneratorExpression.h"
  12. #include "cmLocalGenerator.h"
  13. //----------------------------------------------------------------------------
  14. cmInstallDirectoryGenerator
  15. ::cmInstallDirectoryGenerator(std::vector<std::string> const& dirs,
  16. const char* dest,
  17. const char* file_permissions,
  18. const char* dir_permissions,
  19. std::vector<std::string> const& configurations,
  20. const char* component,
  21. MessageLevel message,
  22. bool exclude_from_all,
  23. const char* literal_args,
  24. bool optional):
  25. cmInstallGenerator(dest, configurations, component, message,
  26. exclude_from_all),
  27. LocalGenerator(0),
  28. Directories(dirs),
  29. FilePermissions(file_permissions), DirPermissions(dir_permissions),
  30. LiteralArguments(literal_args), Optional(optional)
  31. {
  32. // We need per-config actions if destination have generator expressions.
  33. if(cmGeneratorExpression::Find(Destination) != std::string::npos)
  34. {
  35. this->ActionsPerConfig = true;
  36. }
  37. // We need per-config actions if any directories have generator expressions.
  38. for(std::vector<std::string>::const_iterator i = dirs.begin();
  39. !this->ActionsPerConfig && i != dirs.end(); ++i)
  40. {
  41. if(cmGeneratorExpression::Find(*i) != std::string::npos)
  42. {
  43. this->ActionsPerConfig = true;
  44. }
  45. }
  46. }
  47. //----------------------------------------------------------------------------
  48. cmInstallDirectoryGenerator
  49. ::~cmInstallDirectoryGenerator()
  50. {
  51. }
  52. void cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg)
  53. {
  54. LocalGenerator = lg;
  55. }
  56. //----------------------------------------------------------------------------
  57. void
  58. cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
  59. Indent const& indent)
  60. {
  61. if(this->ActionsPerConfig)
  62. {
  63. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  64. }
  65. else
  66. {
  67. this->AddDirectoryInstallRule(os, "", indent, this->Directories);
  68. }
  69. }
  70. void cmInstallDirectoryGenerator::GenerateScriptForConfig(
  71. std::ostream& os,
  72. const std::string& config,
  73. Indent const& indent)
  74. {
  75. std::vector<std::string> dirs;
  76. cmGeneratorExpression ge;
  77. for(std::vector<std::string>::const_iterator i = this->Directories.begin();
  78. i != this->Directories.end(); ++i)
  79. {
  80. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
  81. cmSystemTools::ExpandListArgument(cge->Evaluate(
  82. this->LocalGenerator, config), dirs);
  83. }
  84. this->AddDirectoryInstallRule(os, config, indent, dirs);
  85. }
  86. void cmInstallDirectoryGenerator::AddDirectoryInstallRule(
  87. std::ostream& os,
  88. const std::string& config,
  89. Indent const& indent,
  90. std::vector<std::string> const& dirs)
  91. {
  92. // Write code to install the directories.
  93. const char* no_rename = 0;
  94. this->AddInstallRule(os,
  95. this->GetDestination(config),
  96. cmInstallType_DIRECTORY,
  97. dirs,
  98. this->Optional,
  99. this->FilePermissions.c_str(),
  100. this->DirPermissions.c_str(),
  101. no_rename, this->LiteralArguments.c_str(),
  102. indent);
  103. }
  104. //----------------------------------------------------------------------------
  105. std::string
  106. cmInstallDirectoryGenerator::GetDestination(std::string const& config) const
  107. {
  108. cmGeneratorExpression ge;
  109. return ge.Parse(this->Destination)
  110. ->Evaluate(this->LocalGenerator, config);
  111. }