Why can't CMake functions return values?

Question for CMake experts. According to the CMake documentation, the function simply returns nothing. To change the values โ€‹โ€‹of variables, you need to pass it to the function, and inside the function set a new value that defines the PARENT_SCOPE parameter. Well, this is a well-known feature of CMake.

My question here is not how, but why: why CMake functions do not return values? What is the idea? For example, a function cannot be used inside an if or is called inside a set command. If I remember correctly, this is the same with autotools, so I don't think it looks like this by accident.

Is there any expert who knows why?

+5
source share
1 answer

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

Regarding the general question of functions that return values, it can be done, but these are slightly larger changes. Functions and commands look the same (and should act the same IMO) to the people using them. Therefore, we are talking about commands that return values. This is basically just a syntax problem. 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 .. It gets into the parser and argument processing in CMake, but I think that it can be done. I think I'm not sure that we should do this. Discover opinions.

+2
source

Source: https://habr.com/ru/post/1272214/


All Articles