Convert pkg-config (.pc) file to relocatable CMake package

Is there a way to convert a pkg-config .pc file into a relocatable CMake package file?

Sometimes we need to move a 3rd party library that has a .pc, which isn’t relocatable. We’d like a reliable way to convert these .pc into the relocatable CMake packages.

Is there a CMake function, method or pattern that I can use to do this.

I know I can do it by hand (and I have), I’m looking for an automated way to do this.

Thank you.

In general, no. For basics, you can look at how FindPkgConfig.cmake does it in its source. Note that beyond “basics”, dependencies should become find_dependency() calls rather than baking in flag selections through any pkgconf combining.