[CMake] map structure on cmake script

Alexander Neundorf a.neundorf-work at gmx.net
Mon Dec 17 15:59:13 EST 2007


On Monday 17 December 2007, Rodolfo Schulz de Lima wrote:
> Alexander Neundorf escreveu:
> > Yes, you can get map-like behaviour by using just variables:
> > SET(MY_MAP_${KEY} myValue)
>
> That's fine if ${KEY} doesn't have spaces nor characters that aren't
> allowed in variable names. As I'm using a string containing compiler
> flags and stuff, this solution isn't possible. A workaround would be

The following code works for me:

# create a  strange variable name and put it into tmp
set(tmp "- - / ' hallo welt")
#assign a value to that strange var
set("${tmp}" blub)
# print the value
message(STATUS "value: -${${tmp}}-")
#assign it to another var
set(tmp2 ${${tmp}})
message(STATUS "tmp2: -${tmp2}-")

After all, inside cmake the variables are simple a std::map<std::string, 
std::string> .

Alex


More information about the CMake mailing list