[CMake] Full paths for transitive dependencies

Richard Taylor rsjtaylor.github at gmail.com
Mon Mar 16 09:48:13 EDT 2015


Hello, I'm a CMake newbie trying to build a chain of libraries on windows,
let's call them A, B and C

A is a standalone shared library
B is a shared library that depends on A in its headers & implementation
C is a shared library that depends on B (and so implicitly depends on A)

All three export themselves as cmake packages - config generation is
essentially a copy & paste job from
http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file

Each is built and installed in turn.

B uses find_package(A) - The installed location of A's .cmake files is
provided during configuration by setting the A_DIR var.
C is built similarly via find_package(B) and providing the location of the
installed .cmake files for B.

B builds fine and finds & links to it's dependency A using the full
installed path of A.
C finds B, and knows it is dependent on A, but the linker is only passed
the name of A rather than the full path. No additional library paths get
added to the generated project, so the build fails at link time.

Is it normal behaviour that you need to manually specify the location of
all public transitive dependencies somehow, or am I doing something wrong
when exporting targets?

I figured that as B was installed using a known location of A, C should be
able to find A from B's installed configs. Looking at the installed
<targetname>Targets-<config>.cmake from B, it's own location is specified
as a full path (set via IMPORTED_LOCATION_<CONFIG>)

However, only the names of dependent targets are set (via
INTERFACE_LINK_LIBRARIES in <targetname>Targets.cmake)

I guess that's where the problem lies, I'm just not sure how to fix it..

Rich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150316/273ff277/attachment.html>


More information about the CMake mailing list