Merge topic 'fastbuild-imported-objlib' into release-4.2

67dc1dff7c FASTBuild: fix imported object libs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11670
This commit is contained in:
Brad King
2026-02-10 16:31:46 +00:00
committed by Kitware Robot
4 changed files with 37 additions and 3 deletions

View File

@@ -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 +

View File

@@ -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)

View File

@@ -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 $<TARGET_OBJECTS:ExternalObjLib>)

View File

@@ -9,3 +9,4 @@ run_cmake(UnityIsolate)
run_cmake(DisableCaching)
run_cmake(DisableDistribution)
run_cmake(SetCompilerProps)
run_cmake(ImportedObjectLib)