-
Notifications
You must be signed in to change notification settings - Fork 991
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] Can CMakeToolchain tell CMake the correct compilers? #11842
Comments
The problem is that CMake is not a toolchain responsibility in general. For example, for Visual Studio compilers, it is defined in the CMake generator and not in the toolchain. So the approach that Conan follows hasn't changed much from the legacy build system integrations, and it is still the responsibility of the users to have the dev environment that matches the declared configuration. But at least, the new tools provide some more explicit helpers. For example for Visual Studio compilers, it can generate a |
Why is that though? conan could easily set the correct compilers in the toolchain file or the CMake preset to make sure that everything fits together. So far there isn't even a check that the CMake-selected compiler matches the one specified in the conan profile. |
Because it is not that easy. The previous integration, the |
I trust that you have more insight into all possible problems with that but according to the CMake Wiki it's easy to switch to a different compiler. Conan already knows which compiler to use when calling I'm curious why the CMakeToolchain generators doesn't even try to e.g. set environment variables from the profile like CC/CXX because that alone might already be enough to let CMake select the corresponding compiler. See what happens if I manually add the environment variables to the CMake preset:
|
Conan knows which compiler and compiler version you intend to use, however, Conan does not necessarily know where that compiler lives, and different Linux distributions follow different conventions with regards to being able to install multiple versioned copies of the GNU Toolchain side by side.
Thanks for bringing this example to our attention, @fschoenm! In this example, CMake is assuming two things:
Unfortunately this convention of is not uniform across Linux distributions - and as such there isn't any "safe" assumption that we can make. Traditionally on Linux distros you will find the C and C++ compilers in the For example, on Ubuntu Linux you will find that if you have the "default" g++ installed, you have However, on other Linux distributions, the name of the compiler executable that includes the version may follows a different convention, for example |
Sure, I agree that it might be complicated to cover all cases. But somebody somewhere has to know where the compiler lives. It can even be configured in the profile. Obviously, the profile has to be correct for the machine and its installation paths. When using That doesn't make much sense to me. I already showed above that it's possible to tell CMake the correct compiler via a toolchain file or via presets. |
Quick question, why the above Windows example doesn't define the env-vars too in the profile, as the Linux profile does? Also a 2.0 tip: use Maybe we want to consider a |
No specific reason. We mainly develop on Linux and support Windows with less effort going into it. |
Hi @fschoenm We have added in #12556, for 1.55 the possibility to explicitly tell the compilers to CMake (not only CMake, but also other build systems as well), via a new I think this PR will solve this request, could you please have a look and confirm? Thanks! |
Looks fine to me. Thanks for spending the effort! |
My understanding of the new CMakeToolchain's purpose was that it can also be used to guarantee that CMake uses the correct compiler versions. However, that doesn't seem to be the case?
See the examples below. As I understand so far, the user is responsible for selecting the correct compiler when using CMake? Is there a way to force CMake to use the correct compiler that has been defined in the conan profile or is that not in scope of the CMakeToolchain generator?
Linux example
I have a gcc10 profile (with CC/CXX environment variables). As you can see, CMake uses the (default) GCC 11 compiler instead of GCC 10, which has been defined in the conan profile.
Windows example
Same issue here: CMake doesn't know about the compiler specified in the conan toolchain. In my IDE (e.g. CLion) the compiler that was selected in the IDE is used instead of the one specified in the
conan install
call.The text was updated successfully, but these errors were encountered: