docs
docs copied to clipboard
How to integrate `cmake_find_package_multi` with CMake
Hi,
The docs state
You also need to adjust CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH so CMake can locate all the <PKG-NAME>Config.cmake files: The CMAKE_PREFIX_PATH is used by the find_package and the CMAKE_MODULE_PATH is used by the find_dependency calls that locates the transitive dependencies.
However, there is no information on how to do it in the best way. It confuses people that are not CMake experts. I get questions from my students if they should do it:
- inside CMake file with
set() - externally with
-DCMAKE_PREFIX_PATH... - or maybe set some environemnt variable.
As it is going to be THE CMake generator for Conan 2.0 it would be nice to have an easy instruction to follow so people can get familiar with it more easily.
Hi @mpusz
This should be quite straightforward in Conan 2.0, because those will be defined by the CMakeToolchain. You can already try it in latest Conan, use the toolchain and pass it to cmake .... -DCMAKE_TOOLCHAIN_FILE=conantoolchain.cmake and it will find the generated files by the cmake_find_package_multi generator.
Our only challenge right now is that we cannot introduce it in the docs as the canonical recommended one, because toolchains are still very experimental, but hopefully we can soon estabilize and start recommending it.
The only problem I have with toolchains is that they are a bit hard to use with IDEs. Also if someone has another custom toolchains (i.e. to define an initial value of CXX_FLAGS with all the compiler warnings) they do not compose easily.
Yes, they will compose easily, it is just we haven't implemented the feature yet, but it is planned. As said, they are still early stage, but this shouldn't be a problem when done.
What I would like to know better is to understand why it would be an issue with IDEs, as far as I know it is not a problem to pass the -DCMAKE_TOOLCHAIN_FILE to cmake, is it? At least VisualStudio (CMake integration) and CLion implement it. Could you please elaborate a bit more on this issue?
Well, if you know your IDE and understand CMake and Conan quite well then there is probably no problem at all. However, it is yet another step that a (potentially junior) developer has to manage in order to compile his/her "hello world" project.
Don't get me wrong. I like the idea. I think that in the end, it is the right solution. However, it will take some time to get there. Improving Conan's support in IDEs also will be helpful as Vcpkg is clearly a leader in this domain for now.
Anyway, for my case of units library, cmake_find_package_multi does not work for now (I spent quite a lot of effort to make it work and I failed). And yes, I tried CMake toolchain as well.