# Is it possible to implicitly find nested component dependencies after installation?

**URL:** <https://discourse.cmake.org/t/is-it-possible-to-implicitly-find-nested-component-dependencies-after-installation/10465>\
**Category:** Code\
**Created:** [March 25, 2024, 5:25am UTC](https://discourse.cmake.org/t/is-it-possible-to-implicitly-find-nested-component-dependencies-after-installation/10465 "2024-03-25T05:25:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josiest](https://discourse.cmake.org/user_avatar/discourse.cmake.org/josiest/32/2208_2.png) [@josiest](https://discourse.cmake.org/u/josiest)\
**Post date:** [March 25, 2024, 5:25am UTC](https://discourse.cmake.org/t/is-it-possible-to-implicitly-find-nested-component-dependencies-after-installation/10465/1 "2024-03-25T05:25:59Z")

</div>

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

```CMake
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

```CMake
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](https://stackoverflow.com/a/50064639/4661269) 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](https://discourse.cmake.org/t/help-with-find-package-with-nested-libs/7014/2) 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.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [April 11, 2024, 12:23am UTC](https://discourse.cmake.org/t/is-it-possible-to-implicitly-find-nested-component-dependencies-after-installation/10465/2 "2024-04-11T00:23:46Z")

</div>

You’ll need to have the component dependency graph somewhere and traverse it to determine which components are actually required. VTK does this, but it only uses a single `EXPORT` set, so all targets are _there_. The targets are then asked about their dependencies from the module properties that exist. What ends up breaking is that unrequested-and-unrequired components don’t have their dependent `find_package` calls made, so their target references fail at generate time.
