summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2022-08-31 15:53:05 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2022-12-02 18:01:21 (GMT)
commit21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3 (patch)
tree4347424a86a7e8e6fb39faedd425676f22ceb849 /Source
parent9c662246684bf649899228d02705440fa4480558 (diff)
downloadCMake-21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3.zip
CMake-21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3.tar.gz
CMake-21b9fb1e8c7348ac4493f4fc245a3c5c5828d2d3.tar.bz2
cmCxxModuleMapper: support the `clang` module map format
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCxxModuleMapper.cxx36
-rw-r--r--Source/cmCxxModuleMapper.h1
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx2
3 files changed, 39 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:
diff --git a/Source/cmCxxModuleMapper.h b/Source/cmCxxModuleMapper.h
index 8526a07..9271978 100644
--- a/Source/cmCxxModuleMapper.h
+++ b/Source/cmCxxModuleMapper.h
@@ -17,6 +17,7 @@
enum class CxxModuleMapFormat
{
+ Clang,
Gcc,
Msvc,
};
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 4500f33..f7753da 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -2567,6 +2567,8 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
cm::optional<CxxModuleMapFormat> modmap_fmt;
if (arg_modmapfmt.empty()) {
// nothing to do.
+ } else if (arg_modmapfmt == "clang") {
+ modmap_fmt = CxxModuleMapFormat::Clang;
} else if (arg_modmapfmt == "gcc") {
modmap_fmt = CxxModuleMapFormat::Gcc;
} else if (arg_modmapfmt == "msvc") {