# Handle custom Findfoo.cmake in dependency

**URL:** https://discourse.cmake.org/t/handle-custom-findfoo-cmake-in-dependency/7178
**Category:** Code
**Created:** [January 2, 2023, 11:07pm UTC](https://discourse.cmake.org/t/handle-custom-findfoo-cmake-in-dependency/7178 "2023-01-02T23:07:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![skcusekamc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/skcusekamc/32/3053_2.png) [@skcusekamc](https://discourse.cmake.org/u/skcusekamc)
#### Post date: [January 2, 2023, 11:07pm UTC](https://discourse.cmake.org/t/handle-custom-findfoo-cmake-in-dependency/7178/1 "2023-01-02T23:07:38Z")

</div>

For my library `bla` I have a `Config.cmake.in` that does a `find_dependency(foo)` because `bla` depends on `foo` and by using `find_dependency(foo)` I can propogate this dependency to any project that uses `bla` via `find_package(bla REQUIRED)`.

This works (the `find_package(bla)` part), however this `foo` dependency is resolved via a **custom** `Findfoo.cmake` file **that is part of the `bla` project and not available to any downstream projects**.

i.e: I install `bla` to `/usr/local/...` via `sudo make install` and it writes a bunch of things:

- The library itself `/usr/local/lib/libbla.so`
- The CMake config file(s) so that `find_package(bla REQUIRED)` is possible under `/usr/local/lib/cmake/bla`

But it does **not** write `Findfoo.cmake` anywhere.

How to handle this so that downstream projects also have access to this custom `Findfoo.cmake` file?

---

<div class="post-metadata">

### Author: ![skcusekamc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/skcusekamc/32/3053_2.png) [@skcusekamc](https://discourse.cmake.org/u/skcusekamc)
#### Post date: [January 3, 2023, 12:03am UTC](https://discourse.cmake.org/t/handle-custom-findfoo-cmake-in-dependency/7178/2 "2023-01-03T00:03:17Z")

</div>

I was able to solve this by installing `Find*.cmake` files to the `cmake` directory:

```cmake
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/"
        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/bla/modules/"
        FILES_MATCHING
        PATTERN "*.cmake"
        )

```

Then in `Config.cmake.in` I can append `modules/` to `CMAKE_MODULE_PATH`:

```cmake
@PACKAGE_INIT@

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules/")

include(CMakeFindDependencyMacro)
find_dependency(foo)

include("${CMAKE_CURRENT_LIST_DIR}/blaTargets.cmake")

check_required_components(bla)

```
