Naios
Naios

Reputation: 1573

CMake interpret string as variable

I'm looking for a way to interpret a string as variable name in cmake.

Given:

set(MY_SECRET_VAR "foo")

# later only the name of the variable is known.
set(THE_NAME "MY_SECRET_VAR")

# Now i'm looking for a way to get the value "foo" from the name
# something like:
set(THE_VALUE "${THE_NAME}")

# THE_VALUE should be "foo"

Upvotes: 29

Views: 11925

Answers (1)

Gombat
Gombat

Reputation: 2084

A second level of unwrapping:

set(THE_VALUE "${${THE_NAME}}")

Upvotes: 41

Related Questions