# install(EXPORT) complains that a dependency is in multiple export sets

**URL:** https://discourse.cmake.org/t/install-export-complains-that-a-dependency-is-in-multiple-export-sets/8218
**Category:** Code
**Created:** [May 25, 2023, 4:49pm UTC](https://discourse.cmake.org/t/install-export-complains-that-a-dependency-is-in-multiple-export-sets/8218 "2023-05-25T16:49:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Dylan\_Reedy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dylan_reedy/32/1533_2.png) [@Dylan\_Reedy](https://discourse.cmake.org/u/Dylan_Reedy)
#### Post date: [May 25, 2023, 4:49pm UTC](https://discourse.cmake.org/t/install-export-complains-that-a-dependency-is-in-multiple-export-sets/8218/1 "2023-05-25T16:49:15Z")

</div>

I have a project, Foo, which depends on another project, Bar. Bar creates multiple targets, which I add to a single export set via a macro thusly:

```auto
add_library(Bar::${TARGET_NAME} ALIAS ${TARGET_NAME})

# do things like target_include_directories(...)

install(TARGETS ${TARGET_NAME}
    EXPORT Bar
    DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(EXPORT Bar
    DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/Bar
    NAMESPACE Bar::
    FILE BarConfig.cmake
)

```

In project Foo, I add Bar with FetchContent and create an export set for Foo as well, thusly:

```auto
install(EXPORT Foo
    DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/Foo
    NAMESPACE Foo::
    FILE FooConfig.cmake
)

```

However, I get an error:

```auto
CMake Error: install(EXPORT "Foo" ...) includes target "Foo-lib" which requires target "Bar-lib" that is not in this export set, but in multiple other export sets:

...

```

In this error, it lists many many locations where BarConfig.cmake definitely does not exist:

- /usr/local/lib/cmake/Bar/Bar.cmake
- /usr/local/lib/cmake/Bar/BarConfig.cmake
- and on and on, something like ~10-15 locations

I have no idea what’s going on here, or why it thinks there are so many Bar export sets.

---

<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: [May 29, 2023, 1:55pm UTC](https://discourse.cmake.org/t/install-export-complains-that-a-dependency-is-in-multiple-export-sets/8218/2 "2023-05-29T13:55:20Z")

</div>

> [@Dylan\_Reedy](#):
>
> Bar creates multiple targets, which I add to a single export set via a macro thusly:

Do you `install(EXPORT)` in the macro for each target? It should be done only once after all of the targets have been added to it (effectively “closing” the export set).

Does `Bar` do its own target exporting? If so, you may need to suppress that.

---

<div class="post-metadata">

### Author: ![Dylan\_Reedy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dylan_reedy/32/1533_2.png) [@Dylan\_Reedy](https://discourse.cmake.org/u/Dylan_Reedy)
#### Post date: [August 28, 2023, 8:42pm UTC](https://discourse.cmake.org/t/install-export-complains-that-a-dependency-is-in-multiple-export-sets/8218/3 "2023-08-28T20:42:04Z")

</div>

Sorry, I got pulled onto a different problem at work and completely forgot about this thread. I was in fact calling the macro for each target, and `Bar` was also doing its own target exporting. Thanks for the assistance many moons ago!
