[CMake] make target export file follow symlinks (or something better?)
Nico Schlömer
nico.schloemer at gmail.com
Sat Aug 23 12:36:46 EDT 2014
> How do I get LINK_LIBRARIES instead of INTERFACE_LINK_LIBRARIES in the
> target file?
Got it! It's the PRIVATE attribute for TARGET_LINK_LIBRARIES that i need [1].
Cheers,
Nico
[1] http://www.cmake.org/cmake/help/v3.0/command/target_link_libraries.html
On Sat, Aug 23, 2014 at 3:51 PM, Nico Schlömer <nico.schloemer at gmail.com> wrote:
> Hi,
>
> thanks for your concise reply!
>
>> 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.
>
> That is exactly my use case.
>
>> In that case you should drop that library from your public link interface.
>
> Right, it should not be INTERFACE_LINK_LIBRARIES but LINK_LIBRARIES
> [1]. The reason why I do need to have the link libraries is
>
>> (at least for shared libraries).
>
> exactly that: static libs.
> How do I get LINK_LIBRARIES instead of INTERFACE_LINK_LIBRARIES in the
> target file?
>
> --Nico
>
>
> [1] http://www.cmake.org/cmake/help/v3.0/prop_tgt/LINK_LIBRARIES.html
>
>
>
> On Sat, Aug 23, 2014 at 11:01 AM, Andreas Pakulat <apaku at gmx.de> wrote:
>> 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
More information about the CMake
mailing list