Resolving dependencies in custom generator
Hello fellow conaneers!
I know that packages references dependencies at a package level, and that I can resolve the package dependencies in my custom generator:
for require, package in self._conanfile.dependencies.items():
for dep_require, dep_package in package.dependencies.items():
print(f"package {require.ref.name} depend on {dep_require.ref.name}")
I would like to do the same at a cpp_info level.
I see in the following in the openssl recipe:
https://github.com/conan-io/conan-center-index/blob/0c86693f18b14e52d7119b3e225706a002f27a9e/recipes/openssl/3.x.x/conanfile.py#L654
It references the component "zlib::zlib", but zlib does not expose such a compoent, only "ZLIB::ZLIB".
https://github.com/conan-io/conan-center-index/blob/0c86693f18b14e52d7119b3e225706a002f27a9e/recipes/zlib/all/conanfile.py#L101
Is this an error or is there some underlying assumption that I am not aware of. Maybe that all packages has a global default component [package_name]::[package_name]?
My question boils down to. When openssl depends on the component "zlib::zlib" how can I then resolve what package that belongs to?
Regards Klaus
Have you read the CONTRIBUTING guide?
- [X] I've read the CONTRIBUTING guide
Hi @klausholstjacobsen
Thanks for your question
It references the component "zlib::zlib", but zlib does not expose such a compoent, only "ZLIB::ZLIB".
No, this is correct. The zlib::zlib is the way to reference to the zlib package, the whole package. It is not the same and not related to the CMake target name ZLIB::ZLIB. The .requires in cpp_info and components, refers always to packages and components names, not to CMake targets.
Is this an error or is there some underlying assumption that I am not aware of. Maybe that all packages has a global default component [package_name]::[package_name]?
yes, exactly that
My question boils down to. When openssl depends on the component "zlib::zlib" how can I then resolve what package that belongs to?
All cpp_info.requires and cpp_info.components[].requires always refers to either comp_name for dependencies to components in this same package or to pkg_name::component_name for other packages named pkg_name, with the special case of pkg_name::pkg_name being a name for the whole package.
I hope this clarifies the issue.
@memsharded that makes total sense!
Bonus question. The libcurl package defines the cmake target "CURL::libcurl" for both the "global" package component:
https://github.com/conan-io/conan-center-index/blob/d52c7aa3c335033f331ad560d2b5cd8e4190d5a1/recipes/libcurl/all/conanfile.py#L662
and for the "curl" component:
https://github.com/conan-io/conan-center-index/blob/d52c7aa3c335033f331ad560d2b5cd8e4190d5a1/recipes/libcurl/all/conanfile.py#L730
So when I do target_link_libraries(....CURL::libcurl) which component does that resolve to? Is it always specific components first?
//Klaus
The libcurl recipe in ConanCenter has just 1 component. This is due to legacy Conan 1.X generators reasons, where it was necessary to define one component to be able to define some custom target names. This wouldn't be really necessary with CMakeDeps, and the recipe could be simplified.
The behavior of CMakeDeps is that the component has priority. It doesn't matter much, because it is still an INTERFACE "abstract" target, not the real internal one.