Forcing variable expansion

Is there a way to force variable expansion on a string that contains a variable reference?

In my case I have a variable SOME_VAR that is set by the user on the command line and contains a reference to a variable that is defined in the CMake script – something like this:

cmake ... -DSOME_VAR="${SOME_OTHER_VAR}_bar"

And my script defines SOME_OTHER_VAR to be “foo”. But if I then print out SOME_VAR, I still see “${SOME_OTHER_VAR}_bar”, rather than “foo_bar”.

Is there something I can do to trigger variable expansion in SOME_VAR?

On the command line, that expansion is going to be controlled by the shell, not CMake. If you want replacement like that, you’ll need a CMake file to do it (maybe via the -C command line flag). But there’s no way to say “defer evaluation of this value until it is needed” in CMake.

Not sure what my shell has to do with any of that? I neither expect nor want to perform any expansion “on the command line”.

Anyway, it seems that string(CONFIGURE) does exactly what I wanted.