-
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] How to pass cmake configuration option with modern conan? #10515
Comments
Interesting question, I didn't know that the project() call would not be able to use toolchain.cmake defined vars. I see projects like https://github.com/tinyalsa/tinyalsa/blob/515be35688a76edee90b892150ea22fa9516638c/CMakeLists.txt#L7 doing some crazy things like reading things from a file. I think I would try something in the line of:
Alternatively, we could add to the modern |
Thank you for the quick reply @memsharded I'm not sure to understand what you mean by Like you, I think that the |
The alternative is to implement something that adds command line cmake variables in the But the goal of toolchains is to be able to do native builds, so basically Please let me know if this clarifies it a bit. |
Yes this clarifies. It is just that it doesn't really fit with the cmake phylosophy. Cmake doesn't offer a way to configure options through toolchain because we can't be sure when the toolchain is loaded. I mean not in a generic/global solution. From my side, I think something like |
Not sure I follow. In general toolchains seems a good approach to define cmake inputs, and it seems only the project() version thing could be one exception. But the rest of possible options, configurations, etc, seems to be well defined, it is possible to configure many different things in a toolchain, define cmake variables, compilation flags, shared/static and more. If there are more things like the project version that will not work, it would be very interesting to know, please let us know.
Yes, I am not opposed to adding this feature, it should be simple and low risk from the implementation point of view. But it is very important to clearly explain the implications, and what it means, because otherwise misuse/abuse will result in unnecessary pain for users and a burden on maintenance and support for us. |
I made some more investigations:
So toolchain is great to add new variable but not to override existing one. |
This is because CMAKE_TOOLCHAIN_FILE is loaded in CmakeSystem.cmake, which is loaded by enable_language(). So toolchain variables are not brought in until at least one language has been enabled. I think they do it this way since CMakeSystemSpecificInformation often uses some things (like CMAKE_LIBRARY_ARCHITECTURE) that aren't really language-specific (they really come from ld, not gcc/g++/clang), but aren't known until the CMake*DetermineABI calls have done some work. One can of course do an But yes, I've also occasionally missed the fact that conan.tools.cmake doesn't have anything to replace One idea: what if conan generated the CMakePresets.json format, and conan.tools.cmake.CMake just used Since it's an upstream thing rather than a conan-specific format, so you'd also get IDE integration: cmake-gui of course, but also visual studio, CLion, QtCreator not yet but it's on their roadmap. |
Ok, another vote for this, I think we can implement it, no prob.
Presets is CMake 3.19. We have stabilized and approved on CMake 3.15 support in the Tribe 2.0. (conan-io/tribe#4) We might add some more powerful capabilities for presets, but the "canonical" integration should be the one supported by CMake 3.15 |
Hmm, true. Not something I care much about, but I had forgotten there was already an official ruling. Others certainly do care. On the other hand, that really just means conan.tools.cmake.CMake can't use In fact, the IDE Integration Guide explicitly endorses this sort of thing, saying
And they give schemas/test cases for doing your own parsing. If conan's helper object did this (interfacing as they recommend an IDE should), that ought to be a stable integration and would make this compatible with older CMake (while also getting the benefits for newer IDEs). |
Uhm, that is a really interesting approach. If in fact everything is possible via command line, and no other internal logic, then this looks like feasible. Thanks for the idea, let's have a look and try it! |
I don't know if every feature of an arbitrary preset is possible. Certainly that seems unlikely in be a guarantee - if a newer CMake added some feature that doesn't exist before, it's likely that CMakePresets.json would be extended with a new key to support it. But it at least started as way of presetting features that cmake has had for a long time, it didn't arrive along an entirely different paradigm of configuration options. So there should be a large subset that would be compatible back to 3.15. And certainly every feature But here conan would own both sides (a CMakePresets.json generator and conan.tools.cmake.CMake). So it should be straightforward to limit itself to generating only things that are compatible with CMake 3.15. And this would still deliver the value-add that it's something other tools would also understand, so you could |
I need to pass cmake configuration option to be able to modify the project version. Unfortunately, by using toolchain variables, those variable aren't already loaded when the project() cmake function is called.
How could I achieve that?
The text was updated successfully, but these errors were encountered: