[cmake] Make pkg-config files relocatable - #6471
Conversation
fallenmi
left a comment
There was a problem hiding this comment.
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.
Problem
PCL's pkg-config templates expand
CMAKE_INSTALL_PREFIXwhile the project is being configured. The resulting.pcfiles 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
PKGCONFIG_PREFIXinPCL_MAKE_PKGCONFIG..pctemplates.pcl_*.pcfile against the expected prefix for the configured installation layout.Results
With the default
lib/pkgconfiglayout, generated files now contain:A deeper relative layout such as
lib/custom/pkgconfigproduces: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_commonand the reported include flags both resolve against the new location.Validation
pcl_commontarget successfully.git diff --check.The complete
global_testsconfiguration was not available locally because the environment does not contain the GoogleTest source package required byFindGTestSource. The new regression is a standalone CMake script and was executed directly for all three layouts.Fixes #4240.