[CMake] Interpackage dependencies - find_package() from package

Thomas Ruschival t.ruschival at gmail.com
Sun Jan 17 04:39:25 EST 2016


Hi,
I have problems understanding how the cmake-buildsystem is supposed to
resolve inter-package dependencies (imported targets form installed
packages).

Let say I have a project with an executable target (e.g. someApp) that
depends on a library (libfoo). While libfoo is built in a separate
project and depends on libbar which is built in another project.
Libbar and libfoo export cmake packages (fooConfig.cmake,
fooVersion.cmake fooTargets.cmake etc.) according to [1] and [3]

I.e.:
someApp->libfoo->libbar

In libfoo:
- find_package(bar CONFIG REQUIRED)
- target_link_libraries(bar::bar)

The packages are installed and found - no problem here.
In FooTargets.cmake the dependency on bar::bar is added to
INTERFACE_LINK_LIBRARIES.

If in someApp I find foo find_package(foo CONFIG REQUIRED)
I get an error: "The following imported targets are referenced, but are
missing: bar::bar"

The current workaround is to manually add in someApp
find_package(bar CONFIG REQUIRED) before
find_package(foo CONFIG REQUIRED)


But in my understanding this find_package(bar) should somehow be
resolved from the package foo - am I wrong?
The client should not have to resolve the entire dependency tree
manually bay adding find_package() in the correct order.
How can this be done?

Do I miss something or does CMake (3.4) just not do what I want it to do
out of the box?

Thanks in advance!
Thomas

I am using the wiki + reference:
[1] https://cmake.org/Wiki/CMake/Tutorials/Packaging
[2] https://cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
and this example:
[3] https://github.com/forexample/package-example




More information about the CMake mailing list