cmCxxModuleMapper.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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<CxxBmiLocation(std::string const&)> BmiLocationForModule;
  42. // Returns the generator path (if known) for the BMI given a
  43. // logical module name.
  44. CxxBmiLocation BmiGeneratorPathForModule(
  45. std::string const& logical_name) const;
  46. };
  47. struct CxxModuleReference
  48. {
  49. // The path to the module file used.
  50. std::string Path;
  51. // How the module was looked up.
  52. LookupMethod Method;
  53. };
  54. struct CxxModuleUsage
  55. {
  56. // The usage requirements for this object.
  57. std::map<std::string, std::set<std::string>> Usage;
  58. // The references for this object.
  59. std::map<std::string, CxxModuleReference> Reference;
  60. // Add a reference to a module.
  61. //
  62. // Returns `true` if it matches how it was found previously, `false` if it
  63. // conflicts.
  64. bool AddReference(std::string const& logical, std::string const& loc,
  65. LookupMethod method);
  66. };
  67. // Return the extension to use for a given modulemap format.
  68. cm::static_string_view CxxModuleMapExtension(
  69. cm::optional<CxxModuleMapFormat> format);
  70. // Fill in module usage information for internal usages.
  71. //
  72. // Returns the set of unresolved module usage requirements (these form an
  73. // import cycle).
  74. std::set<std::string> CxxModuleUsageSeed(
  75. CxxModuleLocations const& loc, std::vector<cmScanDepInfo> const& objects,
  76. CxxModuleUsage& usages);
  77. // Return the contents of the module map in the given format for the
  78. // object file.
  79. std::string CxxModuleMapContent(CxxModuleMapFormat format,
  80. CxxModuleLocations const& loc,
  81. cmScanDepInfo const& obj,
  82. CxxModuleUsage const& usages);