# Exporting packages with a custom Find module

**URL:** https://discourse.cmake.org/t/exporting-packages-with-a-custom-find-module/3820
**Category:** Code
**Created:** [July 23, 2021, 10:41am UTC](https://discourse.cmake.org/t/exporting-packages-with-a-custom-find-module/3820 "2021-07-23T10:41:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![steve2510](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@steve2510](https://discourse.cmake.org/u/steve2510)
#### Post date: [July 23, 2021, 10:41am UTC](https://discourse.cmake.org/t/exporting-packages-with-a-custom-find-module/3820/1 "2021-07-23T10:41:11Z")

</div>

Hello,

I’m currently in the process of creating a CMake export package for a library we develop. This library has a public dependency on several other libraries, one of which doesn’t have package config files or a find module. In order to find this target (lets call it libA for now) we have a custom find module. From what I’ve gathered so far, the way you handle dependencies in the package is to call find\_dependency(package\_name). This obviously won’t work for libA as there isn’t a built in way to find it. I’m just wondering what options I have, I’m thinking I could either:

1. Copy the contents of our custom find module into the config files, so we can create the targets.
2. Install the custom find module along with the library, so find\_dependency will create the targets.

I’m wondering if there is a better/standard way to solve this issue?

---

<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: [July 23, 2021, 11:56am UTC](https://discourse.cmake.org/t/exporting-packages-with-a-custom-find-module/3820/2 "2021-07-23T11:56:11Z")

</div>

I would do something like this:

```cmake
set(_mypackage_module_path_save "${CMAKE_MODULE_PATH}")
list(CMAKE_MODULE_PATH INSERT 0 "${CMAKE_CURRENT_LIST_DIR}/find_modules")

# Find modules

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

```

---

<div class="post-metadata">

### Author: ![steve2510](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@steve2510](https://discourse.cmake.org/u/steve2510)
#### Post date: [July 23, 2021, 1:40pm UTC](https://discourse.cmake.org/t/exporting-packages-with-a-custom-find-module/3820/3 "2021-07-23T13:40:52Z")

</div>

Thank for your response! Can I just confirm this would be installing the libA finder with my library, i.e. the directory for my lib would be something like:

```auto
lib/cmake/MyLib
├── MyLibConfig.cmake
├── MyLibTargets.cmake
├── MyLibConfig-version.cmake
├── find_modules
│ ├── FindLiba.cmake

```

and then within the config file I put the above code

```auto
set(_mypackage_module_path_save "${CMAKE_MODULE_PATH}")
list(CMAKE_MODULE_PATH INSERT 0 "${CMAKE_CURRENT_LIST_DIR}/find_modules")

find_dependency(libA) # uses my installed finder to create liba::liba targets used by this library

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

```

---

<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: [July 23, 2021, 2:00pm UTC](https://discourse.cmake.org/t/exporting-packages-with-a-custom-find-module/3820/4 "2021-07-23T14:00:05Z")

</div>

Yep, that looks like a suitable pattern to me.
