From 56f7d6f827290dd7d4d5c6edf0fe12568d4a819e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 15 May 2023 14:34:48 -0400 Subject: 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. --- Source/cmCxxModuleMapper.cxx | 44 ++++++++++++++++++++++++++++++++++++++++++++ Source/cmCxxModuleMapper.h | 17 +++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Source/cmCxxModuleMapper.cxx b/Source/cmCxxModuleMapper.cxx index 59bf4c7..e320f54 100644 --- a/Source/cmCxxModuleMapper.cxx +++ b/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 CxxModuleLocations::BmiGeneratorPathForModule( std::string const& logical_name) const { diff --git a/Source/cmCxxModuleMapper.h b/Source/cmCxxModuleMapper.h index 0f453b0..f405054 100644 --- a/Source/cmCxxModuleMapper.h +++ b/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 BmiLocation; +}; + struct CxxModuleLocations { // The path from which all relative paths should be computed. If -- cgit v0.12