[CMake] Discuss Adding return values/dynamic function invokation to cmake

Tobias Becker becker.tobi at gmail.com
Sun Jan 11 14:03:49 EST 2015


Hi All,


I've been thinking aboutallowing return values/ function evaluation in the
cmake script language.  Especially if there are any downsides e.g.
compatibility issues/language inconsistency.

What I mean is the following syntax:
```
function(func1)
 return(1)
endfunction()

function(add lhs rhs)
 math(EXPR res "${lhs} + ${rhs}")
 return(${res})
endfunction()

set(result  ${func1()}) # checks to see if function is defined and if so
invokes it idicated by parenthesis
assert(${result} EQUAL 1)

set(result ${add(${func1()} 2}) # inner function is evaluated first and
result is pasted in outer function
assert(${result} EQUAL 3)

message(INFO "${add(1 3)}") # --> prints 4

set(function_name add)
message(INFO "${function_name}(3 5)}") # --> prints 8
```

This could replace generator expressions with a cleaner and more general
alternative and also it would allow cmake to become much easier to use.

I'd also like to know if someone could point me to where in the cmake
codebase the "${}" evaluation expression is actually processed.

If you have any critique of this idea then I would also be happy - else
I'll try to fork cmake and implement this.



Cheers!

Tobias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150111/023d694e/attachment.html>


More information about the CMake mailing list