From 67dc1dff7cb5ff447698bfc5747723ddee0d1531 Mon Sep 17 00:00:00 2001 From: Eduard Voronkin <42834212+Noxybot@users.noreply.github.com> Date: Sun, 8 Feb 2026 14:35:11 -0800 Subject: [PATCH] FASTBuild: fix imported object libs Fixes: #27507 --- Source/cmFastbuildNormalTargetGenerator.cxx | 21 ++++++++++++++++--- .../FASTBuild/ImportedObjectLib-check.cmake | 10 +++++++++ .../FASTBuild/ImportedObjectLib.cmake | 8 +++++++ Tests/RunCMake/FASTBuild/RunCMakeTest.cmake | 1 + 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 Tests/RunCMake/FASTBuild/ImportedObjectLib-check.cmake create mode 100644 Tests/RunCMake/FASTBuild/ImportedObjectLib.cmake diff --git a/Source/cmFastbuildNormalTargetGenerator.cxx b/Source/cmFastbuildNormalTargetGenerator.cxx index 45b172e31c..16be7e95c2 100644 --- a/Source/cmFastbuildNormalTargetGenerator.cxx +++ b/Source/cmFastbuildNormalTargetGenerator.cxx @@ -2073,6 +2073,8 @@ void cmFastbuildNormalTargetGenerator::AppendLinkDeps( for (cmComputeLinkInformation::Item const& item : items) { std::string const feature = item.GetFeatureName(); LogMessage("GetFeatureName: " + feature); + std::string const formatted = + item.GetFormattedItem(item.Value.Value).Value; if (!feature.empty()) { LogMessage("GetFormattedItem: " + item.GetFormattedItem(item.Value.Value).Value); @@ -2083,13 +2085,26 @@ void cmFastbuildNormalTargetGenerator::AppendLinkDeps( if (item.ObjectSource && linkerNode.Type != FastbuildLinkerNode::STATIC_LIBRARY) { // Tested in "ObjectLibrary" test. - auto libName = item.ObjectSource->GetObjectLibrary(); + std::string const libName = item.ObjectSource->GetObjectLibrary(); std::string dep = libName + FASTBUILD_OBJECTS_ALIAS_POSTFIX; if (linkedObjects.emplace(dep).second) { - FastbuildTargetDep targetDep{ std::move(libName) }; + FastbuildTargetDep targetDep{ libName }; targetDep.Type = FastbuildTargetDepType::ORDER_ONLY; preBuildDeps.emplace(std::move(targetDep)); - linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep)); + + cmTarget const* importedTarget = + this->LocalGenerator->GetMakefile()->FindImportedTarget(libName); + // Add direct path to the object for imported target + // since such targets are not defined in fbuild.bff file. + if (importedTarget) { + LogMessage( + cmStrCat("Adding ", formatted, " to LibrarianAdditionalInputs")); + linkerNode.LibrarianAdditionalInputs.emplace_back(formatted); + } else { + LogMessage( + cmStrCat("Adding ", dep, " to LibrarianAdditionalInputs")); + linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep)); + } } } else if (linkerNode.Type == FastbuildLinkerNode::STATIC_LIBRARY) { LogMessage("Skipping linking to STATIC_LIBRARY (" + linkerNode.Name + diff --git a/Tests/RunCMake/FASTBuild/ImportedObjectLib-check.cmake b/Tests/RunCMake/FASTBuild/ImportedObjectLib-check.cmake new file mode 100644 index 0000000000..3eb41f8e18 --- /dev/null +++ b/Tests/RunCMake/FASTBuild/ImportedObjectLib-check.cmake @@ -0,0 +1,10 @@ +# Check that we're linking to an object file on disk +# and not to "-objects" alias (which only exists for non-imported targets). +set(REGEX_TO_MATCH " +.*.Libraries = +.*{ +.*'MyApp_CXX_Objs_1', +.*dummy.o' +.*} +") +include(${RunCMake_SOURCE_DIR}/check.cmake) diff --git a/Tests/RunCMake/FASTBuild/ImportedObjectLib.cmake b/Tests/RunCMake/FASTBuild/ImportedObjectLib.cmake new file mode 100644 index 0000000000..b65f46885a --- /dev/null +++ b/Tests/RunCMake/FASTBuild/ImportedObjectLib.cmake @@ -0,0 +1,8 @@ +add_library(ExternalObjLib OBJECT IMPORTED) +set_target_properties(ExternalObjLib PROPERTIES + IMPORTED_OBJECTS "${CMAKE_CURRENT_SOURCE_DIR}/dummy.o" +) + +add_executable(MyApp main.cpp) + +target_link_libraries(MyApp PRIVATE $) diff --git a/Tests/RunCMake/FASTBuild/RunCMakeTest.cmake b/Tests/RunCMake/FASTBuild/RunCMakeTest.cmake index a258dbfe4e..57f74a2879 100644 --- a/Tests/RunCMake/FASTBuild/RunCMakeTest.cmake +++ b/Tests/RunCMake/FASTBuild/RunCMakeTest.cmake @@ -9,3 +9,4 @@ run_cmake(UnityIsolate) run_cmake(DisableCaching) run_cmake(DisableDistribution) run_cmake(SetCompilerProps) +run_cmake(ImportedObjectLib)