#1121850 cmake: Debian cross builds fail when using cmake_pkg_config

Package:
cmake
Source:
cmake
Description:
cross-platform, open-source make system
Submitter:
Helmut Grohne
Date:
2025-12-03 23:37:01 UTC
Severity:
normal
Tags:
#1121850#5
Date:
2025-12-03 14:28:52 UTC
From:
To:
Hi Timo and others,

CMake gained a new "cmake_pkg_config". It's not a macro, but a builtin
and it effectively reimplements pkgconf and pkg-config. As with many
reimplementations, this one also is feature-incomplete. When performing
a Debian package cross build, cmake_pkg_config fails to locate
dependencies, because it ends up using the build architecture .pc search
path. For example, when building endless-sky, minizip is not found
despite being properly installed.

It is not clear how to fix this. debhelper export the PKG_CONFIG
environment variable and sets both CMake variables PKG_CONFIG_EXECUTABLE
and PKGCONFIG_EXECUTABLE, but apparently that is not enough. When I
looked into it, it seemed as if it were actually querying
CMAKE_PKG_CONFIG_BIN, but setting that doesn't make it work either. It
is fairly evident from a failing build log by looking at the resulting
CMAKE_PKG_CONFIG_PC_LIB_DIRS. On the flip side, setting
CMAKE_PKG_CONFIG_PC_LIB_DIRS=/usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig;/usr/share/pkgconfig
makes cmake_pkg_config work. The recommended way to properly discover
this value is pkg-config --variable=pc_path pkg-config, but this gives
us the path for pkg-config's architecture. It is where pkgconf stops
being Multi-Arch:foreign:

$ bash -c 'exec -a aarch64-linux-gnu-pkgconf pkgconf --variable=pc_path pkg-config'
/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
$

So it's not that obvious how to communicate this to CMake and where to
do this. For instance, extending debhelper with yet another assignment
may be a sensible option.

So for now, I'm documenting the problem hoping that others chime in and
provide feedback on how this is supposed to work in theory.

Helmut

#1121850#14
Date:
2025-12-03 18:12:44 UTC
From:
To:
Hi Helmut and others!

I had anticipated this to CMake upstream when this feature was
originally being developed, and my concerns were somewhat dismissed :/

Please have a look at the full conversation in upstream's issue tracker,
at <https://gitlab.kitware.com/cmake/cmake/-/issues/26067>

Bye!

#1121850#23
Date:
2025-12-03 23:29:48 UTC
From:
To:
It looks like upstream has *almost* addressed this problem by
refactoring the statically compiled virtual packages into something that
could use the cross build personality (but does not yet):

https://github.com/pkgconf/pkgconf/commit/ef935a6349b82259513a1f0cc0cc3180f34a34f5

#1121850#28
Date:
2025-12-03 23:34:46 UTC
From:
To:
On Thu, 4 Dec 2025 00:29:48 +0100 Timo =?utf-8?Q?R=C3=B6hling?= <roehling@debian.org> wrote:
https://github.com/pkgconf/pkgconf/commit/2bfd36beb4d48d178f1521300ee57a3b96d95dd1

In other words, this issue might resolve itself with the next pkgconf
release.