Static Library Package Configuration: Why is there a need for INTERFACE_LINK_LIBRARIES?

Core Question: Why do consumers of static library packages via find_package require the need to have all the dependencies noted in the INTERFACE_LINK_LIBRARIES property?

In my scenario, I cannot guarantee the environment that was used to create the static library will be the same environment for the consumer of the library. The static library uses target_link_libraries to link to several other static libraries that are pulled in via find_package and FetchContent. With that said, my original thought would be that the consumer would not need to have knowledge of the static library’s dependencies, but when I attempted to find_package it, it provided me the following error:

Found package configuration file:

but it is set to FALSE so package "static_lib" is considered to be NOT found. Reason given by package:
The following imported targets are referenced, but are missing: some dependency.

Can the static library’s package configuration be modified in a manner such that its consumers do not require its INTERFACE_LINK_LIBRARIES? Or am I missing something more fundamental and would be unable to get around this issue?

No one else (more knowledgeable) has replied yet, so I’ll try with my silly explanation.

Why do consumers of static library packages […] need to have all the dependencies

That is because static libraries aren’t actually libraries - they are archives, which contain object files with symbols (functions/variables?), which will be used for the actual linking when building the final target. And when one builds a static library with some dependencies, the resulting binary (archive) will not contain symbols of the dependencies, so those dependencies binaries are also required to be available for the final linking in a consuming project.

I believe, this isn’t specific to CMake, so it might be one of those fundamentals that you’ve mentioned :slight_smile:

I cannot guarantee the environment that was used to create the static library will be the same environment for the consumer of the library

Then you’ll need to ship the dependencies of your static library too, so everything would be in one package.

Can the static library’s package configuration be modified

You can of course manually edit the generated CMake configs of your package to remove items from INTERFACE_LINK_LIBRARIES or add some logic in your project file for removing them from the target properties, but then, while your consumers will be able to configure their projects, later the linking will obviously fail. To remedy that you could probably also manually “repack” your static library and its dependencies into one “super” archive, and that might even work, but I would probably not recommended doing so.

In general, you questions aren’t new, this topic has been discussed many times over the years. Here are also some notes on the matter.