install(EXPORT): carry over find_dependency() for relevant targets
This is a "sub-issue of my more general issue regarding installation automation; it's supposed to be more concrete, focused and actionable
When we write something like:
find_package(bar REQUIRED)
target_link_library(foo PUBLIC bar::bar)
install(TARGETS foo EXPORT foo_export etc. etc.)
export(EXPORT foo_export NAMESPACE "foo::" FILE "foo-config.cmake")
the dependency of foo
on bar
is carried forward into the generated file, and whoever does find_package(foo)
will have that dependency. But - the use of find_package()
is not carried forward. Currently, it's "on us" to somehow insert a find_dependency()
call in the package config file - i.e. we can't just use the generated one, we have to write our own and include the generated one.
My suggestion:
- When a target is introduced, CMake will decorate it with certain properties indicating how it was introduced, specifically whether it was the result of a
find_package()
. - When a target is exported, the above information is also included in whatever data is part of the named export.
- When a
-config.cmake
file is generated for exported targets, this information is used, when relevant, to get the including CMake to also perform relevant actions to ensure dependencies are available. Specifically, in the above example, thefoo-config.cmake
generation will include afind_dependency(bar)
(edit: or maybe even with aREQUIRED
argument?), becausefoo
depends onbar::bar
which in turn was created due to afind_package()
call.
Edited by Eyal Rozenberg