cmInstallDirectoryGenerator.cxx 3.5 KB

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