cmInstallDirectoryGenerator.cxx 3.9 KB

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