Use full paths in compile_commands.json for out of source builds.
Clang tooling requires that paths in the directory and file JSON fields are relative to the directory field, but clang doesn't normalize the paths already. The result is that clang doesn't find the relevant entry for files which begin with ../.
This commit is contained in:
parent
1d8199ffec
commit
e30d46e20e
|
@ -644,13 +644,22 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand(
|
|||
*this->CompileCommandsStream << "," << std::endl;
|
||||
}
|
||||
|
||||
std::string sourceFileName = sourceFile;
|
||||
if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
|
||||
{
|
||||
sourceFileName = cmSystemTools::CollapseFullPath(
|
||||
sourceFileName.c_str(),
|
||||
this->GetCMakeInstance()->GetHomeOutputDirectory());
|
||||
}
|
||||
|
||||
|
||||
*this->CompileCommandsStream << "\n{\n"
|
||||
<< " \"directory\": \""
|
||||
<< cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
|
||||
<< " \"command\": \""
|
||||
<< cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
|
||||
<< " \"file\": \""
|
||||
<< cmGlobalGenerator::EscapeJSON(sourceFile) << "\"\n"
|
||||
<< cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n"
|
||||
<< "}";
|
||||
}
|
||||
|
||||
|
|
|
@ -492,6 +492,15 @@ cmNinjaTargetGenerator
|
|||
std::string escapedSourceFileName =
|
||||
this->LocalGenerator->ConvertToOutputFormat(
|
||||
sourceFileName.c_str(), cmLocalGenerator::SHELL);
|
||||
|
||||
if (!cmSystemTools::FileIsFullPath(escapedSourceFileName.c_str()))
|
||||
{
|
||||
escapedSourceFileName = cmSystemTools::CollapseFullPath(
|
||||
escapedSourceFileName.c_str(),
|
||||
this->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory());
|
||||
}
|
||||
|
||||
|
||||
compileObjectVars.Source = escapedSourceFileName.c_str();
|
||||
compileObjectVars.Object = objectFileName.c_str();
|
||||
compileObjectVars.Flags = vars["FLAGS"].c_str();
|
||||
|
|
Loading…
Reference in New Issue