diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2022-08-31 15:53:05 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2022-12-02 18:01:21 (GMT) |
commit | 21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3 (patch) | |
tree | 4347424a86a7e8e6fb39faedd425676f22ceb849 /Source/cmCxxModuleMapper.cxx | |
parent | 9c662246684bf649899228d02705440fa4480558 (diff) | |
download | CMake-21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3.zip CMake-21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3.tar.gz CMake-21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3.tar.bz2 |
cmCxxModuleMapper: support the `clang` module map format
Diffstat (limited to 'Source/cmCxxModuleMapper.cxx')
-rw-r--r-- | Source/cmCxxModuleMapper.cxx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Source/cmCxxModuleMapper.cxx b/Source/cmCxxModuleMapper.cxx index 84691c9..ca4ffdf 100644 --- a/Source/cmCxxModuleMapper.cxx +++ b/Source/cmCxxModuleMapper.cxx @@ -28,6 +28,38 @@ cm::optional<std::string> CxxModuleLocations::BmiGeneratorPathForModule( namespace { +std::string CxxModuleMapContentClang(CxxModuleLocations const& loc, + cmScanDepInfo const& obj) +{ + std::stringstream mm; + + // Clang's command line only supports a single output. If more than one is + // expected, we cannot make a useful module map file. + if (obj.Provides.size() > 1) { + return {}; + } + + // A series of flags which tell the compiler where to look for modules. + + for (auto const& p : obj.Provides) { + if (auto bmi_loc = loc.BmiGeneratorPathForModule(p.LogicalName)) { + // Force the TU to be considered a C++ module source file regardless of + // extension. + mm << "-x c++-module\n"; + + mm << "-fsave-std-c++-module-file=" << *bmi_loc << '\n'; + break; + } + } + for (auto const& r : obj.Requires) { + if (auto bmi_loc = loc.BmiGeneratorPathForModule(r.LogicalName)) { + mm << "-fmodule-file=" << *bmi_loc << '\n'; + } + } + + return mm.str(); +} + std::string CxxModuleMapContentGcc(CxxModuleLocations const& loc, cmScanDepInfo const& obj) { @@ -179,6 +211,8 @@ cm::static_string_view CxxModuleMapExtension( { if (format) { switch (*format) { + case CxxModuleMapFormat::Clang: + return ".pcm"_s; case CxxModuleMapFormat::Gcc: return ".gcm"_s; case CxxModuleMapFormat::Msvc: @@ -297,6 +331,8 @@ std::string CxxModuleMapContent(CxxModuleMapFormat format, CxxModuleUsage const& usages) { switch (format) { + case CxxModuleMapFormat::Clang: + return CxxModuleMapContentClang(loc, obj); case CxxModuleMapFormat::Gcc: return CxxModuleMapContentGcc(loc, obj); case CxxModuleMapFormat::Msvc: |