cmCxxModuleMapper.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "cmScanDepFormat.h"
  13. enum class CxxModuleMapFormat
  14. {
  15. Clang,
  16. Gcc,
  17. Msvc,
  18. };
  19. struct CxxBmiLocation
  20. {
  21. static CxxBmiLocation Unknown();
  22. static CxxBmiLocation Private();
  23. static CxxBmiLocation Known(std::string path);
  24. bool IsKnown() const;
  25. bool IsPrivate() const;
  26. std::string const& Location() const;
  27. private:
  28. CxxBmiLocation();
  29. CxxBmiLocation(std::string path);
  30. cm::optional<std::string> BmiLocation;
  31. };
  32. struct CxxModuleLocations
  33. {
  34. // The path from which all relative paths should be computed. If
  35. // this is relative, it is relative to the compiler's working
  36. // directory.
  37. std::string RootDirectory;
  38. // A function to convert a full path to a path for the generator.
  39. std::function<std::string(std::string)> PathForGenerator;
  40. // Lookup the BMI location of a logical module name.
  41. std::function<cm::optional<std::string>(std::string const&)>
  42. BmiLocationForModule;
  43. // Returns the generator path (if known) for the BMI given a
  44. // logical module name.
  45. cm::optional<std::string> 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. // Return the extension to use for a given modulemap format.
  69. cm::static_string_view CxxModuleMapExtension(
  70. cm::optional<CxxModuleMapFormat> format);
  71. // Fill in module usage information for internal usages.
  72. //
  73. // Returns the set of unresolved module usage requirements (these form an
  74. // import cycle).
  75. std::set<std::string> CxxModuleUsageSeed(
  76. CxxModuleLocations const& loc, std::vector<cmScanDepInfo> const& objects,
  77. CxxModuleUsage& usages);
  78. // Return the contents of the module map in the given format for the
  79. // object file.
  80. std::string CxxModuleMapContent(CxxModuleMapFormat format,
  81. CxxModuleLocations const& loc,
  82. cmScanDepInfo const& obj,
  83. CxxModuleUsage const& usages);