Commit b083efd
pkg-config file: fix handling of variable-relative paths
In order to handle cross compilation and other concerns, pkg-config
files support defining includedir/libdir relative to prefix and perform
deferred expansion. For this reason, the expected value of each is:
${prefix}/lib
${prefix}/include
or similar.
This may or may not work depending on how the standard directories are
installed:
- autotools
all directory variables must be specified by absolute path. However,
those variables use the same format as pkg-config to do expansions, so
it is possible to pass --libdir='${prefix}/lib' and generate correct
pkg-config files
- meson
all directory variables can be specified by either relative or
absolute path. For absolute paths, if they fit inside prefix they are
converted to relative paths. There is also a builtin `join_paths`
function that correctly handles path joining for both relative and
absolute paths. The builtin pkg-config generator always generates
correct pkg-config files no matter how you specify directory
variables, and it is possible to manually define paths as:
join_paths('${prefix}', get_option('libdir'))
- cmake
all directory variables can be specified by either relative or
absolute path. No post-processing is done, so CMAKE_INSTALL_LIBDIR may
be relative or absolute, but CMAKE_INSTALL_FULL_LIBDIR is always
absolute. If you must have a relative path, you cannot get one.
Unfortunately, cmake has neither of the coping mechanisms of meson or
autotools. So some manual work is needed in order to generate correct
pkg-config files. The following assumption must be made:
- this will only be correct if the user configures cmake using relative
paths
We also need a shared third-party function to reimplement join_paths
semantics, available from:
https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files
Using this we can guarantee that directory variables are always expanded
to one of two things:
- a "technically incorrect" full path such as `/usr/lib` if the user
configured with full paths
- a spec compliant path such as `${prefix}/lib` if the user configured
with relative paths
Although this isn't always perfect, it allows -- like autotools --
having fully correct pkg-config files as long as the user configures the
build system the "correct" way (relative paths), and in the event that a
sub-optimal configuration is used (full paths) a working but sub-optimal
pkg-config file is generated.
This fixes the case where previously, if a user configured with full
paths the generated pkg-config file ended up with directory variables
such as:
prefix=/usr
libdir=${prefix}/usr/lib
includedir=${prefix}/usr/include
Using a proper join_paths() function guarantees that if the
CMAKE_INSTALL_* variables are absolute paths already, the `${prefix}` is
not prepended to them.1 parent 298cc53 commit b083efd
3 files changed
Lines changed: 32 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
97 | 104 | | |
98 | 105 | | |
99 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments