[CMake] make target export file follow symlinks (or something better?)

Andreas Pakulat apaku at gmx.de
Sat Aug 23 05:01:15 EDT 2014


Hi,

On Sat, Aug 23, 2014 at 8:12 AM, Nico Schlömer <nico.schloemer at gmail.com>
wrote:

> Hi all,
>
> I'm linking my shared library against
> ```
> /usr/lib/x86_64-linux-gnu/libhdf5.so -> libhdf5.so.7.0.0
> /usr/lib/x86_64-linux-gnu/libhdf5.so.7 -> libhdf5.so.7.0.0
> /usr/lib/x86_64-linux-gnu/libhdf5.so.7.0.0
> ```
> resulting in the dynamic dependency
> ```
> $ ldd mylib.so.1.0.0  | grep hdf5
> libhdf5.so.7 => /usr/lib/x86_64-linux-gnu/libhdf5.so.7 (0x00007f50179e2000)
> ```
> The export file `mylibTargets.cmake` however lists
> ```
> set_target_properties(mylib PROPERTIES
>   INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
>   INTERFACE_LINK_LIBRARIES "/usr/lib/x86_64-linux-gnu/libhdf5.so"
> )
> ```
> (without the so-version). This is not good since this symlink might
> not be present when I configure a project against mylib. And it
> doesn't have to be either:


Actually it does have to be there (or rather it will be there).


> > All I need is
> `/usr/lib/x86_64-linux-gnu/libhdf5.so.7` as specified by `ldd`.
>

No, what you also need are the headers of that library, i.e. the
'development' part of the library installation. Since those development
parts are usually mutually exclusively installable between different
versions there's going to be only 1 installed. So the .so symlink will be
there and hence the linking will work. If the symlink links to a different
so-version the linker will abort when trying to link against mylib.

The only exception would be if your mylib does not expose any of the API
that hdf5 provides and a user of mylib does not need to know or care that
you're using hdf5. In that case you should drop that library from your
public link interface. That'll automatically drop the imported target in
the export file, as the linker does not need to know what mylib links
against when linking an app against mylib. (at least for shared libraries).

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140823/c66277ce/attachment-0001.html>


More information about the CMake mailing list