Skip to content

fileapi: Distinguish between direct and transitive link dependencies

Currently, the includes and dependencies entries in the codemodel version 2 target object do not distinguish between dependencies that were explicitly defined and transitive dependencies that were pulled in automatically. For example:

add_library(BAR)
...


add_library(FOO)
...
target_link_libraries(FOO PUBLIC BAR)


add_executable(MYPROGRAM)

target_link_libraries(MYPROGRAM FOO)

The resulting target object will list dependencies as if both FOO and BAR had been explicitly listed in target_link_libraries(MYPROGRAM ..., resulting in something like this:

	"dependencies": [
		{
			"backtrace": 2,
			"id": "FOO::@1e1e126c0f0420494318"
		},
		{
			"backtrace": 2,
			"id": "BAR::@345bf86d895796fe5bed"
		}
         ]

It would be useful to know which targets were explicitly linked and which weren't. My particular use case is for static analysis and automatic refactoring. For example, automatically finding explicitly linked targets that are redundant because they are already implicit dependencies.

Edited by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information