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

[question] How to use conan components with cmake? #7476

Closed
0x4d0x4b opened this issue Aug 2, 2020 · 5 comments
Closed

[question] How to use conan components with cmake? #7476

0x4d0x4b opened this issue Aug 2, 2020 · 5 comments

Comments

@0x4d0x4b
Copy link

0x4d0x4b commented Aug 2, 2020

I have tried to use conan components with cmake generator, but conanbuildinfo.cmake did not contain any targets or references pointing to components.
After browsing conan's source code I came into conclusion that cmake_find_package genrator has to be used to make components work.
Is it correct and expected behaviour? Are there any plans to expand component functionality for a plain cmake generator?
I apprciate it is an experimental feature, but I was not able to find anything in documentation that would suggest only speific generators are supported.

Conan version 1.28.0
cmake version 3.18.0

For a specific example and a bit more context on my use case, please refer to my other question #7475

@uilianries
Copy link
Member

Hi @kajdam !

Yes, you are correct, cmake_find_package and cmake_find_package_multi are used with components. About cmake package, it can be used together to other generators, they are different things, so there is not reason for including it cmake.

If you check Conan Center Index, it's a common approach. For instance: https://github.com/conan-io/conan-center-index/blob/master/recipes/openssl/1.x.x/conanfile.py#L714

@0x4d0x4b
Copy link
Author

0x4d0x4b commented Aug 3, 2020

@uilianries Thanks for clarifying that cmake_find_package and cmake_find_package_multi are the way to go with components.

I did not quite get the part about plain cmake generator though.
Could you elaborate more why it is not supporting components at the moment, please?

For example if I were to use an openssl you linked in your reply in my consumer's package conanfile.py I would be forced to use

generators = "cmake_find_package"

followed by

find_package(OpenSSL)

in my CMakeLists.txt

Why use of

generators = "cmake"

with

include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake)

in CMakeLists.txt is not supported?

It would be just a matter of changing implementation of plain cmake generator to generate targets for components in conanbuildinfo.cmake
Why would that be an issue?

@uilianries
Copy link
Member

Could you elaborate more why it is not supporting components at the moment, please?

#6718 (comment)

in CMakeLists.txt is not supported?

No. When you use ONLY cmake generator, CMake will consume the FindOpenSSL.cmake from your system. But again you can use both cmake and cmake_find_package together, not because the Find file, but set all correct settings according your Conan profile.

Please, read the issue conan-io/conan-center-index#787 which contains more details about.

@0x4d0x4b
Copy link
Author

0x4d0x4b commented Aug 3, 2020

Thanks @uilianries
#6718 (comment) clarifies it all i.e. that cmake_find_package/_multi and find_packages() are they way forward which I am happy with, but wanted to have clarity on that.
I would suggest to update the documentation to clearly state that those generators are correct way to work with components using cmake

0x4d0x4b added a commit to 0x4d0x4b/docs that referenced this issue Aug 4, 2020
If a consumer package is using cmake build system, then
cmake_find_package and cmake_find_package_multi are the only supported
generators to take advantage of dependencies' components.
0x4d0x4b added a commit to 0x4d0x4b/docs that referenced this issue Aug 4, 2020
If a consumer package is using cmake build system, then
cmake_find_package and cmake_find_package_multi are the only supported
generators to take advantage of dependencies' components.
@memsharded
Copy link
Member

This ticket is about legacy (removed in 2.0) generators like cmake and cmake_find_package. Closing as outdated, please create new tickets to report against CMakeDeps and CMakeToolchain. Thanks!

@memsharded memsharded closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants