cmExportSet.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "cmExportSet.h" // IWYU pragma: associated
  4. #include <algorithm>
  5. #include <tuple>
  6. #include <utility>
  7. #include "cmGeneratorTarget.h"
  8. #include "cmLocalGenerator.h"
  9. #include "cmMessageType.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmTarget.h"
  12. #include "cmTargetExport.h" // IWYU pragma: associated
  13. cmExportSet::cmExportSet(std::string name)
  14. : Name(std::move(name))
  15. {
  16. }
  17. cmExportSet::~cmExportSet() = default;
  18. cmExportSet::PackageDependency& cmExportSet::GetPackageDependencyForSetup(
  19. const std::string& name)
  20. {
  21. auto& dep = this->PackageDependencies[name];
  22. if (!dep.SpecifiedIndex) {
  23. dep.SpecifiedIndex = this->NextPackageDependencyIndex;
  24. this->NextPackageDependencyIndex++;
  25. }
  26. return dep;
  27. }
  28. bool cmExportSet::Compute(cmLocalGenerator* lg)
  29. {
  30. for (std::unique_ptr<cmTargetExport>& tgtExport : this->TargetExports) {
  31. tgtExport->Target = lg->FindGeneratorTargetToUse(tgtExport->TargetName);
  32. auto const interfaceFileSets =
  33. tgtExport->Target->Target->GetAllInterfaceFileSets();
  34. auto const fileSetInTargetExport =
  35. [&tgtExport, lg](const std::string& fileSetName) -> bool {
  36. auto* fileSet = tgtExport->Target->Target->GetFileSet(fileSetName);
  37. if (!tgtExport->FileSetGenerators.count(fileSet)) {
  38. lg->IssueMessage(MessageType::FATAL_ERROR,
  39. cmStrCat("File set \"", fileSetName,
  40. "\" is listed in interface file sets of ",
  41. tgtExport->Target->GetName(),
  42. " but has not been exported"));
  43. return false;
  44. }
  45. return true;
  46. };
  47. if (!std::all_of(interfaceFileSets.begin(), interfaceFileSets.end(),
  48. fileSetInTargetExport)) {
  49. return false;
  50. }
  51. }
  52. return true;
  53. }
  54. void cmExportSet::AddTargetExport(std::unique_ptr<cmTargetExport> te)
  55. {
  56. this->TargetExports.emplace_back(std::move(te));
  57. }
  58. void cmExportSet::AddInstallation(cmInstallExportGenerator const* installation)
  59. {
  60. this->Installations.push_back(installation);
  61. }
  62. cmExportSet& cmExportSetMap::operator[](const std::string& name)
  63. {
  64. auto it = this->find(name);
  65. if (it == this->end()) // Export set not found
  66. {
  67. auto tup_name = std::make_tuple(name);
  68. it = this->emplace(std::piecewise_construct, tup_name, tup_name).first;
  69. }
  70. return it->second;
  71. }