cmCxxModuleMapper.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Gcc,
  16. Msvc,
  17. };
  18. struct CxxModuleLocations
  19. {
  20. // The path from which all relative paths should be computed. If
  21. // this is relative, it is relative to the compiler's working
  22. // directory.
  23. std::string RootDirectory;
  24. // A function to convert a full path to a path for the generator.
  25. std::function<std::string(std::string const&)> PathForGenerator;
  26. // Lookup the BMI location of a logical module name.
  27. std::function<cm::optional<std::string>(std::string const&)>
  28. BmiLocationForModule;
  29. // Returns the generator path (if known) for the BMI given a
  30. // logical module name.
  31. cm::optional<std::string> BmiGeneratorPathForModule(
  32. std::string const& logical_name) const;
  33. };
  34. struct CxxModuleReference
  35. {
  36. // The path to the module file used.
  37. std::string Path;
  38. // How the module was looked up.
  39. LookupMethod Method;
  40. };
  41. struct CxxModuleUsage
  42. {
  43. // The usage requirements for this object.
  44. std::map<std::string, std::set<std::string>> Usage;
  45. // The references for this object.
  46. std::map<std::string, CxxModuleReference> Reference;
  47. // Add a reference to a module.
  48. //
  49. // Returns `true` if it matches how it was found previously, `false` if it
  50. // conflicts.
  51. bool AddReference(std::string const& logical, std::string const& loc,
  52. LookupMethod method);
  53. };
  54. // Return the extension to use for a given modulemap format.
  55. cm::static_string_view CxxModuleMapExtension(
  56. cm::optional<CxxModuleMapFormat> format);
  57. // Fill in module usage information for internal usages.
  58. //
  59. // Returns the set of unresolved module usage requirements (these form an
  60. // import cycle).
  61. std::set<std::string> CxxModuleUsageSeed(
  62. CxxModuleLocations const& loc, std::vector<cmScanDepInfo> const& objects,
  63. CxxModuleUsage& usages);
  64. // Return the contents of the module map in the given format for the
  65. // object file.
  66. std::string CxxModuleMapContent(CxxModuleMapFormat format,
  67. CxxModuleLocations const& loc,
  68. cmScanDepInfo const& obj,
  69. CxxModuleUsage const& usages);