cmInstallFilesGenerator.cxx 3.4 KB

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