cmCxxModuleMapper.h 2.4 KB

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