# Proper way for a package to propagate CMAKE\_MODULE\_PATH

**URL:** https://discourse.cmake.org/t/proper-way-for-a-package-to-propagate-cmake-module-path/6301
**Category:** Code
**Created:** [August 18, 2022, 5:05pm UTC](https://discourse.cmake.org/t/proper-way-for-a-package-to-propagate-cmake-module-path/6301 "2022-08-18T17:05:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [August 18, 2022, 5:05pm UTC](https://discourse.cmake.org/t/proper-way-for-a-package-to-propagate-cmake-module-path/6301/1 "2022-08-18T17:05:37Z")

</div>

Is there a proper way for a CMake package to propagate variables (in particular, CMAKE\_MODULE\_PATH) to any consuming projects? I’ve got a package that provides some find modules, and in its CMakeLists.txt, it adds the appropriate path to CMAKE\_MODULE\_PATH and everything works as expected. However, if I add this package to a consuming project using FetchContent, and then try to use one of its find modules from the superproject, I get errors that the requested find module isn’t in CMAKE\_MODULE\_PATH.

Is the only answer to have the project containing the find modules set an internal cache variable, and to do

```cmake
list (APPEND CMAKE_MODULE_PATH "${MY_PKG_MODULE_PATH}")

```

from the consuming project? This works, but seems ugly.

---

<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: [August 19, 2022, 2:01pm UTC](https://discourse.cmake.org/t/proper-way-for-a-package-to-propagate-cmake-module-path/6301/2 "2022-08-19T14:01:40Z")

</div>

Rather than forcing `CMAKE_MODULE_PATH` changes on the consumer, I’d just offer the variable for them to use as needed. The way I do it in VTK and ParaView is to modify `CMAKE_MODULE_PATH` locally in the `-config.cmake` and reset it at the end.

Note that things like API modules are best just included unconditionally. What kind of `include()` API are you trying to provide?

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [August 19, 2022, 4:21pm UTC](https://discourse.cmake.org/t/proper-way-for-a-package-to-propagate-cmake-module-path/6301/3 "2022-08-19T16:21:04Z")

</div>

They’re find modules. I can just provide a `MY_PKG_MODULE_PATH` variable for the user, but I would rather have it “just work” after the user calls `find_package(MyPkg)`.
