Skip to content

[cmake] Make pkg-config files relocatable - #6471

Open
tandede wants to merge 1 commit into
PointCloudLibrary:masterfrom
tandede:fix/relocatable-pkgconfig-prefix
Open

[cmake] Make pkg-config files relocatable#6471
tandede wants to merge 1 commit into
PointCloudLibrary:masterfrom
tandede:fix/relocatable-pkgconfig-prefix

Conversation

@tandede

@tandede tandede commented Aug 24, 2026

Copy link
Copy Markdown

Problem

PCL's pkg-config templates expand CMAKE_INSTALL_PREFIX while the project is being configured. The resulting .pc files therefore retain the path used on the build machine.

This is especially visible in the Windows All-In-One installer: users may select a different installation directory, but the installed pkg-config files continue to reference the packager's original prefix. Moving an installed PCL tree has the same problem.

Approach

For a relative PKGCFG_INSTALL_DIR, derive the package prefix from ${pcfiledir} and the number of path components between the pkg-config directory and the installation root. This keeps the generated file independent of the build-time installation prefix.

Absolute pkg-config destinations retain the previous behavior because they are not necessarily located inside the installation tree.

The computed prefix is shared by both the regular and header-only pkg-config templates.

Changes

  • Compute a relocatable PKGCONFIG_PREFIX in PCL_MAKE_PKGCONFIG.
  • Use it in the regular and header-only .pc templates.
  • Add a CMake regression test that checks every generated pcl_*.pc file against the expected prefix for the configured installation layout.

Results

With the default lib/pkgconfig layout, generated files now contain:

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

A deeper relative layout such as lib/custom/pkgconfig produces:

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

Absolute pkg-config installation directories continue to use the configured CMAKE_INSTALL_PREFIX.

After installing into one directory and moving the complete installation tree, pkg-config --variable=prefix pcl_common and the reported include flags both resolve against the new location.

Validation

  • Configured default, nested relative, and absolute pkg-config installation layouts.
  • Ran the new prefix regression against all three layouts.
  • Confirmed both regular and header-only generated files.
  • Built the pcl_common target successfully.
  • Installed and relocated the default layout, then queried its prefix and include flags with pkg-config.
  • Ran git diff --check.

The complete global_tests configuration was not available locally because the environment does not contain the GoogleTest source package required by FindGTestSource. The new regression is a standalone CMake script and was executed directly for all three layouts.

Fixes #4240.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad info in pkgconfig file

1 participant