# Findmodule transitivity?

**URL:** https://discourse.cmake.org/t/findmodule-transitivity/4333
**Category:** Usage
**Created:** [October 25, 2021, 8:30am UTC](https://discourse.cmake.org/t/findmodule-transitivity/4333 "2021-10-25T08:30:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [October 25, 2021, 8:30am UTC](https://discourse.cmake.org/t/findmodule-transitivity/4333/1 "2021-10-25T08:30:41Z")

</div>

Hi,

I have a library project A that depend on a third-party library B that is not properly packaged (I can’t use find\_package directly on it).  
Thus I wrote a FindB.cmake file whose path I give to A, using the variable CMAKE\_MODULE\_PATH.

I now have a different project C (an application) that make use of A.  
find\_package(A) succeed but I’ve got the following error:  
CMake Error at …/cmake-3.19/Modules/CMakeFindDependencyMacro.cmake:47 (find\_package):  
By not providing “FindB.cmake” in CMAKE\_MODULE\_PATH this project  
has asked CMake to find a package configuration file provided by  
“B”, but CMake did not find one.

Could not find a package configuration file provided by “B” with  
any of the following names:

```
BConfig.cmake
b-config.cmake

```

…

Does it mean that B locations were not properly propagate through the package A? Do I need to explicitly give FindB.cmake to C? Or do I do something wrong? In which case, what is the proper way to propagate a dependency “wrapped” with a FindModule file?

Regards,  
A.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [October 26, 2021, 7:18pm UTC](https://discourse.cmake.org/t/findmodule-transitivity/4333/2 "2021-10-26T19:18:09Z")

</div>

perhaps this blog may help you: [https://crascit.com/2015/02/02/cmake-target-dependencies/](https://crascit.com/2015/02/02/cmake-target-dependencies/)

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [October 28, 2021, 3:09pm UTC](https://discourse.cmake.org/t/findmodule-transitivity/4333/3 "2021-10-28T15:09:16Z")

</div>

Hi,

Thanks for the link but it puzzles me in two ways:  
1- I think I already understood an applied the concepts in this blog  
2- I don’t understand the specific boost example  
indeed, even if foo does not use Boost binaries, it is declared anyway as a dependency that will be propagated to gumby  
bar uses boost headers internally but it is not said that it uses it in its interface so why target\_include\_directories(bar PUBLIC ${Boost\_INCLUDE\_DIRS})  
instead of  
target\_include\_directories(private PUBLIC ${Boost\_INCLUDE\_DIRS})  
gumby uses parts of bar in its interface but not internally  
why not  
target\_link\_libraries(gumby PRIVATE foo INTERFACE bar) ?

Anyway, it does not speak about my FindModule issue: When I “find\_package” a target A that depends at least privately on another one B that can be found by a FindModule.cmake, clients of my target need to link against B transitively but the link fails as B is not found (dependencies info within package A does not seem to describe the target B but only declare a dependency)  
it seems that, if C depends on A that depends on B, when in C Cmakelist I do find\_package(A), cmake does not import B but calls find\_package(B) which fails as from C CMakeList, FindB.cmake is unknown

Am I wrong ?  
Otherwise, is there a good practice with respect to FindModule.cmake location and CMake\_Module\_Path setting?

Thanks,  
A.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [October 29, 2021, 10:00am UTC](https://discourse.cmake.org/t/findmodule-transitivity/4333/4 "2021-10-29T10:00:45Z")

</div>

Hi,

in general [find\_package(… CONFIG …)](https://cmake.org/cmake/help/v3.22/command/find_package.html#search-procedure) should be used to find exported `cmake config packages`.

Each packages should export its `compile options`, `include directories`, and sure its `direct link dependencies`.

If everything is **PUBLIC** or **INTERFACE** exported, it works fine. But, every packages must be properly installed!

A more academic example is this: [minijson\_reader/CMakeLists.txt at feature/use-string-buffer · ClausKlein/minijson\_reader · GitHub](https://github.com/ClausKlein/minijson_reader/blob/feature/use-string-buffer/CMakeLists.txt) which use [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to make the fetching of dependencies much easier.

The general behaviour is documented in the [CMake using-dependencies-guide](https://cmake.org/cmake/help/v3.22/guide/using-dependencies/index.html)  
and [importing-exporting-guid](https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html)

I hope this helps you  
Claus

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [October 31, 2021, 5:50pm UTC](https://discourse.cmake.org/t/findmodule-transitivity/4333/5 "2021-10-31T17:50:56Z")

</div>

> [@adaldev](#):
>
> In which case, what is the proper way to propagate a dependency “wrapped” with a FindModule file?

You should use `find_package(... CONFIG ...)` variant and your TPL packages should be fixed to export the `CMake config package` right with their own dependencies!

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [November 2, 2021, 10:42am UTC](https://discourse.cmake.org/t/findmodule-transitivity/4333/6 "2021-11-02T10:42:07Z")

</div>

Thanks for your feedback.

My issue with inherited dependency through a FindModule.cmake is not solved by I have a few tracks to follow.

Regards  
A.
