cmInstallFilesGenerator.cxx 4.3 KB

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