# Can't export top level lib with dependency on subdir lib

**URL:** https://discourse.cmake.org/t/cant-export-top-level-lib-with-dependency-on-subdir-lib/1084
**Category:** Usage
**Created:** [April 23, 2020, 8:17pm UTC](https://discourse.cmake.org/t/cant-export-top-level-lib-with-dependency-on-subdir-lib/1084 "2020-04-23T20:17:17Z")
**Posts on this page:** 1
**Showing post:** 21

<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 6, 2020, 1:07am UTC](https://discourse.cmake.org/t/cant-export-top-level-lib-with-dependency-on-subdir-lib/1084/21 "2020-05-06T01:07:53Z")

</div>

> [@yisseamake](#):
>
> Since my library dependent on IMPORTED target, the consumers of my library has to use find\_package to find (=IMPORT) in their CMake files

They should just need to do `find_package(yourprogram)`. `yourprogram-config.cmake` does `find_package()` for your dependencies to bring in their imported targets. I usually add them to `cmake` in the source tree and beside `yourpackage-config.cmake` in the build/install tree. Just scope it so your Find modules don’t interfere with the caller’s.

```cmake
set(CMAKE_MODULE_PATH_save "${CMAKE_MODULE_PATH}")
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}")

# Any find_packages you need.

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH_save}")
unset(CMAKE_MODULE_PATH_save)

```

> [@yisseamake](#):
>
> What if external packages does not provide FooConfig.cmake but provides foo.pc file? Should not then pkg\_search\_module /pkg\_check\_module be used instead of find\_package /writing FooFind.cmake? What are pro and contra points?

I’d write a `FindFoo.cmake` that does the `pkg_search_module` inside of it.

---

_[View the full topic](https://discourse.cmake.org/t/cant-export-top-level-lib-with-dependency-on-subdir-lib/1084)._
