cmInstallFilesGenerator.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 "cmInstallFilesGenerator.h"
  11. #include "cmGeneratorExpression.h"
  12. #include "cmMakefile.h"
  13. #include "cmSystemTools.h"
  14. #include "cmLocalGenerator.h"
  15. //----------------------------------------------------------------------------
  16. cmInstallFilesGenerator
  17. ::cmInstallFilesGenerator(std::vector<std::string> const& files,
  18. const char* dest, bool programs,
  19. const char* file_permissions,
  20. std::vector<std::string> const& configurations,
  21. const char* component,
  22. MessageLevel message,
  23. bool exclude_from_all,
  24. const char* rename,
  25. bool optional):
  26. cmInstallGenerator(dest, configurations, component, message,
  27. exclude_from_all),
  28. LocalGenerator(0),
  29. Files(files),
  30. FilePermissions(file_permissions),
  31. Rename(rename),
  32. Programs(programs),
  33. Optional(optional)
  34. {
  35. // We need per-config actions if the destination has generator expressions.
  36. if(cmGeneratorExpression::Find(Destination) != std::string::npos)
  37. {
  38. this->ActionsPerConfig = true;
  39. }
  40. // We need per-config actions if any files have generator expressions.
  41. for(std::vector<std::string>::const_iterator i = files.begin();
  42. !this->ActionsPerConfig && i != files.end(); ++i)
  43. {
  44. if(cmGeneratorExpression::Find(*i) != std::string::npos)
  45. {
  46. this->ActionsPerConfig = true;
  47. }
  48. }
  49. }
  50. //----------------------------------------------------------------------------
  51. cmInstallFilesGenerator
  52. ::~cmInstallFilesGenerator()
  53. {
  54. }
  55. void cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
  56. {
  57. this->LocalGenerator = lg;
  58. }
  59. //----------------------------------------------------------------------------
  60. std::string
  61. cmInstallFilesGenerator::GetDestination(std::string const& config) const
  62. {
  63. cmGeneratorExpression ge;
  64. return ge.Parse(this->Destination)
  65. ->Evaluate(this->LocalGenerator, config);
  66. }
  67. //----------------------------------------------------------------------------
  68. void cmInstallFilesGenerator::AddFilesInstallRule(
  69. std::ostream& os,
  70. const std::string config,
  71. Indent const& indent,
  72. std::vector<std::string> const& files)
  73. {
  74. // Write code to install the files.
  75. const char* no_dir_permissions = 0;
  76. this->AddInstallRule(os,
  77. this->GetDestination(config),
  78. (this->Programs
  79. ? cmInstallType_PROGRAMS
  80. : cmInstallType_FILES),
  81. files,
  82. this->Optional,
  83. this->FilePermissions.c_str(), no_dir_permissions,
  84. this->Rename.c_str(), 0, indent);
  85. }
  86. //----------------------------------------------------------------------------
  87. void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
  88. Indent const& indent)
  89. {
  90. if(this->ActionsPerConfig)
  91. {
  92. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  93. }
  94. else
  95. {
  96. this->AddFilesInstallRule(os, "", indent, this->Files);
  97. }
  98. }
  99. //----------------------------------------------------------------------------
  100. void cmInstallFilesGenerator::GenerateScriptForConfig(std::ostream& os,
  101. const std::string& config,
  102. Indent const& indent)
  103. {
  104. std::vector<std::string> files;
  105. cmGeneratorExpression ge;
  106. for(std::vector<std::string>::const_iterator i = this->Files.begin();
  107. i != this->Files.end(); ++i)
  108. {
  109. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
  110. cmSystemTools::ExpandListArgument(cge->Evaluate(
  111. this->LocalGenerator, config), files);
  112. }
  113. this->AddFilesInstallRule(os, config, indent, files);
  114. }