cmInstallCxxModuleBmiGenerator.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "cmInstallCxxModuleBmiGenerator.h"
  4. #include <ostream>
  5. #include <utility>
  6. #include "cmGeneratorExpression.h"
  7. #include "cmGeneratorTarget.h"
  8. #include "cmGlobalGenerator.h"
  9. #include "cmListFileCache.h"
  10. #include "cmLocalGenerator.h"
  11. #include "cmOutputConverter.h"
  12. #include "cmStringAlgorithms.h"
  13. cmInstallCxxModuleBmiGenerator::cmInstallCxxModuleBmiGenerator(
  14. std::string target, std::string const& dest, std::string file_permissions,
  15. std::vector<std::string> const& configurations, std::string const& component,
  16. MessageLevel message, bool exclude_from_all, bool optional,
  17. cmListFileBacktrace backtrace)
  18. : cmInstallGenerator(dest, configurations, component, message,
  19. exclude_from_all, false, std::move(backtrace))
  20. , TargetName(std::move(target))
  21. , FilePermissions(std::move(file_permissions))
  22. , Optional(optional)
  23. {
  24. this->ActionsPerConfig = true;
  25. }
  26. cmInstallCxxModuleBmiGenerator::~cmInstallCxxModuleBmiGenerator() = default;
  27. bool cmInstallCxxModuleBmiGenerator::Compute(cmLocalGenerator* lg)
  28. {
  29. this->LocalGenerator = lg;
  30. this->Target = lg->FindLocalNonAliasGeneratorTarget(this->TargetName);
  31. if (!this->Target) {
  32. // If no local target has been found, find it in the global scope.
  33. this->Target =
  34. lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName);
  35. }
  36. return true;
  37. }
  38. std::string cmInstallCxxModuleBmiGenerator::GetScriptLocation(
  39. std::string const& config) const
  40. {
  41. char const* config_name = config.c_str();
  42. if (config.empty()) {
  43. config_name = "noconfig";
  44. }
  45. return cmStrCat(this->Target->GetSupportDirectory(),
  46. "/install-cxx-module-bmi-", config_name, ".cmake");
  47. }
  48. std::string cmInstallCxxModuleBmiGenerator::GetDestination(
  49. std::string const& config) const
  50. {
  51. return cmGeneratorExpression::Evaluate(this->Destination,
  52. this->LocalGenerator, config);
  53. }
  54. void cmInstallCxxModuleBmiGenerator::GenerateScriptForConfig(
  55. std::ostream& os, const std::string& config, Indent indent)
  56. {
  57. auto const& loc = this->GetScriptLocation(config);
  58. if (loc.empty()) {
  59. return;
  60. }
  61. os << indent << "include(\""
  62. << cmOutputConverter::EscapeForCMake(
  63. loc, cmOutputConverter::WrapQuotes::NoWrap)
  64. << "\" OPTIONAL)\n";
  65. }