find_dependency() fails to find additional components to already found packages
... because its whole body is wrapped in if (NOT ${dep}_FOUND)
.
Use case: my program requires two libraries, libA and libB. libA requires Boost regex module, libB requires Boost program_options. Their Config.cmake files contains calls to find_dependency()
:
find_dependency(Boost COMPONENTS regex)
and
find_dependency(Boost COMPONENTS program_options)
and they test for Boost_REGEX_FOUND
and Boost_PROGRAM_OPTIONS_FOUND
respectively.
Now no matter how I order my find_package(libA)
and find_package(libB)
calls, the second one always fails because Boost_FOUND
is already set when calling find_dependecny(Boost ...)
.
A similar problem arises if my dependency links to a Boost imported target, and I need only boost headers and put find_package(Boost)
earlier than find_package(theDependency)
.