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

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

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9525
diff --git a/Source/cmCxxModuleMapper.cxx b/Source/cmCxxModuleMapper.cxx
index b6b9540..4b2aec7 100644
--- a/Source/cmCxxModuleMapper.cxx
+++ b/Source/cmCxxModuleMapper.cxx
@@ -434,3 +434,17 @@
   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;
+}
diff --git a/Source/cmCxxModuleMapper.h b/Source/cmCxxModuleMapper.h
index c785099..898396c 100644
--- a/Source/cmCxxModuleMapper.h
+++ b/Source/cmCxxModuleMapper.h
@@ -83,6 +83,14 @@
                     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 @@
                                 CxxModuleLocations const& loc,
                                 cmScanDepInfo const& obj,
                                 CxxModuleUsage const& usages);
+
+// Return the open mode required for the modmap file format.
+CxxModuleMapMode CxxModuleMapOpenMode(CxxModuleMapFormat format);
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index f350efa..4ad801f 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -2783,7 +2783,10 @@
         // `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;
       }