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.

@fallenmi fallenmi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review disclosure: this review was prepared with OpenAI Codex assistance for human review before posting.

I reviewed exact head ab5164ab2e98297264e8d3de85d0a9b5c78b8b69 against current master a1e2c4aae1226f5f10feba60f55b3eec0197bcec, including a clean locally synthesized current-base merge because GitHub's merge ref still targets an older base.

The relative-destination handling looks correct: the generated prefix is derived from ${pcfiledir} only when the pkg-config destination is relative, while absolute destinations preserve the previous configured-prefix behavior. An independent relocation oracle showed the exact base continuing to resolve pcl_common to the old install root, while both the exact head and current merge resolve the physically moved tree. Default lib/pkgconfig and nested lib/custom/pkgconfig layouts both resolved to the new root.

I also configured the exact base, head, and current merge from scratch. The added CMake regression passed on head/current merge for default, nested, and absolute layouts across all 17 generated pcl_*.pc files, and git diff --check is clean. The live rollup has 11 successful build/format checks, two neutral optional jobs, and no pending, failing, or action-required check.

No blocking findings.

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

2 participants