Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why cannot CMake functions return values?

Tags:

cmake

A question for CMake experts out-there. According to the CMake function documentation a function simply does not return anything. To change variable values one has to pass it to the function, and inside the function set the new value specifying the PARENT_SCOPE option. Fine, this is a well-known feature of CMake.

My question here is not about the how, rather on why: why CMake functions do not return values? What is the idea behind? For example, a function cannot be used inside a if expression, or called inside a set command. If I remember correctly, it is the same with autotools, therefore I do not think it is like this just by chance.

Is there any expert that knows why?

like image 996
fedino Avatar asked Oct 17 '22 05:10

fedino


1 Answers

You can find a partial answer by Ken Martin in a message from the CMake's mailing list:

With respect to the general question of functions returning values it could be done but it is a bit of a big change. Functions and commands look the same (and should act the same IMO) to the people using them. So really we are talking about commands returning values. This is mostly just a syntax issue. Right now we have

command(arg arg arg
) 

to support return values we need something that could handle

command (arg command2(arg arg) arg arg 
) 

or in your case

if(assertdef(foo))

or in another case

set(foo get_property(
)) 

etc. This hits the parser and the argument processing in CMake but I think it could be done. I guess I’m not sure if we should do it. Open to opinions here.

like image 62
Caduchon Avatar answered Oct 21 '22 04:10

Caduchon