I wrote some header only library, like:
cmake_minimum_required(VERSION 3.10)
add_library(testLib INTERFACE)
...
find_package(GSL REQUIRED)
find_package(Boost 1.32 REQUIRED)
target_link_libraries(testLib INTERFACE Boost::boost GSL::gsl GSL::gslcblas)
and wrote in the testLibConfig.cmake file:
include(CMakeFindDependencyMacro)
find_dependency(GSL)
find_dependency(Boost 1.32)
include("${CMAKE_CURRENT_LIST_DIR}/testLibTargets.cmake")
but when I try to use it like:
find_package(testLib)
I get the error:
Target "importTest" links to target "GSL::gsl" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
and a similar error message for the gslcblas component. However by including the library as
find_package(testLib)
find_package(GSL)
The error message disappears. Notice that a similar knowledge about the used library boost is not needed by the client. Am I doing anything wrong?
The problem seems to be the earlier find_package call. By removing the find_package call (only forwarding the dependency by using find_dependency) no additional find_package call is needed by a client of the interface library. I guess the problem is that the find_dependency really is a macro. By calling find_package first the variables are set to found and no second find_package call is evoked by the client...?