cmExportPackageInfoGenerator.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <iosfwd>
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include <cm/string_view>
  10. #include "cmExportFileGenerator.h"
  11. #include "cmFindPackageStack.h"
  12. #include "cmStateTypes.h"
  13. namespace Json {
  14. class Value;
  15. }
  16. class cmGeneratorTarget;
  17. class cmPackageInfoArguments;
  18. /** \class cmExportPackageInfoGenerator
  19. * \brief Generate Common Package Specification package information files
  20. * exporting targets from a build or install tree.
  21. *
  22. * cmExportPackageInfoGenerator is the superclass for
  23. * cmExportBuildPackageInfoGenerator and cmExportInstallPackageInfoGenerator.
  24. * It contains common code generation routines for the two kinds of export
  25. * implementations.
  26. */
  27. class cmExportPackageInfoGenerator : virtual public cmExportFileGenerator
  28. {
  29. public:
  30. cmExportPackageInfoGenerator(cmPackageInfoArguments arguments);
  31. using cmExportFileGenerator::GenerateImportFile;
  32. protected:
  33. std::string const& GetPackageName() const { return this->PackageName; }
  34. void WritePackageInfo(Json::Value const& packageInfo,
  35. std::ostream& os) const;
  36. // Methods to implement export file code generation.
  37. bool GenerateImportFile(std::ostream& os) override;
  38. bool CheckDefaultTargets() const;
  39. Json::Value GeneratePackageInfo() const;
  40. Json::Value* GenerateImportTarget(Json::Value& components,
  41. cmGeneratorTarget const* target,
  42. cmStateEnums::TargetType targetType) const;
  43. void GeneratePackageRequires(Json::Value& package) const;
  44. using ImportPropertyMap = std::map<std::string, std::string>;
  45. bool GenerateInterfaceProperties(Json::Value& component,
  46. cmGeneratorTarget const* target,
  47. ImportPropertyMap const& properties) const;
  48. Json::Value GenerateInterfaceConfigProperties(
  49. std::string const& suffix, ImportPropertyMap const& properties) const;
  50. cm::string_view GetImportPrefixWithSlash() const override;
  51. std::string GetCxxModuleFile(std::string const& /*name*/) const override
  52. {
  53. // TODO
  54. return {};
  55. }
  56. void GenerateCxxModuleConfigInformation(std::string const& /*name*/,
  57. std::ostream& /*os*/) const override
  58. {
  59. // TODO
  60. }
  61. bool NoteLinkedTarget(cmGeneratorTarget const* target,
  62. std::string const& linkedName,
  63. cmGeneratorTarget const* linkedTarget) override;
  64. private:
  65. void GenerateInterfaceLinkProperties(
  66. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  67. ImportPropertyMap const& properties) const;
  68. void GenerateInterfaceCompileFeatures(
  69. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  70. ImportPropertyMap const& properties) const;
  71. void GenerateInterfaceCompileDefines(
  72. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  73. ImportPropertyMap const& properties) const;
  74. void GenerateInterfaceListProperty(
  75. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  76. std::string const& outName, cm::string_view inName,
  77. ImportPropertyMap const& properties) const;
  78. void GenerateProperty(bool& result, Json::Value& component,
  79. cmGeneratorTarget const* target,
  80. std::string const& outName, std::string const& inName,
  81. ImportPropertyMap const& properties) const;
  82. std::string const PackageName;
  83. std::string const PackageVersion;
  84. std::string const PackageVersionCompat;
  85. std::string const PackageVersionSchema;
  86. std::string const PackageDescription;
  87. std::string const PackageWebsite;
  88. std::string const PackageLicense;
  89. std::string const DefaultLicense;
  90. std::vector<std::string> DefaultTargets;
  91. std::vector<std::string> DefaultConfigurations;
  92. std::map<std::string, std::string> LinkTargets;
  93. std::map<std::string, cmPackageInformation> Requirements;
  94. };