conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.25k stars 980 forks source link

[question] CMake Generator priority #14024

Closed PengolodhGoedath closed 1 month ago

PengolodhGoedath commented 1 year ago

What is your question?

Hi! I have a question regarding the CMake Generator selection priority. I am wondering why configuration setting tools.cmake.cmaketoolchain:generator is prioritized over the generator parameter to CMakeToolchains constructor?

I stumbled upon this recently in a recipe that simply wouldn't work with a multi-config generator, but a profile "forced" it to use "Ninja Multi-Config", even though I tried setting the generator in the CMakeToolchain constructor to just "Ninja". I have wondered about this choice of prioritization since.

EDIT; I'm talking about this function specifically: https://github.com/conan-io/conan/blob/a8074a2be4f7e48b328ced4417846a1b318a925e/conan/tools/cmake/toolchain/toolchain.py#L212-L248

Have you read the CONTRIBUTING guide?

memsharded commented 1 year ago

Hi @PengolodhGoedath

This is a general Conan design criteria: the most "downstream" has precedence. In this case, if the consumer user, the one defining the profiles decides they want to define conf to set cmaketoolchain:generator, they can do it, and that must be respected. If they want to define it only for the consumer conanfile.py they have mechanisms, like &:tools.cmake.cmaketoolchain:generator=Ninja, but as a general rule, if they define it for every recipe it should work. Same applies for *:shared=True defined in a profile, that will have precendence and overwrite every recipe option definition or default.

memsharded commented 1 month ago

Closing as responded back then, but please don't hesitate to re-open or create new tickets for any further question. Thanks for your feedback.