How to easily compare if 'gnu17' is is less than '20' in configure()? Could you please provide a common tool to compare that?
I like it.
We have discussed in https://github.com/conan-io/conan/pull/5440 that this is a bit more problematic than it seems:
CppStd(self.settings.compiler.cppstd)> "14" seems very not ergonomicA proposal could be to use the order in which the settings are defined in settings.yml. This will take some time and will try to make it for the next 1.21, not this one. Issues to take into account:
self.settings.compiler.cppstd < "foo" should raise because "foo" is not a valid cppstd declared in the settings.yml.IMO the use-case is more about requiring a minimum standard than comparing them, so...
What about using a declarative approach closer to the CMake one?
def configure(self):
... dependending on options, settings...
tools.CppStdRequired(self, cppstd=17, extensions=True|False)
...
The implementation could take advantage of the utilities we already have to parse self.settings.compiler.cppstd and identify the _number_ and the _gnu-extension-enabled_... . and also, very important, the _default-standard_ from the given compiler-version .
If it fails, raise a ConanInvalidConfiguration, if we don't know how to parse it, print a warning and do nothing.
Note for readers that by itself it's not a sufficient metric since the standard support is a very granular thing.
The tools.CppStdRequired would be quite handy when checking for the current compiler, maybe even allowing for feature-required like functionality based on that.
I agree that is the use case all of us had in mind.
I propose this interface:
def configure(self):
... dependending on options, settings...
tools.check_min_cppstd(self, cppstd=17, gnu_extensions=False)
...
The tool will check that the current cppstd (because declared or because it is the default of the compiler) if at least the specified number.
gnu_extensions==True then it is required also that the gnu extensions are enabled. gnu_extensions==False then a valid input will be gnuXXX or XXX.gnu_extensions won't have any effect on Windows.tools.check_min_cppstd(self, cppstd=14, gnu_extensions=True) an input of compiler.cppstd==14, compiler.cppstd==17 or compiler.cppstd==20 will raise, it is needed gnu14 or gnu17 or gnu20.EDIT:
Add also tools.valid_min_cppstd() that will do the same but returning a boolean instead of raising.
EDIT:
The gnu_extensions=True won't check the OSS. It is tricky to do it automatically since you can cross build to Arduino or any other embeeded where it could makes sense but it is not linux.
Add also tools.valid_min_cppstd() that will do the same but returning a boolean instead of raising.
I liked it!
Most helpful comment
I agree that is the use case all of us had in mind.
I propose this interface:
The tool will check that the current cppstd (because declared or because it is the default of the compiler) if at least the specified number.
gnu_extensions==Truethen it is required also that the gnu extensions are enabled.gnu_extensions==Falsethen a valid input will be gnuXXX or XXX.- Thegnu_extensionswon't have any effect on Windows.tools.check_min_cppstd(self, cppstd=14, gnu_extensions=True)an input ofcompiler.cppstd==14,compiler.cppstd==17orcompiler.cppstd==20will raise, it is neededgnu14orgnu17orgnu20.EDIT:
Add also
tools.valid_min_cppstd()that will do the same but returning a boolean instead of raising.EDIT:
The
gnu_extensions=Truewon't check the OSS. It is tricky to do it automatically since you can cross build to Arduino or any other embeeded where it could makes sense but it is not linux.