diff --git a/Source/cmCxxModuleMapper.cxx b/Source/cmCxxModuleMapper.cxx index b6b95404ed..4b2aec7c57 100644 --- a/Source/cmCxxModuleMapper.cxx +++ b/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; +} diff --git a/Source/cmCxxModuleMapper.h b/Source/cmCxxModuleMapper.h index c7850994f9..898396cfae 100644 --- a/Source/cmCxxModuleMapper.h +++ b/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 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); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 612af4f49f..250546fc80 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/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; }