cmExportBuildPackageInfoGenerator.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmExportBuildPackageInfoGenerator.h"
  4. #include <cassert>
  5. #include <utility>
  6. #include <vector>
  7. #include <cmext/string_view>
  8. #include <cm3p/json/value.h>
  9. #include "cmGeneratorExpression.h"
  10. #include "cmPackageInfoArguments.h"
  11. #include "cmStateTypes.h"
  12. #include "cmStringAlgorithms.h"
  13. cmExportBuildPackageInfoGenerator::cmExportBuildPackageInfoGenerator(
  14. cmPackageInfoArguments arguments)
  15. : cmExportPackageInfoGenerator(std::move(arguments))
  16. {
  17. this->SetNamespace(cmStrCat(this->GetPackageName(), "::"_s));
  18. }
  19. bool cmExportBuildPackageInfoGenerator::GenerateMainFile(std::ostream& os)
  20. {
  21. if (!this->CollectExports([&](cmGeneratorTarget const*) {})) {
  22. return false;
  23. }
  24. if (!this->CheckDefaultTargets()) {
  25. return false;
  26. }
  27. Json::Value root = this->GeneratePackageInfo();
  28. root["cps_path"] = "@prefix@";
  29. Json::Value& components = root["components"];
  30. // Create all the imported targets.
  31. for (auto const& exp : this->Exports) {
  32. cmGeneratorTarget* const target = exp.Target;
  33. cmStateEnums::TargetType targetType = this->GetExportTargetType(target);
  34. Json::Value* const component =
  35. this->GenerateImportTarget(components, target, targetType);
  36. if (!component) {
  37. return false;
  38. }
  39. ImportPropertyMap properties;
  40. if (!this->PopulateInterfaceProperties(target, properties)) {
  41. return false;
  42. }
  43. this->PopulateInterfaceLinkLibrariesProperty(
  44. target, cmGeneratorExpression::InstallInterface, properties);
  45. if (targetType != cmStateEnums::INTERFACE_LIBRARY) {
  46. auto configurations = Json::Value{ Json::objectValue };
  47. // Add per-configuration properties.
  48. for (std::string const& c : this->Configurations) {
  49. this->GenerateInterfacePropertiesConfig(configurations, target, c);
  50. }
  51. if (!configurations.empty()) {
  52. (*component)["configurations"] = configurations;
  53. }
  54. }
  55. // Set configuration-agnostic properties for component.
  56. this->GenerateInterfaceProperties(*component, target, properties);
  57. }
  58. this->GeneratePackageRequires(root);
  59. // Write the primary packing information file.
  60. this->WritePackageInfo(root, os);
  61. bool result = true;
  62. return result;
  63. }
  64. void cmExportBuildPackageInfoGenerator::GenerateInterfacePropertiesConfig(
  65. Json::Value& configurations, cmGeneratorTarget* target,
  66. std::string const& config)
  67. {
  68. std::string const& suffix = PropertyConfigSuffix(config);
  69. ImportPropertyMap properties;
  70. assert(this->GetExportTargetType(target) != cmStateEnums::INTERFACE_LIBRARY);
  71. this->SetImportLocationProperty(config, suffix, target, properties);
  72. if (properties.empty()) {
  73. return;
  74. }
  75. this->SetImportDetailProperties(config, suffix, target, properties);
  76. // TODO: PUBLIC_HEADER_LOCATION
  77. Json::Value component =
  78. this->GenerateInterfaceConfigProperties(suffix, properties);
  79. if (!component.empty()) {
  80. configurations[config] = std::move(component);
  81. }
  82. }
  83. std::string cmExportBuildPackageInfoGenerator::GetCxxModulesDirectory() const
  84. {
  85. // TODO: Implement a not-CMake-specific mechanism for providing module
  86. // information.
  87. return {};
  88. }