Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the PKG_CONFIG_PATH via CMake build helper or even CMakeToolchain #11962

Closed
prince-chrismc opened this issue Aug 25, 2022 · 3 comments · Fixed by #12513
Closed

add the PKG_CONFIG_PATH via CMake build helper or even CMakeToolchain #11962

prince-chrismc opened this issue Aug 25, 2022 · 3 comments · Fixed by #12513
Assignees
Milestone

Comments

@prince-chrismc
Copy link
Contributor

In conan-io/conan-center-index#12241 there was some wonky code to get the pkg_config support in CMake to work with the new generators

Part of the conversation (and linking to the solutions) seems like it could be continued here


For some reason, pkg_check_modules tries to find .pc files not in the generator_folder, but in the generator_folder/lib/pkgconfig.

After digging deeper into it, I figured out that CMake is adding the suffix lib/pkgconfig to the CMAKE_PREFIX_PATH (pointing to the package_folder where the *.pc files are created). You can have a look at the issue https://gitlab.kitware.com/cmake/cmake/-/issues/18150

I thought the PkgConfigDeps generator should resolve that (via env vars maybe), but it doesn't

Yes, you're right, but it should not be necessary as far as CMake should use that CMAKE_PREFIX_PATH by default. As I said above, CMake is adding that suffix, so it's getting failed because there are no PC files there.

is this the right way to use CMakeToolchain and PkgConfigDeps generators together?

Given that information, I tend to say that yes, it could be one way to solve that issue, and I think there could be another workaround like:

    def build(self):
        pkg_lib_folder = os.path.join(self.generators_folder, "lib", "pkgconfig")
        copy(self, "*.pc", self.generators_folder, pkg_lib_folder)
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

Anyway, we could discuss if it could be a chance to create a mechanism to add the PKG_CONFIG_PATH via CMake build helper or even CMakeToolchain to avoid those workarounds.

Originally posted by @franramirez688 in conan-io/conan-center-index#12241 (comment)

@jwillikers
Copy link
Contributor

I'm trying to support cross-compilation of the glib Conan package and ran into problems with the test package, which uses pkg_check_modules to link against glib. The test package consistently finds the system's PkgConfig files in this scenario instead of those provided by Conan. If I just use the CMake targets from the CMake config modules, cross-compilation works. I think this may be related to this issue.

@prince-chrismc
Copy link
Contributor Author

@franramirez688
Copy link
Contributor

@memsharded A few points about this issue and its possible solutions to discuss them:

  • Via CMakeToolchain: adding this line set(ENV{PKG_CONFIG_PATH} {{ package_folder }} ) directly.
  • Via cmake-presets: adding to the environment section the variable PKG_CONFIG_PATH (I have read some problems about its usage but am not 100% sure).
  • Via CMake build helper: running the environment variable before the cmake command, i.e., PKG_CONFIG_PATH=pc/folder/ cmake xxxxxxxxx.
  • Via VirtualBuildEnv: perhaps, if there would be a kind of method to add it automatically easily. This way could be applied by any other tool as well.

I don't really know what could be the "best way" so I'd prefer to discuss it before starting any draft.

@memsharded memsharded modified the milestones: 1.54, 1.55 Nov 2, 2022
ericLemanissier added a commit to ericLemanissier/conan-center-index that referenced this issue Dec 7, 2022
conan-center-bot pushed a commit to conan-io/conan-center-index that referenced this issue Dec 13, 2022
* use is_mvc

* use CMakeDeps

fixes #13144

* use PkgConfigDeps

* use modern CMake integration

* debug cmake find package

* work arround conan-io/conan#11962

* don't test with qmake on static qt

* fix Invalid character escape

cf conan-io/conan#10539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants