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

GCC (MinGW) wants to use `\n` on Windows too.

Fixes: #25974
stage/master/nightly/2024/05/17
Ben Boeckel 2024-05-16 09:52:38 -04:00
parent 9f7ec4c297
commit 9e2f31ec23
3 changed files with 29 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -2783,7 +2783,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;
}