cmExportPackageInfoGenerator.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 CheckPackage() const
  39. {
  40. return this->CheckVersion() && this->CheckDefaultTargets();
  41. }
  42. Json::Value GeneratePackageInfo() const;
  43. Json::Value* GenerateImportTarget(Json::Value& components,
  44. cmGeneratorTarget const* target,
  45. cmStateEnums::TargetType targetType) const;
  46. void GeneratePackageRequires(Json::Value& package) const;
  47. using ImportPropertyMap = std::map<std::string, std::string>;
  48. bool GenerateInterfaceProperties(Json::Value& component,
  49. cmGeneratorTarget const* target,
  50. ImportPropertyMap const& properties) const;
  51. Json::Value GenerateInterfaceConfigProperties(
  52. std::string const& suffix, ImportPropertyMap const& properties) const;
  53. cm::string_view GetImportPrefixWithSlash() const override;
  54. std::string GetCxxModuleFile(std::string const& /*name*/) const override
  55. {
  56. // TODO
  57. return {};
  58. }
  59. void GenerateCxxModuleConfigInformation(std::string const& /*name*/,
  60. std::ostream& /*os*/) const override
  61. {
  62. // TODO
  63. }
  64. bool NoteLinkedTarget(cmGeneratorTarget const* target,
  65. std::string const& linkedName,
  66. cmGeneratorTarget const* linkedTarget) override;
  67. private:
  68. bool CheckVersion() const;
  69. bool CheckDefaultTargets() const;
  70. void GenerateInterfaceLinkProperties(
  71. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  72. ImportPropertyMap const& properties) const;
  73. void GenerateInterfaceCompileFeatures(
  74. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  75. ImportPropertyMap const& properties) const;
  76. void GenerateInterfaceCompileDefines(
  77. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  78. ImportPropertyMap const& properties) const;
  79. void GenerateInterfaceListProperty(
  80. bool& result, Json::Value& component, cmGeneratorTarget const* target,
  81. std::string const& outName, cm::string_view inName,
  82. ImportPropertyMap const& properties) const;
  83. void GenerateProperty(bool& result, Json::Value& component,
  84. cmGeneratorTarget const* target,
  85. std::string const& outName, std::string const& inName,
  86. ImportPropertyMap const& properties) const;
  87. std::string const PackageName;
  88. std::string const PackageVersion;
  89. std::string const PackageVersionCompat;
  90. std::string const PackageVersionSchema;
  91. std::string const PackageDescription;
  92. std::string const PackageWebsite;
  93. std::string const PackageLicense;
  94. std::string const DefaultLicense;
  95. std::vector<std::string> DefaultTargets;
  96. std::vector<std::string> DefaultConfigurations;
  97. std::map<std::string, std::string> LinkTargets;
  98. std::map<std::string, cmPackageInformation> Requirements;
  99. };