-
Notifications
You must be signed in to change notification settings - Fork 1k
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] Is it possible to select different generators for different packages? #7118
Comments
Hi! Right now this is not something possible. You can always write a This would be a new feature, to be implemented the same way you proposed, as settings and options currently allow that syntax in profiles. |
I don't think it is just a syntax issue, I see a problem with this, and is transitivity. For example, the generator that we are most likely using as default in Conan 2.0 is That generator relies on the other packages to have |
Thanks for the prompt replies, Javier and James. Yes, I can see how new syntax could cause problems as it was not foreseen from the beginning. So maybe I should start over :) ProblemWhen GoalTo use WhyImagine existing project that uses a combination of Please let me know if I could provide any more clarity to the problem. |
IMO, it is up to the user to fix these errors once they are raised. Right now, the syntax in profiles (and CLI) allows the user to mix different settings (some combinations won't link or work at all). Same transitivity problems. For coherence, Conan should take care of these problems for all fields or for none of them, should allow the same syntax for all the fields or for none of them (less surprise). Probably for none: if the user is mixing settings or mixing generators and gets an error related to building/linking or to generators, the user should realize about it and revert this opt-in behavior. In some scenarios (like this one), using different generators for certain packages could be the way to go. |
I agree with @artem-ogre, I am using CMake projects and simply wrapping them into conan packages that work very intuitively with the "cmake_paths" generator. (They install their own package config files correctly and can easily be found using the "cmake_paths" generator)... Also transitive dependencies seem to work fine this way too. Some of my CMake projects use conan to consume other packages and those dependencies get carried along fine. But the second I need to include a third party library that doesn't support "cmake_paths", I need to add the "cmake_find_package" generator and it breaks the libraries that use "cmake_paths" because of the problem Artem mentioned above. I tried making "cmake_find_package" compatible packages from these projects, but compiler options like setting the correct C++ standard do not get transitively resolved properly and I have to add duplicated information in the conanfile that is already in the CMakeLists.txt to get things to work (this becomes a maintenance problem). With the "cmake_paths" generator these things do get transitively resolved without any extra effort because the actual CMake target produced by CMake itself is consumed when using the package. (see here: #7479) I really prefer the simplicity of just wrapping an existing CMake project and using its own package config files to find it with "cmake_paths". Even though it restricts me to only consuming my libraries with CMake, that doesn't bother me because I have no intention of switching build systems. It seems to be the only way things just work without any headaches. |
I agree. I am doing the same thing. For my projects, I am writing recipes that just do a normal cmake install and then set the environment variable For third-party packages, the the new |
I've been experimenting with different ways using a packages CMake Config file and I have found that this works if you have control over the recipe.
I've also tried
which will add a line to one of the However, neither of these workarounds support multi-config, which is what I'm working on now. In the first case, the toolchain file will be overwritten each time |
No, there is not that possibility. The About the multi-config, I'm aware of the limitation of the But what would be the expected behavior? I mean, cmake cannot do an Have you figured out any other way to manage the multi-config only with the packaged config files? Thanks |
I agree, and we actually have a package that depends on
You are correct. I am not very familiar with generator expressions, so I was still trying to understand how it could work. Generator expressions only affect cmake's "generate" step so they cannot conditionally include a file, but they can conditionally link against targets. I was able to get something to work, but it is a bit of a hack, and it requires the second approach above. Let's say you have a library that include a
It looks like this
This almost works with Conan's
So I wrote a custom generator that just uses This actually works for the Ninja Multi-Config and Visual Studio cmake generators on the project I am testing, but I am not sure how general it is. If a packaged |
@czoido is going to propose some client side (from |
We would like to use Conan with a CMake project.
For dependencies that provide package-config file or a find-module file (
<Package>Config.cmake
,Find<Package>.cmake
) we would like to usecmake_paths
generator.In other cases we would like to generate find-module files with
cmake_find_package
generator.In a mixed situation the solution is to use both
cmake_paths
andcmake_find_package
generators and explicitly tell CMake which mode to use forfind_package
:Another option is to use
CMAKE_FIND_PACKAGE_PREFER_CONFIG
.But wouldn't it be great instead to tell Conan which generator to use for which package?
Something like:
Question:
Is something like this possible?
Is there a better way to handle such mixed situations?
If not, would that be something worthy of a feature-request?
Thank you!
The text was updated successfully, but these errors were encountered: