I am creating a header only library (Library A) that includes another library (Library B) using its FindB.cmake file.
I include the FindB.cmake file by having it in a cmake directory and doing:
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_package(B REQUIRED)
target_link_libraries(A INTERFACE B::B)
The tests on Library A all work fine so B is included successfully in A. To make B available to projects that want to include A, I have in my AConfig.cmake.in :
include(CMakeFindDependencyMacro)
find_dependency(B REQUIRED)
But when I try to make an application (App C) that uses Library A (with find_package(A REQUIRED)), I get an error that cmake cannot find the FindB.cmake file. The error goes away if I put the FindB.cmake file in the App C project and include it like I did with Library A, but I don't want people using Library A to need the FindB.cmake file.
Is there a way to make all of the location information from FindB.cmake carry over from Library A to App C without needing to include the actual FindB.cmake file?
FindB.cmakeinto the installation of the library A (e.g. viainstall(FILES)). Note, that results of that script are specific for the machine where it is run. On that machine the script is known to be worked, so you could run the script again, as a part ofAConfig.cmake. It is true that on other machine the script could be absent. But that other machine could have Library B installed under other location, so result of that script on initial machine cannot be used.