cmCxxModuleMapper.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <functional>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #include <cm/optional>
  11. #include <cmext/string_view>
  12. enum class LookupMethod;
  13. struct cmScanDepInfo;
  14. enum class CxxModuleMapFormat
  15. {
  16. Clang,
  17. Gcc,
  18. Msvc,
  19. };
  20. struct CxxBmiLocation
  21. {
  22. static CxxBmiLocation Unknown();
  23. static CxxBmiLocation Private();
  24. static CxxBmiLocation Known(std::string path);
  25. bool IsKnown() const;
  26. bool IsPrivate() const;
  27. std::string const& Location() const;
  28. private:
  29. CxxBmiLocation();
  30. CxxBmiLocation(std::string path);
  31. cm::optional<std::string> BmiLocation;
  32. };
  33. struct CxxModuleLocations
  34. {
  35. // The path from which all relative paths should be computed. If
  36. // this is relative, it is relative to the compiler's working
  37. // directory.
  38. std::string RootDirectory;
  39. // A function to convert a full path to a path for the generator.
  40. std::function<std::string(std::string)> PathForGenerator;
  41. // Lookup the BMI location of a logical module name.
  42. std::function<CxxBmiLocation(std::string const&)> BmiLocationForModule;
  43. // Returns the generator path (if known) for the BMI given a
  44. // logical module name.
  45. CxxBmiLocation BmiGeneratorPathForModule(
  46. std::string const& logical_name) const;
  47. };
  48. struct CxxModuleReference
  49. {
  50. // The path to the module file used.
  51. std::string Path;
  52. // How the module was looked up.
  53. LookupMethod Method;
  54. };
  55. struct CxxModuleUsage
  56. {
  57. // The usage requirements for this object.
  58. std::map<std::string, std::set<std::string>> Usage;
  59. // The references for this object.
  60. std::map<std::string, CxxModuleReference> Reference;
  61. // Add a reference to a module.
  62. //
  63. // Returns `true` if it matches how it was found previously, `false` if it
  64. // conflicts.
  65. bool AddReference(std::string const& logical, std::string const& loc,
  66. LookupMethod method);
  67. };
  68. enum class CxxModuleMapMode
  69. {
  70. Text,
  71. Binary,
  72. Default = Text,
  73. };
  74. // Return the extension to use for a given modulemap format.
  75. cm::static_string_view CxxModuleMapExtension(
  76. cm::optional<CxxModuleMapFormat> format);
  77. // Fill in module usage information for internal usages.
  78. //
  79. // Returns the set of unresolved module usage requirements (these form an
  80. // import cycle).
  81. std::set<std::string> CxxModuleUsageSeed(
  82. CxxModuleLocations const& loc, std::vector<cmScanDepInfo> const& objects,
  83. CxxModuleUsage& usages, bool& private_usage_found);
  84. // Return the contents of the module map in the given format for the
  85. // object file.
  86. std::string CxxModuleMapContent(CxxModuleMapFormat format,
  87. CxxModuleLocations const& loc,
  88. cmScanDepInfo const& obj,
  89. CxxModuleUsage const& usages);
  90. // Return the open mode required for the modmap file format.
  91. CxxModuleMapMode CxxModuleMapOpenMode(CxxModuleMapFormat format);