CMakeLists: make daedalus-fourier.pc relocatable via ${pcfiledir} #5

Merged
marfrit merged 1 commits from noether/pkgconfig-relocatable-prefix into main 2026-05-23 15:11:20 +00:00
Owner

Fixes a pkg-config bug where the .pc generated by cmake --install --prefix /foo still hard-coded the configure-time CMAKE_INSTALL_PREFIX (typically /usr/local), breaking downstream consumers that build against ad-hoc install trees.

Concrete bite

Encountered today on hertz during the deploy-test of daedalus-v4l2 PRs #21/#22:

$ cmake --install build --prefix /tmp/df-prefix
$ cat /tmp/df-prefix/lib/pkgconfig/daedalus-fourier.pc
prefix=/usr/local         ← WRONG
...

Daemon's pkg_check_modules(DAEDALUS_FOURIER ...) then resolved include path to /usr/local/include (empty on the test host) and main.c failed:

main.c:25:10: fatal error: daedalus.h: No such file or directory

Fix

Write the .pc with prefix=${pcfiledir}/<rel> where <rel> is the configure-time-computed relative path from <prefix>/<libdir>/pkgconfig back to <prefix>. pkg-config substitutes ${pcfiledir} with the actual on-disk location of the .pc at lookup time, so prefix tracks wherever the install tree ends up.

The relative-path computation handles GNUInstallDirs multiarch layouts (Debian's lib/aarch64-linux-gnu) without hard-coding ../...

Verification (hertz Debian trixie, libdir=lib)

prefix=${pcfiledir}/../../

$ pkg-config --variable=prefix daedalus-fourier
/tmp/df-prefix-test/lib/pkgconfig/../../

# Move the install tree:
$ mv /tmp/df-prefix-test /tmp/df-prefix-moved
$ pkg-config --variable=prefix daedalus-fourier
/tmp/df-prefix-moved/lib/pkgconfig/../../   ← tracks the move

Works for cmake --install --prefix /foo, DESTDIR-staged installs, apt package installs, and any test-tree relocation.

Unblocks daedalus-v4l2 daemon out-of-tree builds against local daedalus-fourier installs (the hertz deploy of PRs #21/#22).

Fixes a pkg-config bug where the .pc generated by `cmake --install --prefix /foo` still hard-coded the *configure-time* CMAKE_INSTALL_PREFIX (typically `/usr/local`), breaking downstream consumers that build against ad-hoc install trees. ## Concrete bite Encountered today on hertz during the deploy-test of daedalus-v4l2 PRs #21/#22: ``` $ cmake --install build --prefix /tmp/df-prefix $ cat /tmp/df-prefix/lib/pkgconfig/daedalus-fourier.pc prefix=/usr/local ← WRONG ... ``` Daemon's `pkg_check_modules(DAEDALUS_FOURIER ...)` then resolved include path to `/usr/local/include` (empty on the test host) and main.c failed: ``` main.c:25:10: fatal error: daedalus.h: No such file or directory ``` ## Fix Write the .pc with `prefix=${pcfiledir}/<rel>` where `<rel>` is the configure-time-computed relative path from `<prefix>/<libdir>/pkgconfig` back to `<prefix>`. pkg-config substitutes `${pcfiledir}` with the actual on-disk location of the .pc at lookup time, so prefix tracks wherever the install tree ends up. The relative-path computation handles GNUInstallDirs multiarch layouts (Debian's `lib/aarch64-linux-gnu`) without hard-coding `../..`. ## Verification (hertz Debian trixie, libdir=lib) ``` prefix=${pcfiledir}/../../ $ pkg-config --variable=prefix daedalus-fourier /tmp/df-prefix-test/lib/pkgconfig/../../ # Move the install tree: $ mv /tmp/df-prefix-test /tmp/df-prefix-moved $ pkg-config --variable=prefix daedalus-fourier /tmp/df-prefix-moved/lib/pkgconfig/../../ ← tracks the move ``` Works for `cmake --install --prefix /foo`, DESTDIR-staged installs, apt package installs, and any test-tree relocation. Unblocks daedalus-v4l2 daemon out-of-tree builds against local daedalus-fourier installs (the hertz deploy of PRs #21/#22).
marfrit added 1 commit 2026-05-23 14:55:52 +00:00
The pkg-config file was generated at *configure* time with
`prefix=${CMAKE_INSTALL_PREFIX}`, which captured whatever
CMAKE_INSTALL_PREFIX happened to be set to at `cmake -B build`
time — typically the default `/usr/local`.  `cmake --install
build --prefix /foo` then put the files under /foo but the .pc
still pointed pkg-config at /usr/local/include and /usr/local/lib,
which broke downstream consumers configuring against the install
tree.

Concrete bite encountered today on hertz: the daedalus-v4l2 daemon
CMake configure on a /tmp/df-prefix install tree resolved
DAEDALUS_FOURIER_INCLUDE_DIRS to /usr/local/include (empty path on
the test host), so main.c failed to find <daedalus.h>.

Fix: write the .pc with `prefix=${pcfiledir}/<rel>` where <rel> is
the configure-time-computed relative path from
<prefix>/<libdir>/pkgconfig back to <prefix>.  pkg-config
substitutes ${pcfiledir} with the actual on-disk location of the
.pc at lookup time, so the resolved prefix tracks wherever the
install tree is moved to — including DESTDIR-staged builds, apt
package installs, and ad-hoc `cmake --install --prefix /tmp/foo`
test installs.

The relative-path computation handles GNUInstallDirs layouts that
add multiarch tuples (Debian's lib/aarch64-linux-gnu) without
hard-coding `../..`.  Tested on hertz (Debian trixie, libdir=lib):

  prefix=${pcfiledir}/../../
  ...
  $ pkg-config --variable=prefix daedalus-fourier
  /tmp/df-prefix-test/lib/pkgconfig/../../

  # mv preserves relocation:
  $ mv /tmp/df-prefix-test /tmp/df-prefix-moved
  $ pkg-config --variable=prefix daedalus-fourier
  /tmp/df-prefix-moved/lib/pkgconfig/../../

This unblocks the daedalus-v4l2 daemon out-of-tree builds against
local daedalus-fourier installs and is a prerequisite for tidy
test-rig deployments (per the hertz reload session 2026-05-23).
marfrit merged commit c154253432 into main 2026-05-23 15:11:20 +00:00
marfrit deleted branch noether/pkgconfig-relocatable-prefix 2026-05-23 15:11:21 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: marfrit/daedalus-fourier#5