[CMake] Parameters of functions

Glenn Coombs glenn.coombs at gmail.com
Thu May 12 06:50:14 EDT 2011


I think you probably wanted to write and call your function like this:

FUNCTION(build var)
       MESSAGE(STATUS "var: ${var}")
ENDFUNCTION(build)

SET(var red blue yellow green)
build("${var}")

That prints out as you would expect:

-- var: red;blue;yellow;green

--
Glenn


On 12 May 2011 07:27, Rolf Eike Beer <eike at sf-mail.de> wrote:

> > This is funny:
> > FUNCTION(build var)
> >       MESSAGE(STATUS "var: " ${${var}})
> > ENDFUNCTION(build)
> >
> > SET(var red blue yellow green)
> > build(var)
> >
> > Output:
> > -- var: var
> >
> > SET(varX red blue yellow green)
> > build(varX)
> > Output:
> > -- var: redblueyellowgreen
>
> No, it must be that way. Inside build() var is defined as the variable
> that is defined in the interface. build() has no way to see the variable
> outside it because it can only find the inner name. It could reference
> it's value if you had passed the value or it could reference the variable
> by name if it would not be hidden by your interface variable.
>
> int a = 2;
>
> int build(int a)
> {
>  return a;
> }
>
> int b = build(42);
>
> b will be 42.
>
> Eike
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110512/6d0d6704/attachment.htm>


More information about the CMake mailing list