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 cmake-conan with CMakeToolchain generator? #410

Open
hwhsu1231 opened this issue Apr 11, 2022 · 7 comments
Open

[question] How to use cmake-conan with CMakeToolchain generator? #410

hwhsu1231 opened this issue Apr 11, 2022 · 7 comments
Assignees
Labels
Milestone

Comments

@hwhsu1231
Copy link
Contributor

In Conan documentation, it says that we need to add -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake in the command-line. That is, we have to generate the conan_toolchain.cmake file "before" we run cmake to configure the project.

However, with CMake-Conan, we use conan_cmake_configure() to generate conanfile.txt file, and use conan_cmake_install() to run conan install command. If we add CMakeToolchain generator in conan_cmake_configure(), the conan_toolchain.cmake file will be generated after the conan_cmake_install() is conducted.

It looks like the conan_toolchain.cmake file is generated "after" we run cmake executable.

How to deal with this situation?

# 'conanfile.txt' file is generated after this command
conan_cmake_configure(
  GENERATORS  CMakeToolchain  # Specify generator
  REQUIRES    fmt/8.0.0
  OPTIONS     fmt:shared=True
  IMPORTS     "bin, *.dll -> ../bin"
)

conan_cmake_autodetect(settings)

# 'conan_toolchain.cmake' file is generated after this command
conan_cmake_install(
  PATH_OR_REFERENCE "."
  INSTALL_FOLDER    "./conan"
  BUILD             missing
  REMOTE            conancenter
  SETTINGS          ${settings}
)
@memsharded
Copy link
Member

This is kind of a chicken and egg problem, you cannot pass the toolchain because it doesnt exist yet. Unless you want to build a cmake flow that actually stops at the first pass after generating the conan stuff, and then it can use the toolchain at the second run, then, using the toolchain file is impossible by CMake behavior. Even if that is possible, then it is certainly not a conventional flow, and if you need to teach developers to do that, why not just letting them run a "conan install"?

In any case the conan_toolchain.cmake is mostly there to try go guarantee that your CMake configuration follows the Conan settings. As the goal of cmake-conan is the opposite, to obtain the Conan settings from the current CMake configuration, that renders the conan_toolchain.cmake mostly useles, because it should largely contain what is somewhat already defined in the current CMake run.

@hwhsu1231
Copy link
Contributor Author

@memsharded Are you saying,

It's "not" possible/reasonable/recommended to use CMake-Conan with CMakeToolchain generator?

@lbckmnn
Copy link

lbckmnn commented Apr 19, 2022

Can somebody clarify this?
I would also like to use cmake-conan (but with an existing conanfile.py) because this would integrate with IDEs which doesn't have a good conan integration yet.

@hwhsu1231
Copy link
Contributor Author

Can somebody clarify this? I would also like to use cmake-conan (but with an existing conanfile.py) because this would integrate with IDEs which doesn't have a good conan integration yet.

@lbckmnn, If you want to use the existing conanfile.py, then you won't need to use conan_cmake_configure(). Because this command is used to generate a conanfile.txt recipe file.

If you want to use CMake-Conan, I suggest that you use CMakeDeps generator, instead. Because it seems that it has some problems with CMakeToolchain generator when using CMake-Conan.

@hwhsu1231
Copy link
Contributor Author

hwhsu1231 commented May 25, 2022

@czoido @memsharded

If CMakeToolchain generator is NOT appropriate to use with CMake-Conan, should it add some NOTES on README.md to tell users not to use it?

@czoido
Copy link
Contributor

czoido commented May 25, 2022

Hi @hwhsu1231,
I think so, we will add a note about that in the docs. Also, please check we added a note about compatibility with Conan 2.0 in the README in develop branch.

@hwhsu1231
Copy link
Contributor Author

This CAE problem is probably solved by the solution that I proposed previously. (#449)

Project Link: https:/hwhsu1231/cmake-conan-setup

@hwhsu1231 hwhsu1231 changed the title [question] How to use CMake-Conan with CMakeToolchain generator. [question] How to use CMake-Conan with CMakeToolchain generator? Nov 4, 2022
@hwhsu1231 hwhsu1231 changed the title [question] How to use CMake-Conan with CMakeToolchain generator? [question] How to use cmake-conan with CMakeToolchain generator? Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants