mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-21 21:58:50 -05:00
Fix dependencies on targets linked through object libraries
When an object library is used via `target_link_libraries`, any targets listed in the object library's `INTERFACE_LINK_LIBRARIES` closure should become direct dependencies of the consuming target. However, these were accidentally left out by `cmComputeTargetDepends::CollectTargetDepends` because object libraries are encountered through external object sources first and then added to the `emitted` set which blocks them from being processed as link dependencies. This was not noticed by the test case in commitbab24e782c(target_link_libraries: Propagate dependencies of object libraries, 2018-12-10, v3.14.0-rc1~260^2) because the relevant dependency appears transitively through the object library target itself. Re-order the logic to process link dependencies first, and then external object sources. That way object libraries used via `target_link_libraries` will be treated as such by dependency analysis. This also adds missing backtrace information for object libraries used via `target_link_libraries`. The missing information was mentioned in a FIXME comment in the RunCMake.FileAPI test added by commitea0a060168(fileapi: Add test for codemodel v2, 2018-11-09, v3.14.0-rc1~257^2~7). That comment itself was dropped by commita0de350e2f(FileAPI test: Break gen_check_targets() into JSON files, 2020-02-07), but we can now update the corresponding location in the `.json` files to have the now-expected backtrace information. Fixes: #20421
This commit is contained in:
@@ -5,3 +5,8 @@ add_library(FooObject1 OBJECT FooObject.c)
|
||||
target_link_libraries(FooObject1 PRIVATE FooStatic)
|
||||
add_executable(Transitive1 Transitive.c)
|
||||
target_link_libraries(Transitive1 PRIVATE FooObject1)
|
||||
|
||||
add_library(FooObject2 OBJECT FooObject.c)
|
||||
target_link_libraries(FooObject2 INTERFACE FooStatic)
|
||||
add_executable(Transitive2 Transitive.c)
|
||||
target_link_libraries(Transitive2 PRIVATE FooObject2)
|
||||
|
||||
Reference in New Issue
Block a user