# How to handle install+target\_link\_libraries+FetchContent

**URL:** https://discourse.cmake.org/t/how-to-handle-install-target-link-libraries-fetchcontent/8087
**Category:** Usage
**Created:** [May 9, 2023, 3:33pm UTC](https://discourse.cmake.org/t/how-to-handle-install-target-link-libraries-fetchcontent/8087 "2023-05-09T15:33:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [May 9, 2023, 3:33pm UTC](https://discourse.cmake.org/t/how-to-handle-install-target-link-libraries-fetchcontent/8087/1 "2023-05-09T15:33:55Z")

</div>

I am having some trouble understanding how this scenario should be handled.

I have a header only library `DepPkg` that is downloaded automatically via `FetchContent` if it is not found on the system. Then my target `MyPkg` has a `target_link_libraries(PUBLIC)` against `DepPkg` becaue it uses `#include <DepPkg>` in the code. Then how do I correctly handle its installation because as far as I’ve tried when installing `MyPkg`, `DepPkg` must also be installed, but that I understand is bad practice because it might overwrite system installed version without it being evident.

Is there a generator expression way to make `DepPkg` an external target that is known to not be installed? In the `Config.cmake.in` it is sufficient to specify `find_dependency(DepPkg)` right?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [May 9, 2023, 10:46pm UTC](https://discourse.cmake.org/t/how-to-handle-install-target-link-libraries-fetchcontent/8087/2 "2023-05-09T22:46:00Z")

</div>

You could install the `DepPkg` dependency in its own install component. Then you can choose at install time whether to install that separate component or not. This should satisfy CMake’s requirement that you install dependencies built by the project.

> [@Lecris](#):
>
> In the `Config.cmake.in` it is sufficient to specify `find_dependency(DepPkg)` right?

It is a minimum requirement. If you combine that with my suggestion to install `DepPkg` as its own component, you should end up where you’re trying to get to.

---

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [May 10, 2023, 4:32am UTC](https://discourse.cmake.org/t/how-to-handle-install-target-link-libraries-fetchcontent/8087/3 "2023-05-10T04:32:19Z")

</div>

Unfortunately that will not work because `DepPkg` is used in the main `#include` and that one is the only target of the project. But even so, the issue is that when you want to configure the CMakeLists with install enable, the configuration fails with “nothing exports…” Because of the public `target_link_libraries `.

I was thinking if there is a generator expression way of altering that part of `target_link_libraries` and maybe some way to convert the dependency targets to an IMPORTED one in order to satisfy `install(EXPORT)`
