cmInstallScriptGenerator.cxx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmInstallScriptGenerator.h"
  4. #include "cmGeneratorExpression.h"
  5. #include "cmScriptGenerator.h"
  6. #include <ostream>
  7. #include <vector>
  8. cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script,
  9. bool code,
  10. const char* component,
  11. bool exclude_from_all)
  12. : cmInstallGenerator(nullptr, std::vector<std::string>(), component,
  13. MessageDefault, exclude_from_all)
  14. , Script(script)
  15. , Code(code)
  16. {
  17. // We need per-config actions if the script has generator expressions.
  18. if (cmGeneratorExpression::Find(Script) != std::string::npos) {
  19. this->ActionsPerConfig = true;
  20. }
  21. }
  22. cmInstallScriptGenerator::~cmInstallScriptGenerator()
  23. {
  24. }
  25. void cmInstallScriptGenerator::Compute(cmLocalGenerator* lg)
  26. {
  27. this->LocalGenerator = lg;
  28. }
  29. void cmInstallScriptGenerator::AddScriptInstallRule(std::ostream& os,
  30. Indent indent,
  31. std::string const& script)
  32. {
  33. if (this->Code) {
  34. os << indent << script << "\n";
  35. } else {
  36. os << indent << "include(\"" << script << "\")\n";
  37. }
  38. }
  39. void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os,
  40. Indent indent)
  41. {
  42. if (this->ActionsPerConfig) {
  43. this->cmInstallGenerator::GenerateScriptActions(os, indent);
  44. } else {
  45. this->AddScriptInstallRule(os, indent, this->Script);
  46. }
  47. }
  48. void cmInstallScriptGenerator::GenerateScriptForConfig(
  49. std::ostream& os, const std::string& config, Indent indent)
  50. {
  51. cmGeneratorExpression ge;
  52. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(this->Script);
  53. this->AddScriptInstallRule(os, indent,
  54. cge->Evaluate(this->LocalGenerator, config));
  55. }