mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 00:02:21 +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:
7
Help/release/dev/compile-commands-output-field.rst
Normal file
7
Help/release/dev/compile-commands-output-field.rst
Normal 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.
|
@@ -1171,7 +1171,8 @@ void cmGlobalNinjaGenerator::AddAdditionalCleanFile(std::string fileName,
|
||||
}
|
||||
|
||||
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.
|
||||
std::string buildFileDir =
|
||||
@@ -1205,7 +1206,9 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand(
|
||||
<< R"( "command": ")"
|
||||
<< cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
|
||||
<< R"( "file": ")"
|
||||
<< cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n"
|
||||
<< cmGlobalGenerator::EscapeJSON(sourceFileName) << "\",\n"
|
||||
<< R"( "output": ")"
|
||||
<< cmGlobalGenerator::EscapeJSON(objPath) << "\"\n"
|
||||
<< "}";
|
||||
/* clang-format on */
|
||||
}
|
||||
|
@@ -292,7 +292,8 @@ public:
|
||||
}
|
||||
|
||||
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.
|
||||
|
@@ -143,7 +143,7 @@ void cmGlobalUnixMakefileGenerator3::Generate()
|
||||
|
||||
void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
|
||||
const std::string& sourceFile, const std::string& workingDirectory,
|
||||
const std::string& compileCommand)
|
||||
const std::string& compileCommand, const std::string& objPath)
|
||||
{
|
||||
if (!this->CommandDatabase) {
|
||||
std::string commandDatabaseName =
|
||||
@@ -164,7 +164,9 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
|
||||
<< "\",\n"
|
||||
<< R"( "file": ")"
|
||||
<< cmGlobalGenerator::EscapeJSON(sourceFile)
|
||||
<< "\"\n}";
|
||||
<< "\",\n"
|
||||
<< R"( "output": ")"
|
||||
<< cmGlobalGenerator::EscapeJSON(objPath) << "\"\n}";
|
||||
}
|
||||
|
||||
void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
|
||||
|
@@ -174,7 +174,8 @@ public:
|
||||
|
||||
void AddCXXCompileCommand(const std::string& sourceFile,
|
||||
const std::string& workingDirectory,
|
||||
const std::string& compileCommand);
|
||||
const std::string& compileCommand,
|
||||
const std::string& objPath);
|
||||
|
||||
/** Does the make tool tolerate .NOTPARALLEL? */
|
||||
virtual bool AllowNotParallel() const { return true; }
|
||||
|
@@ -1031,7 +1031,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
|
||||
}
|
||||
|
||||
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
|
||||
|
@@ -1998,7 +1998,8 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
|
||||
std::string cmdLine = this->GetLocalGenerator()->BuildCommandLine(
|
||||
compileCmds, outputConfig, outputConfig);
|
||||
|
||||
this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName);
|
||||
this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName,
|
||||
objectFileName);
|
||||
}
|
||||
|
||||
void cmNinjaTargetGenerator::AdditionalCleanFiles(const std::string& config)
|
||||
|
@@ -7,7 +7,8 @@ set(expected_compile_commands
|
||||
]*Debug[^
|
||||
]*",
|
||||
"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": "[^
|
||||
@@ -16,7 +17,8 @@ set(expected_compile_commands
|
||||
]*Release[^
|
||||
]*",
|
||||
"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)"
|
||||
}
|
||||
]$]==])
|
||||
|
||||
|
Reference in New Issue
Block a user