Findmodule transitivity?

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.

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

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.

Hi,

in general find_package(… CONFIG …) 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 which use CPM.cmake to make the fetching of dependencies much easier.

The general behaviour is documented in the CMake using-dependencies-guide
and importing-exporting-guid

I hope this helps you
Claus

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!

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.