[CMake] RPATH for external library

Pawel Veselov pawel.veselov at gmail.com
Tue May 16 15:32:11 EDT 2017


On Tue, May 16, 2017 at 12:09 PM, Patrick Boettcher
<patrick.boettcher at posteo.de> wrote:
> On Tue, 16 May 2017 11:50:47 -0700
> Pawel Veselov <pawel.veselov at gmail.com> wrote:
>
>> >> I'm trying to make CMake add to the linker RPATH automatically.
>> >> There is a library that is installed in a non-default location.
>> >> I'm discovering the library using PkgConfig (custom
>> >> CMAKE_APPBUNDLE_PATH) and add the library build options to the
>> >> LINK_FLAGS (using set_property).
>> > Instead of setting the LINK_FLAGS to your external library try using
>> > target_link_libraries() with the full path name to the library.
>> That doesn't really play well with FindPkgConfig then. AFAIK, there is
>> no way to ask pkg-config to dish out full libraries paths, one would
>> have to sift through all -l and -L and figure them out...
> Could you switch from pkg-config to find_library() ?

In this case I guess I could. For the record, RPATH kicks in just fine if
adding a module dependency (target-link-libraries pointing to a library
created with add_library)

> I was once in a situation where I could have used pkg-config with a
> custom path to have pkg-config look for the .pc-file. I then switched to
> find_library with the custom-path slightly adapted and it worked at
> least as good as with pkg-config, if not better. For my case.

Right. My reason of preferring pkg-config is because it may have all other
kind of stuff in it that the maintainer thought is necessary. I'd imagine
some .pc files export a boatload of flags for all 3 stages, and I rather not
ignored them. It is also quite important when there are chained dependencies.
AFAIU, find_library() is not capable of tracking down dependencies.


More information about the CMake mailing list