conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
958 stars 1.76k forks source link

[package] coin-clp/1.17.7: cpp_info.libs not populated #25164

Closed philsuess closed 1 month ago

philsuess commented 1 month ago

Description

It seems that some packages, coin-clp is among them, don't populate cpp_info.libs. In the recipe, it says

self.cpp_info.components["clp"].libs = ["ClpSolver", "Clp"]

whereas in the recipe for coin-utils (where everything is populated fine) it says:

self.cpp_info.libs = ["CoinUtils"]

I noticed this because I am writing a generator to produce a dependency info for a rust.rs setup and I use cpp_info to get at libs, libdirs, and includedirs.

Am I missing something?

Package and Environment Details

Conan profile

[settings] os=Linux arch=x86_64 compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 compiler.cppstd=17 build_type=Release

Steps to reproduce

follow steps to create your own generator here: https://docs.conan.io/2/reference/extensions/custom_generators.html#custom-generators-as-python-requires

Then alter the generator conanfile in mygenerator/conanfile.py to the following:

from conan import ConanFile
from conan.tools.files import save

class MyGenerator:
    def __init__(self, conanfile):
        self._conanfile = conanfile

    def generate(self):
        deps_info = ""
        for dep, dep_info in self._conanfile.dependencies.items():
            deps_info += f"{dep.ref.name}, {dep.ref.version}, libs: {dep_info.cpp_info.libs}\n"
            save(self._conanfile, "deps.txt", deps_info)

class PyReq(ConanFile):
    name = "mygenerator"
    version = "1.0"
    package_type = "python-require"

This is the output in deps.txt:

coin-clp, 1.17.7, libs: []
coin-osi, 0.108.7, libs: []
coin-utils, 2.11.9, libs: ['CoinUtils']
bzip2, 1.0.8, libs: ['bz2']
zlib, 1.3.1, libs: ['z']

Note that coin-clp and coin-osi don't populate cpp_info.libs.

Logs

Click to expand log ``` conan create mygenerator conan install . -pr:b gcc11 -pr:h gcc11 ``` gcc11 holds the profile shown above. The result is a dep.txt file with the content shown above.
philsuess commented 1 month ago

I am one step closer to what I need. I can indeed access the components field in cpp_info like this:

        for dep, dep_info in self._conanfile.dependencies.items():
            deps_info += f"{dep.ref.name}, {dep.ref.version}, libs: {dep_info.cpp_info.libs}\n"
            for k, c in dep_info.cpp_info.components.items():
                deps_info += f"\t more libs found via components: {c.libs}\n"
            save(self._conanfile, "deps.txt", deps_info)

This way I can get at all libs. Output in deps.txt is then:

coin-clp, 1.17.7, libs: []
     more libs found via components: ['ClpSolver', 'Clp']
     more libs found via components: ['OsiClp']
coin-osi, 0.108.7, libs: []
     more libs found via components: ['Osi']
     more libs found via components: ['OsiCommonTests']
coin-utils, 2.11.9, libs: ['CoinUtils']
bzip2, 1.0.8, libs: ['bz2']
zlib, 1.3.1, libs: ['z']

So: it works for me. But it's not really consistent and doesn't feel good to have to search for the info in many places. Thoughts?

valgur commented 1 month ago

That is by design in Conan. Plain self.cpp_info.libs does not get set if any components are defined. You can use dep_info.cpp_info.aggregated_components().libs instead.

philsuess commented 1 month ago

Thank you @valgur. I did not know that. Mystery solved and one step smarter. :+1: