Browse Source

Ninja: Fix object path quoting in compilation database

For the compile_commands.json file the object file path needs to
be escaped as well, just like the source path. Otherwise tools like
clangd might not be able to parse the commandline properly.
Sander Cox 1 year ago
parent
commit
ad10c31845
1 changed files with 4 additions and 1 deletions
  1. 4 1
      Source/cmNinjaTargetGenerator.cxx

+ 4 - 1
Source/cmNinjaTargetGenerator.cxx

@@ -2273,7 +2273,10 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
   }
 
   compileObjectVars.Source = escapedSourceFileName.c_str();
-  compileObjectVars.Object = objectFileName.c_str();
+  std::string escapedObjectFileName =
+    this->LocalGenerator->ConvertToOutputFormat(objectFileName,
+                                                cmOutputConverter::SHELL);
+  compileObjectVars.Object = escapedObjectFileName.c_str();
   compileObjectVars.ObjectDir = objectDir.c_str();
   compileObjectVars.ObjectFileDir = objectFileDir.c_str();
   compileObjectVars.Flags = fullFlags.c_str();