When installing to a given prefix, make sure that the .pc file contains that prefix rather than the value of CMAKE_INSTALL_PREFIX that the project was configured with.
cmake: configure libsecp256k1.pc during install #1692
pull purpleKarrot wants to merge 1 commits into bitcoin-core:master from purpleKarrot:pkgconf-install-prefix changing 1 files +6 −2-
purpleKarrot commented at 5:10 PM on June 27, 2025: contributor
-
7106dce6fd
cmake: configure libsecp256k1.pc during install
When installing to a given prefix, make sure that the .pc file contains that prefix rather than the value of CMAKE_INSTALL_PREFIX that the project was configured with.
- real-or-random added the label bug on Jun 27, 2025
- real-or-random added the label build on Jun 27, 2025
-
real-or-random commented at 6:29 PM on June 27, 2025: contributor
Thanks! Can you provide instructions for a test case that is fixed by this?
cc @hebasto
-
hebasto commented at 7:45 PM on June 27, 2025: member
cc @hebasto
I haven't tested this PR yet, but the issue I reported to @purpleKarrot offline can be reproduced on the master branch as follows:
$ cmake -B build $ cmake --build build $ install_dir=$(mktemp -d) $ cmake --install build --prefix $install_dir $ cat ${install_dir}/lib/pkgconfig/libsecp256k1.pc prefix=/usr/local exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include Name: libsecp256k1 Description: Optimized C library for EC operations on curve secp256k1 URL: https://github.com/bitcoin-core/secp256k1 Version: 0.6.1 Cflags: -I${includedir} Libs: -L${libdir} -lsecp256k1Note
prefix=/usr/local, which is obviously incorrect. -
purpleKarrot commented at 8:47 PM on June 27, 2025: contributor
What @hebasto wrote.
Also, when testing this, try installing as
rootand then verify whether you can delete the build directory with non-rootpermission. Also, try installing twice in a row and verify that the second install does not modify the timestamp of the file. - real-or-random approved
-
real-or-random commented at 6:12 AM on June 30, 2025: contributor
ACK 7106dce6fd410043fc297139c6307cb6016d2a7b I verified that it fixes the path in libsecp256k1.pc
- real-or-random merged this on Jun 30, 2025
- real-or-random closed this on Jun 30, 2025
- purpleKarrot deleted the branch on Jun 30, 2025
-
hebasto commented at 12:20 PM on June 30, 2025: member
While working on this issue earlier, I also considered support for relative paths.
I'm not sure how important this case is, but the current solution does not handle relative paths correctly. Consider the following examples:
- using
CMAKE_INSTALL_PREFIXduring configuration:
$ cmake -B build -DCMAKE_INSTALL_PREFIX=../install/a $ cmake --build build $ cmake --install build $ cat ../install/a/lib/pkgconfig/libsecp256k1.pc | head -1 prefix=/home/hebasto/dev/secp256k1/install/a- using the
--prefixoption during installation:
$ cmake -B build $ cmake --build build $ cmake --install build --prefix ../install/b $ cat ../install/b/lib/pkgconfig/libsecp256k1.pc | head -1 prefix=../install/b - using
- hebasto referenced this in commit 68094d6972 on Jun 30, 2025
-
purpleKarrot commented at 2:47 PM on June 30, 2025: contributor
@real-or-random, what @hebasto shows is a severe regression for the use case of creating packages. When building binary packages for distribution, you usually install to a temporary directory and then create a tarball of that directory. Since pkg-config does not support relocatable packages, the
.pcfile needs to contain the location where the tarball will be extracted to, not the location that cmake installs to. The builtin default of/usr/localor the value ofCMAKE_INSTALL_PREFIXis actually more correct than the argument tocmake --install. - Sjors referenced this in commit 1b7453ea88 on Jul 17, 2025
- hebasto referenced this in commit 28310efba4 on Jul 18, 2025
- fanquake referenced this in commit 5600e6fc4b on Jul 22, 2025
- fjahr referenced this in commit b6fc8c52d5 on Jul 24, 2025
- saikiran57 referenced this in commit abe11bd67c on Jul 28, 2025
- janus referenced this in commit e0ffd31e87 on Sep 14, 2025
- vmta referenced this in commit 2b25f561a0 on Sep 21, 2025
- real-or-random referenced this in commit a3733f33c1 on Feb 25, 2026
- github-actions[bot] referenced this in commit 758d4e90b4 on Mar 1, 2026
- github-actions[bot] referenced this in commit 68a2178f22 on Mar 1, 2026
- github-actions[bot] referenced this in commit a8bc1a0b2b on Mar 1, 2026
- 0x000000000019d6689c085ae165831e934ff76 referenced this in commit 3b9450150d on Mar 2, 2026
- csjones referenced this in commit a4d92824ae on Mar 2, 2026