Browse Source

Merge topic 'cxxmodules-gcc-binary-mode' into release-3.29

9e2f31ec23 cmCxxModuleMapper: add a query for the open mode for the modmap

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9525
Brad King 1 year ago
parent
commit
ea44e63a7c
3 changed files with 29 additions and 1 deletions
  1. 14 0
      Source/cmCxxModuleMapper.cxx
  2. 11 0
      Source/cmCxxModuleMapper.h
  3. 4 1
      Source/cmGlobalNinjaGenerator.cxx

+ 14 - 0
Source/cmCxxModuleMapper.cxx

@@ -434,3 +434,17 @@ std::string CxxModuleMapContent(CxxModuleMapFormat format,
   assert(false);
   return {};
 }
+
+CxxModuleMapMode CxxModuleMapOpenMode(CxxModuleMapFormat format)
+{
+  switch (format) {
+    case CxxModuleMapFormat::Gcc:
+      return CxxModuleMapMode::Binary;
+    case CxxModuleMapFormat::Clang:
+    case CxxModuleMapFormat::Msvc:
+      return CxxModuleMapMode::Default;
+  }
+
+  assert(false);
+  return CxxModuleMapMode::Default;
+}

+ 11 - 0
Source/cmCxxModuleMapper.h

@@ -83,6 +83,14 @@ struct CxxModuleUsage
                     LookupMethod method);
 };
 
+enum class CxxModuleMapMode
+{
+  Text,
+  Binary,
+
+  Default = Text,
+};
+
 // Return the extension to use for a given modulemap format.
 cm::static_string_view CxxModuleMapExtension(
   cm::optional<CxxModuleMapFormat> format);
@@ -101,3 +109,6 @@ std::string CxxModuleMapContent(CxxModuleMapFormat format,
                                 CxxModuleLocations const& loc,
                                 cmScanDepInfo const& obj,
                                 CxxModuleUsage const& usages);
+
+// Return the open mode required for the modmap file format.
+CxxModuleMapMode CxxModuleMapOpenMode(CxxModuleMapFormat format);

+ 4 - 1
Source/cmGlobalNinjaGenerator.cxx

@@ -2806,7 +2806,10 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
         // `cmNinjaTargetGenerator::WriteObjectBuildStatements` and
         // `cmNinjaTargetGenerator::ExportObjectCompileCommand` to generate the
         // corresponding file path.
-        cmGeneratedFileStream mmf(cmStrCat(object.PrimaryOutput, ".modmap"));
+        cmGeneratedFileStream mmf;
+        mmf.Open(cmStrCat(object.PrimaryOutput, ".modmap"), false,
+                 CxxModuleMapOpenMode(*modmap_fmt) ==
+                   CxxModuleMapMode::Binary);
         mmf.SetCopyIfDifferent(true);
         mmf << mm;
       }