PacktPublishing/Modern-CMake-for-Cpp

How does cmake handle interpolation

xiaomx32 opened this issue · 2 comments

at
“Chapter 02”
“Working with variable“
"Variable references"

set(MyInner "Hello")
set(MyOuter "${My")
message("${MyOuter}Inner} World")

The above code cannot be run:

when parsing string
  ${My
There is an unterminated variable reference.

using cmake 3.20.0 also 3.26.0

As indicated by the error you cannot define "unterminated variable reference".
Here is a working example that may do what you want:

set(MyInner "Hello")
set(MyOuter "My")
message("${${MyOuter}Inner} World")

As indicated by the error you cannot define "unterminated variable reference". Here is a working example that may do what you want:

set(MyInner "Hello")
set(MyOuter "My")
message("${${MyOuter}Inner} World")

you are right, so the example in the book is wrong.