[CMake] Creating relocatable packages

Zac Bergquist zbergquist99 at gmail.com
Fri Oct 16 16:56:34 EDT 2015


I've created a sample project to replicate my issue in hopes that it would
make it easier to troubleshoot.

Thanks for any help,
Zac

https://github.com/zmb3/cmaketest

On Mon, Oct 12, 2015 at 8:53 AM, Zac Bergquist <zbergquist99 at gmail.com>
wrote:

> Hello,
>
> I'm trying to fix a project so that its output is relocatable.  The
> project is a library that itself depends on libpcap.  My goal is to be able
> to import the library into my CMake application and have CMake
> automatically link libpcap with it.
>
> I'm using a toolchain file that invokes an ARM cross compiler, sets
> CMAKE_INSTALL_PREFIX and appends it to CMAKE_FIND_ROOT_PATH.  This all
> seems to work well.
>
> What I'm seeing is that the exported files that get installed to
> CMAKE_INSTALL_PREFIX contain absolute paths to libpcap on my machine, which
> make them useless to other team members.
>
> The first thing I changed was to use CONFIGURE_PACKAGE_CONFIG_FILE instead
> of CONFIGURE_FILE.  This got rid of absolute paths in the generated CMake
> config file.
>
> However, I still have absolute paths in the CMake target import file that
> gets generated.  The IMPORTED_LINK_INTERFACE_LIBRARIES target property has
> an absolute path instead of one relative to CMAKE_INSTALL_PREFIX.
>
> I've read the "Creating Relocatable Packages" [1] section of the CMake
> packages documentation. I'm pretty sure this is what I'm running into, but
> I don't quite understand how to solve it.  The documentation says that I
> should be using imported targets, but I'm not sure how to do so.  The
> library is just using its own FindPCAP.cmake file to locate libpcap.
>
> Does anyone know of an example of a CMake package that imports other
> libraries?  I could also try to create a minimal example project with this
> setup if it would be helpful.
>
> Thanks,
> Zac
>
> [1]:
> https://cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html#creating-relocatable-packages
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151016/c1648794/attachment.html>


More information about the CMake mailing list