diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-07-02 22:44:17 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-07-09 15:04:29 (GMT) |
commit | 677b28dc7b28feda9efb15ae27a267ec5d709b44 (patch) | |
tree | c861b020877fd5f52bc680e6ac523e1a2ab383a3 /Source | |
parent | b384058e4ba77defdff8741db636f60d6843d87d (diff) | |
download | CMake-677b28dc7b28feda9efb15ae27a267ec5d709b44.zip CMake-677b28dc7b28feda9efb15ae27a267ec5d709b44.tar.gz CMake-677b28dc7b28feda9efb15ae27a267ec5d709b44.tar.bz2 |
Ninja: include module mapper flags in `compile_commands.json`
Fixes: #24618
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 28 |
2 files changed, 27 insertions, 4 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index e20f157..97c9b70 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -2733,7 +2733,8 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( auto mm = CxxModuleMapContent(*modmap_fmt, locs, object, usages); // XXX(modmap): If changing this path construction, change - // `cmNinjaTargetGenerator::WriteObjectBuildStatements` to generate the + // `cmNinjaTargetGenerator::WriteObjectBuildStatements` and + // `cmNinjaTargetGenerator::ExportObjectCompileCommand` to generate the // corresponding file path. cmGeneratedFileStream mmf(cmStrCat(object.PrimaryOutput, ".modmap")); mmf << mm; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 85733e1..d712d71 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1428,8 +1428,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( if (!modmapFormat.empty()) { // XXX(modmap): If changing this path construction, change - // `cmGlobalNinjaGenerator::WriteDyndep` to expect the corresponding file - // path. + // `cmGlobalNinjaGenerator::WriteDyndep` and + // `cmNinjaTargetGenerator::ExportObjectCompileCommand` to expect the + // corresponding file path. std::string ddModmapFile = cmStrCat(objectFileName, ".modmap"); vars["DYNDEP_MODULE_MAP_FILE"] = ddModmapFile; objBuild.OrderOnlyDeps.push_back(ddModmapFile); @@ -1688,11 +1689,32 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( escapedSourceFileName = this->LocalGenerator->ConvertToOutputFormat( escapedSourceFileName, cmOutputConverter::SHELL); + std::string fullFlags = flags; + { + bool const needDyndep = + this->GetGeneratorTarget()->NeedDyndep(language, outputConfig); + std::string const modmapFormatVar = + cmStrCat("CMAKE_EXPERIMENTAL_", language, "_MODULE_MAP_FORMAT"); + std::string const modmapFormat = + this->Makefile->GetSafeDefinition(modmapFormatVar); + if (needDyndep && !modmapFormat.empty()) { + std::string modmapFlags = this->GetMakefile()->GetRequiredDefinition( + cmStrCat("CMAKE_EXPERIMENTAL_", language, "_MODULE_MAP_FLAG")); + // XXX(modmap): If changing this path construction, change + // `cmGlobalNinjaGenerator::WriteDyndep` and + // `cmNinjaTargetGenerator::WriteObjectBuildStatement` to expect the + // corresponding file path. + cmSystemTools::ReplaceString(modmapFlags, "<MODULE_MAP_FILE>", + cmStrCat(objectFileName, ".modmap")); + fullFlags += cmStrCat(' ', modmapFlags); + } + } + compileObjectVars.Source = escapedSourceFileName.c_str(); compileObjectVars.Object = objectFileName.c_str(); compileObjectVars.ObjectDir = objectDir.c_str(); compileObjectVars.ObjectFileDir = objectFileDir.c_str(); - compileObjectVars.Flags = flags.c_str(); + compileObjectVars.Flags = fullFlags.c_str(); compileObjectVars.Defines = defines.c_str(); compileObjectVars.Includes = includes.c_str(); |