Following modern CMake guidelines (e.g. see https://www.slideshare.net/DanielPfeifer1/effective-cmake, particularly slide 46), I am trying to write out a PkgConfig.cmake
file for my Pkg
.
Pkg
depends on Foo
which in turn depends on Bar
. Neither Foo
nor Bar
have config files - rather I am using FindFoo.cmake
and FindBar.cmake
to find them.
My PkgConfig.cmake
file looks like this
set(Pkg_LIBRARIES Pkg::Pkg)
include(CMakeFindDependencyMacro)
find_dependency(Foo) # Use FindFoo.cmake find and import as target Foo::Foo
# Foo depends on Bar which is similarly imported using
# FindBar.cmake as target Bar::Bar
include("${CMAKE_CURRENT_LIST_DIR}/PkgTargets.cmake")
My resultant PkgTargets.cmake
looks like
add_library(Pkg::Pkg STATIC IMPORTED_
set_target_properties(Pkg::Pkg PROPERTIES
INTERFACE_LINK_LIBRARIES "Foo::Foo")
# Load information for each installed configuration
.
.
.
My question is how can I avoid other packages importing Pkg
into their project from having to specify where Foo
and more importantly where Bar
is to be found?
Doesn't it defeat the purpose of building transitive dependencies if the locations of Foo
and Bar
packages have to be specified again either through variables Foo_ROOT
and Bar_ROOT
or CMAKE_PREFIX_PATH
?
My Pkg already knows where it was found, so should I parse/set Foo_ROOT
and Bar_ROOT
and put it into my PkgConfig.cmake
file?