I have a package called pi
which consists of several small libraries that I’ve written as components. So for example I can install the package to a project and write
find_package(pi COMPONENTS system-graph yaml-config sdl-systems REQUIRED)
target_link_libraries(<target> PRIVATE pi::system-graph pi::yaml-config pi::sdl-systems)
In this examples, all of these are static libraries, but they each have dependencies on other interface libraries which are also components. For example pi::system-graph
depends on pi::graphs
and pi::yaml-config
depends on pi::containers
and pi::reflection
. In order to get CMake to link the targets without aborting and complaining about missing targets I have to write
find_package(pi COMPONENTS containers reflection graphs
system-graph yaml-config sdl-systems REQUIRED)
target_link_libraries(<target> PRIVATE pi::system-graph pi::yaml-config pi::sdl-systems)
This is mildly frustrating because the project using this library doesn’t directly use the containers
, reflection
or graphs
components. I’ve done a little digging and so far I haven’t been able to find a work-around for this specific use case.
I’ve found this SO answer that suggests using find_dependency
in the config file, but because my dependencies are all part of the same package, they all share the same config file. I also found this answer here that suggests hiding the nested dependency with $<BUILD_INTERFACE:...>
, but I don’t think this would work with interface libraries since it’s all headers.