cmake-conan
cmake-conan copied to clipboard
Using conan_toolchain.cmake when generating it from CMake itself
I am starting to test conan and I am using the CMakeToolchain generator. However, instead of calling conan install .
, I am calling it through the CMake conan.cmake
package.
So if I just run
cmake -S . --preset whatever
the conan_toolchain.cmake file is generated correctly. On the next run I can do
cmake -S . preset whatever -DCMAKE_TOOLCHAIN_FILE=...
This is unconvenient, as I have to run twice the configuration
However, if I try to run directly with the toolchain file on a clean build, it simply fails to configure because the toolchain is not found. Is there any workaround for this?
Hi, I'm moving this issue to the cmake-conan repository because it doesn't look like a Conan issue. If you are starting with Conan I would strongly recommend not to use the conan.cmake
but just call conan install
and then run cmake normally.
Hi,
I was actually told to use conan install
command directly, but I find it unconvenient. It forces me to run a new command and know the compile directory (to be able to put there the output files from conan), which when using CMakePresets might not always be the case.
Still, I completely understand that with that approach you dont need to modify the original CMakeLists.
Hi @jjcasmar,
Thanks a lot for your question. The use of cmake-conan with CMakeToolchain generator is not recommended. In fact, cmake-conan does not support Conan 2.0 and we don't know yet if it will. Please, check the comments in this issue about that: https://github.com/conan-io/cmake-conan/issues/410#issuecomment-1095611994 I opened a PR warning about this here: https://github.com/conan-io/cmake-conan/pull/437 I would recommend you to do a conan install directly. We are making lots of improvements in the preset support (better if you use CMake>=3.23) and also you can define the layout now in the conanfile.txt that should make everything easier. There's some information in this blogpost about the latest release: https://blog.conan.io/2022/06/16/New-conan-release-1-49.html
Hi!
It forces me to run a new command
Yes,
but a simple conan install .
or conan install . -s build_type=Debug
and you are done until you change your dependencies.
and know the compile directory (to be able to put there the output files from conan),
Maybe you can try to put this in your conanfile.txt
(or the alternative layout()
method in the conanfile.py
):
[layout]
cmake_layout
The directory used to write the files generated by conan will always be the same and it nicely supports multi-configuration builds.
Also, if you use the CMakeToolchain
generator, it will generate automatically the presets for your configuration, so calling cmake --preset XX
will do all the work for you. Here you have an example, instead of the project generated with the conan new
you can use your own project.
We can assist if you can explain a bit more about your project and the issues you are having with the folders.
I am using CMakeToolchain generator, and I doubt I can use the generated preset, mainly because I am already using presets. Ill have a look at the cmake_layout stuff.
Could I ask which information have you set in your presets?
note I'm not trying to lead you to use the generated by Conan, but maybe there is a point of integration between them, the usage of the Presets is still very low in the community and we can learn a lot.
In the preset I am adding some build options.
However, as you said, (better if you use CMake>=3.23)
in CMake 3.23 you can include one preset from another, so probably the developer can add the preset generated by conan on its own preset.
At some point it will be nice if calling cmake could code conan anyway. It will be much easier to integrate.
The last thing I am thinking is how to deal with release/debug mode on dependencies. Most of the time you dont want your dependencies build on Debug mode, even if you are compiling in Debug mode your code. This can be solved with profiles, right?