1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 02:17:27 +08:00

EXPORT_COMPILE_COMMANDS: add output field

Also write for all configurations from multi-config generators.

This field was added in the Clang 5 documentation and not present in the
Clang 4 documentation (sometime between Dec 2016 and Mar 2017 according
to `web.archive.org`).
This commit is contained in:
Ben Boeckel
2022-10-28 11:42:24 -04:00
parent 5e1c542565
commit 887a8874c3
8 changed files with 27 additions and 10 deletions

View File

@@ -0,0 +1,7 @@
compile-commands-output-field
-----------------------------
* The :prop_tgt:`EXPORT_COMPILE_COMMANDS` target property will now have the
``output`` field in the compile commands objects. This allows multi-config
generators (namely :generator:`Ninja Multi-Config` generator) to contain the
compile commands for all configurations.

View File

@@ -1171,7 +1171,8 @@ void cmGlobalNinjaGenerator::AddAdditionalCleanFile(std::string fileName,
} }
void cmGlobalNinjaGenerator::AddCXXCompileCommand( void cmGlobalNinjaGenerator::AddCXXCompileCommand(
const std::string& commandLine, const std::string& sourceFile) const std::string& commandLine, const std::string& sourceFile,
const std::string& objPath)
{ {
// Compute Ninja's build file path. // Compute Ninja's build file path.
std::string buildFileDir = std::string buildFileDir =
@@ -1205,7 +1206,9 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand(
<< R"( "command": ")" << R"( "command": ")"
<< cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n" << cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
<< R"( "file": ")" << R"( "file": ")"
<< cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n" << cmGlobalGenerator::EscapeJSON(sourceFileName) << "\",\n"
<< R"( "output": ")"
<< cmGlobalGenerator::EscapeJSON(objPath) << "\"\n"
<< "}"; << "}";
/* clang-format on */ /* clang-format on */
} }

View File

@@ -292,7 +292,8 @@ public:
} }
void AddCXXCompileCommand(const std::string& commandLine, void AddCXXCompileCommand(const std::string& commandLine,
const std::string& sourceFile); const std::string& sourceFile,
const std::string& objPath);
/** /**
* Add a rule to the generated build system. * Add a rule to the generated build system.

View File

@@ -143,7 +143,7 @@ void cmGlobalUnixMakefileGenerator3::Generate()
void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand( void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
const std::string& sourceFile, const std::string& workingDirectory, const std::string& sourceFile, const std::string& workingDirectory,
const std::string& compileCommand) const std::string& compileCommand, const std::string& objPath)
{ {
if (!this->CommandDatabase) { if (!this->CommandDatabase) {
std::string commandDatabaseName = std::string commandDatabaseName =
@@ -164,7 +164,9 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
<< "\",\n" << "\",\n"
<< R"( "file": ")" << R"( "file": ")"
<< cmGlobalGenerator::EscapeJSON(sourceFile) << cmGlobalGenerator::EscapeJSON(sourceFile)
<< "\"\n}"; << "\",\n"
<< R"( "output": ")"
<< cmGlobalGenerator::EscapeJSON(objPath) << "\"\n}";
} }
void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2() void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()

View File

@@ -174,7 +174,8 @@ public:
void AddCXXCompileCommand(const std::string& sourceFile, void AddCXXCompileCommand(const std::string& sourceFile,
const std::string& workingDirectory, const std::string& workingDirectory,
const std::string& compileCommand); const std::string& compileCommand,
const std::string& objPath);
/** Does the make tool tolerate .NOTPARALLEL? */ /** Does the make tool tolerate .NOTPARALLEL? */
virtual bool AllowNotParallel() const { return true; } virtual bool AllowNotParallel() const { return true; }

View File

@@ -1031,7 +1031,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
} }
this->GlobalGenerator->AddCXXCompileCommand( this->GlobalGenerator->AddCXXCompileCommand(
source.GetFullPath(), workingDirectory, compileCommand); source.GetFullPath(), workingDirectory, compileCommand, relativeObj);
} }
// See if we need to use a compiler launcher like ccache or distcc // See if we need to use a compiler launcher like ccache or distcc

View File

@@ -1998,7 +1998,8 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
std::string cmdLine = this->GetLocalGenerator()->BuildCommandLine( std::string cmdLine = this->GetLocalGenerator()->BuildCommandLine(
compileCmds, outputConfig, outputConfig); compileCmds, outputConfig, outputConfig);
this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName); this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName,
objectFileName);
} }
void cmNinjaTargetGenerator::AdditionalCleanFiles(const std::string& config) void cmNinjaTargetGenerator::AdditionalCleanFiles(const std::string& config)

View File

@@ -7,7 +7,8 @@ set(expected_compile_commands
]*Debug[^ ]*Debug[^
]*", ]*",
"file": "[^ "file": "[^
]*(/Tests/RunCMake/NinjaMultiConfig/main\.c|\\\\Tests\\\\RunCMake\\\\NinjaMultiConfig\\\\main\.c)" ]*(/Tests/RunCMake/NinjaMultiConfig/main\.c|\\\\Tests\\\\RunCMake\\\\NinjaMultiConfig\\\\main\.c)",
"output": "(CMakeFiles/exe\.dir/Debug/main\.c\.o|CMakeFiles\\\\exe\.dir\\\\Debug\\\\main\.c\.obj)"
}, },
{ {
"directory": "[^ "directory": "[^
@@ -16,7 +17,8 @@ set(expected_compile_commands
]*Release[^ ]*Release[^
]*", ]*",
"file": "[^ "file": "[^
]*(/Tests/RunCMake/NinjaMultiConfig/main\.c|\\\\Tests\\\\RunCMake\\\\NinjaMultiConfig\\\\main\.c)" ]*(/Tests/RunCMake/NinjaMultiConfig/main\.c|\\\\Tests\\\\RunCMake\\\\NinjaMultiConfig\\\\main\.c)",
"output": "(CMakeFiles/exe\.dir/Release/main\.c\.o|CMakeFiles\\\\exe\.dir\\\\Release\\\\main\.c\.obj)"
} }
]$]==]) ]$]==])