From 5e25ee691af91c6db35b9c61d0be9d6b2483eefc Mon Sep 17 00:00:00 2001 From: Eduard Voronkin Date: Wed, 29 Oct 2025 12:05:15 -0700 Subject: [PATCH] FASTBuild: generate compile_commands If `CMAKE_EXPORT_COMPILE_COMMANDS` is set use FASTBuild's `-compdb` option in order to generate `compile_commands.json` file. Fixes: #27345 --- Source/cmGlobalFastbuildGenerator.cxx | 11 +++++++++-- Tests/RunCMake/CMakeLists.txt | 2 +- .../RunCMake/ExportCompileCommands/RunCMakeTest.cmake | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/cmGlobalFastbuildGenerator.cxx b/Source/cmGlobalFastbuildGenerator.cxx index 3f54d23b1d..87bff2e619 100644 --- a/Source/cmGlobalFastbuildGenerator.cxx +++ b/Source/cmGlobalFastbuildGenerator.cxx @@ -477,11 +477,18 @@ void cmGlobalFastbuildGenerator::Generate() this->GetCMakeInstance()->GetIsInTryCompile()) { return; } + std::string const workingDir = + this->GetCMakeInstance()->GetHomeOutputDirectory(); // Make "rebuild-bff" target up-to-date after the generation. // This is actually a noop, it just asks CMake to touch the generated file // so FASTBuild would consider the target as up-to-date. - AskCMakeToMakeRebuildBFFUpToDate( - this->GetCMakeInstance()->GetHomeOutputDirectory()); + AskCMakeToMakeRebuildBFFUpToDate(workingDir); + + if (this->GlobalSettingIsOn("CMAKE_EXPORT_COMPILE_COMMANDS")) { + std::string output; + ExecuteFastbuildTarget(workingDir, FASTBUILD_ALL_TARGET_NAME, output, + { "-compdb" }); + } } void cmGlobalFastbuildGenerator::AskCMakeToMakeRebuildBFFUpToDate( diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 35ce7e25b5..8652a5c4e2 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -407,7 +407,7 @@ add_RunCMake_test(Configure -DMSVC_IDE=${MSVC_IDE}) add_RunCMake_test(CpsExportImportBuild) add_RunCMake_test(CpsExportImportInstall) add_RunCMake_test(DisallowedCommands) -if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") +if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja|FASTBuild") add_RunCMake_test(ExportCompileCommands) endif() add_RunCMake_test(ExcludeFromAll) diff --git a/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake b/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake index b69163782c..3a7f7816d6 100644 --- a/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake @@ -9,4 +9,7 @@ endif() run_cmake_with_options(BeforeProject -DCMAKE_PROJECT_INCLUDE_BEFORE=BeforeProjectBEFORE.cmake) run_cmake(CustomCompileRule) run_cmake(Properties) -run_cmake(PropertiesGenerateCommand) + +if(NOT RunCMake_GENERATOR STREQUAL "FASTBuild") + run_cmake(PropertiesGenerateCommand) +endif()