What is the right recommendation to upstream for fixing paths in pkg-config files generated by CMake?

It happens quite often that an upstream package built with CMake generates a pkg-config file, which contains paths incompatible with NixOS. For example, upstream may assume CMAKE_INSTALL_LIBDIR is a relative path lib/ and concatenates ${prefix}/lib out of it, while in case of NixOS/nixpkgs it is absolute.
The CMake documentation states unambigously, that CMAKE_INSTALL_* can be relative or absolute and that one should use the CMAKE_INSTALL_FULL_* variables to get an absolute path.

What is the right recommendation to give to upstream if they generate a pkg-config file with paths that break on NixOS?

I was shouted at for suggesting CMAKE_INSTALL_FULL_* instead of an approach defining CMake variables specifically for pkg-config (e.g. libdir_for_pc_file), hence I’m seeking clarification.

If there is consensus, I suggest adding the recommendation to the nixpkgs documentation section on CMake.

cc @jtojnar

It does not really have much to do with Nixpkgs but rather CMake and pkg-config themselves. For Nixpkgs, it is only relevant that this is an issue with upstream build script and thus should be fixed upstream according to our guidelines:

In the interest of keeping our maintenance burden to a minimum, only patches that are unique to nixpkgs should be [placed as .patch files to Nixpkgs].


There are reasons why you want paths in pkg-config files to have interpolated variables – Eli could tell you more about that, I can never remember. And “Concatenating paths when building pkg-config files” section of CMake snips are the best practices I am aware regarding that.

1 Like

If this is the consensus (interpolated variables may make sense, but there was not much feedback/confirmation/etc.), then probably the error message in the check hook should be changed to not suggest CMAKE_INSTALL_FULL_LIBDIR.