[CMake] Parameters of functions
Michael Wild
themiwi at gmail.com
Thu May 12 08:19:47 EDT 2011
Often one wants to pass in the *name* of a variable (i.e. the name of
list, like for list(APPEND name ...)), so Rolf's code does make sense.
Haven't had the time to try the test-case myself, though...
Michael
On 05/12/2011 12:50 PM, Glenn Coombs wrote:
> 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
More information about the CMake
mailing list