Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information