Browse Source

cmCxxModuleMapper: add a structure to represent BMI locations

This structure allows representing whether a module is private in order
to give a more useful error message when its usage is attempted from
another target.
Ben Boeckel 2 years ago
parent
commit
56f7d6f827
2 changed files with 61 additions and 0 deletions
  1. 44 0
      Source/cmCxxModuleMapper.cxx
  2. 17 0
      Source/cmCxxModuleMapper.h

+ 44 - 0
Source/cmCxxModuleMapper.cxx

@@ -17,6 +17,50 @@
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
+CxxBmiLocation::CxxBmiLocation() = default;
+
+CxxBmiLocation::CxxBmiLocation(std::string path)
+  : BmiLocation(std::move(path))
+{
+}
+
+CxxBmiLocation CxxBmiLocation::Unknown()
+{
+  return {};
+}
+
+CxxBmiLocation CxxBmiLocation::Private()
+{
+  return { std::string{} };
+}
+
+CxxBmiLocation CxxBmiLocation::Known(std::string path)
+{
+  return { std::move(path) };
+}
+
+bool CxxBmiLocation::IsKnown() const
+{
+  return this->BmiLocation.has_value();
+}
+
+bool CxxBmiLocation::IsPrivate() const
+{
+  if (auto const& loc = this->BmiLocation) {
+    return loc->empty();
+  }
+  return false;
+}
+
+std::string const& CxxBmiLocation::Location() const
+{
+  if (auto const& loc = this->BmiLocation) {
+    return *loc;
+  }
+  static std::string empty;
+  return empty;
+}
+
 cm::optional<std::string> CxxModuleLocations::BmiGeneratorPathForModule(
   std::string const& logical_name) const
 {

+ 17 - 0
Source/cmCxxModuleMapper.h

@@ -22,6 +22,23 @@ enum class CxxModuleMapFormat
   Msvc,
 };
 
+struct CxxBmiLocation
+{
+  static CxxBmiLocation Unknown();
+  static CxxBmiLocation Private();
+  static CxxBmiLocation Known(std::string path);
+
+  bool IsKnown() const;
+  bool IsPrivate() const;
+  std::string const& Location() const;
+
+private:
+  CxxBmiLocation();
+  CxxBmiLocation(std::string path);
+
+  cm::optional<std::string> BmiLocation;
+};
+
 struct CxxModuleLocations
 {
   // The path from which all relative paths should be computed. If