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

[suggest][dev2] Run conan install and include conan_toolchain.cmake directly when injection. #480

Open
hwhsu1231 opened this issue Mar 17, 2023 · 6 comments
Assignees

Comments

@hwhsu1231
Copy link
Contributor

Suggestion

According to #475 (comment)

Since the conan install command is executed in the conan_provide_dependency() function, the conan_toolchain.cmake file of CMakeToolchain will be generated only when the find_package() command is called, which is after the project() command. Therefore, the CAE problem cannot be solved.

However, I suddenly thought of an idea:

  1. What if we run conan install and include conan_toolchain.cmake directly when injection.
  2. And then append ${CONAN_GENERATORS_FOLDER} into CMAKE_PREFIX_PATH inside conan_provide_dependency().

In other words:

[DEBUG] Before calling "project()" command...
[DEBUG] Start to include "conan_provider.cmake" file...        # run conan install and include conan_toolchain.cmake
[DEBUG] After calling "project()" command...
[DEBUG] Before calling "find_package(fmt)" command...
[DEBUG] Start to call "conan_provide_dependency()" function... # append ${CONAN_GENERATORS_FOLDER} into CMAKE_PREFIX_PATH
[DEBUG] After calling "find_package(fmt)" command...

Maybe the CAE problem can be solved in this way?

@memsharded
Copy link
Member

Hi @hwhsu1231

I am afraid that what you are suggesting is not possible:

DEBUG] Before calling "project()" command...
[DEBUG] Start to include "conan_provider.cmake" file... # run conan install and include conan_toolchain.cmake

You need the full CMake definition of compiler to be able to obtain it and use it for conan install. Until CMake don't fully define the setup, it is not possible to get the values, and that doesn't happen until after the project()

@memsharded memsharded self-assigned this Mar 17, 2023
@hwhsu1231
Copy link
Contributor Author

@memsharded

If that is the case, I feel like we might have reached a deadlock with Dependecny Provider. Any other ideas?

@memsharded
Copy link
Member

No we havent, this is good. This can work by guaranteeing an alignment between the configuration and what would be generated by the conan_toolchain.cmake. If the detection of the current configuration is good enough, and it would match the generated conan_toolchain.cmake, we will be good.

The plan is now to test it, experiment with it and get feedback, and lets see how it goes. So far it seems it has good potential.

@hwhsu1231
Copy link
Contributor Author

This can work by guaranteeing an alignment between the configuration and what would be generated by the conan_toolchain.cmake. If the detection of the current configuration is good enough, and it would match the generated conan_toolchain.cmake, we will be good.

What do you mean? Do you mean that we won't need CMakeToolchain anymore in the future?

@memsharded
Copy link
Member

It is definitely needed for building packages, because the cmake-conan integration is only for pure consumers, but cannot and will never be used to create packages.

It will also be very relevant in many other situations and contexts. The vast majority of Conan users are not using the cmake-conan integration, and there will be some special scenarios like when having tool_requires that cannot work with cmake-conan by definition.

@hwhsu1231
Copy link
Contributor Author

hwhsu1231 commented Mar 17, 2023

It is definitely needed for building packages, because the cmake-conan integration is only for pure consumers, but cannot and will never be used to create packages.

So you mean that CMakeToolchain is:

  • required when creating the package,
  • but not so important when consuming the package.

Therefore, it's fine to use just CMakeDeps with cmake-conan in most cases, right?

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

2 participants