# Export sets with targets in subdirectory

**URL:** <https://discourse.cmake.org/t/export-sets-with-targets-in-subdirectory/1694>\
**Category:** Code\
**Created:** [August 12, 2020, 6:52pm UTC](https://discourse.cmake.org/t/export-sets-with-targets-in-subdirectory/1694 "2020-08-12T18:52:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpb](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/e5b9ba/32.png) [@tpb](https://discourse.cmake.org/u/tpb)\
**Post date:** [August 12, 2020, 6:52pm UTC](https://discourse.cmake.org/t/export-sets-with-targets-in-subdirectory/1694/1 "2020-08-12T18:52:13Z")

</div>

I am attempting to install my project foo which has a dependency bar which is included as a git submodule and consumed in my cmake project via `add_subdirectory(bar)`. bar is a library that is intended to be consumed via `add_subdirectory` or via a system installation and `find_project(bar)`. However, during the generate step I get the following error:

```auto
CMake Error in src/CMakeLists.txt:
export called with target "foo" which requires target "bar" that is not in any export set.

```

My installation-relevant CMake lines are:

```auto
include(GNUInstallDirs)
install( TARGETS foo EXPORT fooTargets
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT fooTargets FILE foo-targets.cmake DESTINATION share/cmake/foo)

```

the ‘bar’ library includes installation instructions similar to foo, just swapping foo for bar.

I would like to keep the installations of foo and bar separate, as bar has its own dependencies that are consumed from system installations via `find_package` or `find_dependency` and I would like to avoid having to copy bar’s `find_dependency` calls in bar-config.cmake into foo-config.cmake.

---

<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:** [January 4, 2021, 3:13pm UTC](https://discourse.cmake.org/t/export-sets-with-targets-in-subdirectory/1694/2 "2021-01-04T15:13:30Z")

</div>

That should be possible. It just seems that the `bar` subproject is missing/skipping an `install(EXPORT)` for the export set it uses.
