summaryrefslogtreecommitdiffstats
path: root/Source/cmCxxModuleMapper.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-12-06 13:04:07 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-12-06 13:04:18 (GMT)
commitf1f064b7b2c93048897014e096217e1a00f668c7 (patch)
tree6cd0ff2dbc453a45105743af22556072a1231ada /Source/cmCxxModuleMapper.cxx
parent85d89ca88586be09e940fea938d2a2add5dd4425 (diff)
parent2c558cfd1b26e879bf6acce619255ca7b1ba0425 (diff)
downloadCMake-f1f064b7b2c93048897014e096217e1a00f668c7.zip
CMake-f1f064b7b2c93048897014e096217e1a00f668c7.tar.gz
CMake-f1f064b7b2c93048897014e096217e1a00f668c7.tar.bz2
Merge topic 'cxx-module-map-clang'
2c558cfd1b gitlab-ci: add CI jobs for Clang with C++20 modules abd42e9cfc ci: add a Docker container for clang support of C++20 modules 51093f3002 Clang-FindBinUtils: also find `clang-scan-deps` 0b333de923 ci: add C++ module rules file for Clang 21b9fb1e8c cmCxxModuleMapper: support the `clang` module map format 9c66224668 cmNinjaTargetGenerator: skip setting `depfile` for `none` scantypes 9123a0991f cmNinjaTargetGenerator: use `.clear()` to empty out some strings Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Cristian Adam <cristian.adam@gmail.com> Merge-request: !7978
Diffstat (limited to 'Source/cmCxxModuleMapper.cxx')
-rw-r--r--Source/cmCxxModuleMapper.cxx36
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: