How to generate .pc (pkg-config) file supporting --prefix of the cmake --install?

Consider the case where someone creates a tarball archive of your project rather than installing directly from the build tree (e.g.via cmake --install). They might unpack that tarball anywhere, which is both a desirable capability and common practice. In that scenario, you can’t hard-code the absolute path of the install location in the .pc file.

Perhaps a better solution might be to define your prefix=... line in terms of the ${pcfiledir} variable, something like prefix=${pcfiledir}/../... The following link might be helpful:

https://bugs.freedesktop.org/show_bug.cgi?id=62018

2 Likes