diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2022-10-28 15:42:24 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2022-10-28 17:54:43 (GMT) |
commit | 887a8874c343e88ccfca4098584cea91ab8138e6 (patch) | |
tree | 1deb703c267fa45069c16d30cafbb706a5970408 | |
parent | 5e1c5425651b215dbee89e46e146e87d10df268f (diff) | |
download | CMake-887a8874c343e88ccfca4098584cea91ab8138e6.zip CMake-887a8874c343e88ccfca4098584cea91ab8138e6.tar.gz CMake-887a8874c343e88ccfca4098584cea91ab8138e6.tar.bz2 |
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`).
-rw-r--r-- | Help/release/dev/compile-commands-output-field.rst | 7 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 7 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.cxx | 6 | ||||
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.h | 3 | ||||
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 3 | ||||
-rw-r--r-- | Tests/RunCMake/NinjaMultiConfig/CompileCommands-check.cmake | 6 |
8 files changed, 27 insertions, 10 deletions
diff --git a/Help/release/dev/compile-commands-output-field.rst b/Help/release/dev/compile-commands-output-field.rst new file mode 100644 index 0000000..110fd4e --- /dev/null +++ b/Help/release/dev/compile-commands-output-field.rst @@ -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. diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 077de42..395372b 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -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 */ } diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index defa264..dac1c52 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -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. diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 21aa89c..bf9e40e 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -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() diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index b9d333e..92e567a 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -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; } diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index d19bbb9..c5c5490 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -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 diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index e4427f5..cf8c844 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -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) diff --git a/Tests/RunCMake/NinjaMultiConfig/CompileCommands-check.cmake b/Tests/RunCMake/NinjaMultiConfig/CompileCommands-check.cmake index a1ae6ac..30b24bf 100644 --- a/Tests/RunCMake/NinjaMultiConfig/CompileCommands-check.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/CompileCommands-check.cmake @@ -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)" } ]$]==]) |