diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2022-06-02 17:20:05 -0400 |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2022-06-16 10:28:34 -0400 |
commit | b43bdaff3c13fe2273ec407797ff05db89bf3761 (patch) | |
tree | c3fe0f014526741acfcebd81a689c656bc26376f /Source/cmCxxModuleMapper.cxx | |
parent | 02d0f0e752ec9d9ab099c7005a9eedd7bf4b94a1 (diff) | |
download | cmake-b43bdaff3c13fe2273ec407797ff05db89bf3761.tar.gz |
cmCxxModuleMapper: implement support for GCC's module map format
Diffstat (limited to 'Source/cmCxxModuleMapper.cxx')
-rw-r--r-- | Source/cmCxxModuleMapper.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Source/cmCxxModuleMapper.cxx b/Source/cmCxxModuleMapper.cxx index ddb95e38dd..94ad721702 100644 --- a/Source/cmCxxModuleMapper.cxx +++ b/Source/cmCxxModuleMapper.cxx @@ -3,6 +3,8 @@ #include "cmCxxModuleMapper.h" #include <cassert> +#include <sstream> +#include <vector> #include "cmScanDepFormat.h" @@ -15,9 +17,48 @@ cm::optional<std::string> CxxModuleLocations::BmiGeneratorPathForModule( return {}; } +namespace { + +std::string CxxModuleMapContentGcc(CxxModuleLocations const& loc, + cmScanDepInfo const& obj) +{ + std::stringstream mm; + + // Documented in GCC's documentation. The format is a series of + // lines with a module name and the associated filename separated + // by spaces. The first line may use `$root` as the module name + // to specify a "repository root". That is used to anchor any + // relative paths present in the file (CMake should never + // generate any). + + // Write the root directory to use for module paths. + mm << "$root " << loc.RootDirectory << "\n"; + + for (auto const& p : obj.Provides) { + if (auto bmi_loc = loc.BmiGeneratorPathForModule(p.LogicalName)) { + mm << p.LogicalName << ' ' << *bmi_loc << '\n'; + } + } + for (auto const& r : obj.Requires) { + if (auto bmi_loc = loc.BmiGeneratorPathForModule(r.LogicalName)) { + mm << r.LogicalName << ' ' << *bmi_loc << '\n'; + } + } + + return mm.str(); +} +} + cm::static_string_view CxxModuleMapExtension( cm::optional<CxxModuleMapFormat> format) { + if (format) { + switch (*format) { + case CxxModuleMapFormat::Gcc: + return ".gcm"_s; + } + } + return ".bmi"_s; } @@ -25,6 +66,11 @@ std::string CxxModuleMapContent(CxxModuleMapFormat format, CxxModuleLocations const& loc, cmScanDepInfo const& obj) { + switch (format) { + case CxxModuleMapFormat::Gcc: + return CxxModuleMapContentGcc(loc, obj); + } + assert(false); return {}; } |