Question about non numeric versioning discussion

Hello, I wanted to ask a bit about the state of discussion #23649 (can’t link due to new user limitation). I saw that the proposed options are currently either modifying the if expression to allow for additional parameters:

if(<string|variable> VERSION_MATCHES <string|variable> [<version_scheme>])

Or a bunch of verbose overloads for all current operations:

if(<string|expression> <VERSION_SCHEME>_MATCHES <string|expression>)

To not enter that discussion on the GitLab, as I don’t want to clutter it up with questions. I ask here.

Why is the operator1,2-syntax used for scoped variables (i.e. CACHE{} and ENV{}), not used more broadly in CMake?

I suppose that these operators act like read only scopes. Not actually persistent metadata/type information. So perhaps using it like VERSION_MATCHES $SCHEME{"x.y.z-pre"} would be very different from the current behaviour. Would something like $SCHEME:{VERSION_MATCHES} also not work?

Having some concept of generics/templates would be the only way to solve this in a way that doesn’t make CMake harder to maintain, nor introduces new types that make implementing CMake harder/less stable?

CACHE{} and ENV{} are query domains with well defined semantics, not arbitrary transforms or views of existing data. They’re not functions.

It’s unclear what SCHEME{} would be querying into, which you have already pointed out.

That’s the whole reason. It’s not more complicated than “such a thing does not exist within CMake, implementing it would be a deal of work, and it’s unclear that syntax is good or intuitive”.

Isn’t ENV{} actually not read only? It can be set, and applies to the current process (sort of, but does not persist in the cache/between different cmake runs).

Well SCHEME{} would here merely be a pure-function. No side effects. So not a function in the general sense of the word. No more than CACHE and ENV are.

Something like $OVERLOAD{VERSION_MATCHES SEMVER} would be well defined. It would query into the language itself. Merely providing a syntax for making overloads more predictable (such as in VERSION_MATCHES in if(... VERSION_MATCHES ...)).

Currently as there is no way to organise this kind of thing you have discussion going like the #23649 one.

ENV isn’t read only, the point is it’s not a function call. It’s a query, a load or a store. All variable expansions are. That includes regular variables, ENV{}, and CACHE{}. The CMake internals do not model these as transformations over the underlying data.

We could, we don’t, and that’s the whole story. If you want to transform a string from one form to another you write a function to do that.