conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.27k stars 981 forks source link

[question] How to generate merged CppInfo data (libs, libdirs etc.) for a given package component? (Conan 2.0) #14683

Closed db4 closed 1 week ago

db4 commented 1 year ago

What is your question?

Say, I require "opencv/4.5.3" and need to fully resolve includedirs, libs, and libdirs for opencv::opencv_imgproc component. For the entire dependency, it's quite easy: cpp_info = self.dependencies["opencv"].cpp_info.aggregated_components() Edit: not exactly, see the corrected code below.

Have you read the CONTRIBUTING guide?

memsharded commented 1 year ago

I think using self.dependencies["opencv"].cpp_info.components["opencv_imgproc"] you get access to that information, is that what you are looking for?

db4 commented 1 year ago

@memsharded I need to walk all dependencies recursively and create the merged CppInfo. For a package, it can be done with

        res = CppInfo(root)
        deps = root.dependencies.host.topological_sort
        deps = [dep for dep in reversed(deps.values())]
        for dep in deps:
            dep_cppinfo = dep.cpp_info.aggregated_components()
            res.merge(dep_cppinfo)

but how to do the same for a package component? (in the example above for opencv::opencv_imgproc)

memsharded commented 2 months ago

Hi @db4

Sorry this was not followed up back then.

it is not very clear what would be the question. If you want all the components aggregated, you can use .aggregated_components, if you want an individual component, then accessing that component .components["opencv_imgproc"] would get access to the data.

db4 commented 1 week ago

Hi @memsharded

I needed aggregated dependencies (e.g. all libs and headers including transitive ones) for a given component. Since then I've done without them, but they could be useful.

memsharded commented 1 week ago

Maybe you need the merge() method in https://docs.conan.io/2/reference/tools/cpp_info.html#aggregating-information-in-custom-generators?

You can iterate self.dependencies and merging all the cpp_info from those dependencies. If you want to limit to a subset of all dependencies for that given component, that subset can be computed from the .requires of that component.

Doesn't sound trivial, but it looks possible. Have you tried that?

db4 commented 1 week ago

Not yet. The question is old enough, I managed to get by with PkgConfigDeps generator. I close the issue right now and may follow your advice in the future. Thanks!