Cmake - 奇怪的函数参数名行为 [英] Cmake - strange function argument name behaviour

查看:231
本文介绍了Cmake - 奇怪的函数参数名行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问过关于cmake和传递变量的问题此处。我可以让它工作,但只有如果我命名我的变量在函数中不同于父范围中的变量我调用的函数。所以在本质上:

I asked a questions about cmake and passing variables here. I can make it work, but only if I name my variable in the function differently than the variable in parent scope I call the function for. So in essence:

function(strange name)
   message(STATUS ${name})
   message(STATUS ${${name}})
endfunction()

set(name foo)
set(anothername foo)
strange(name)
strange(anothername)

其结果是:

-- name   (message(STATUS ${name}) for var "name")
-- name   (message(STATUS ${${name}}) for var "name")
-- anothername message(STATUS ${name}) for var "anothername")
-- foo    (message(STATUS ${${name}}) for var "anothername")

这不奇怪吗?发生了什么?
我认为函数的行为不应该取决于父作用域中变量的命名 - 是吗?

Isn't that a little weird? What's happening? I think the behaviour of a function should not depend on the naming of variable in the parent scope - should it?!

任何澄清都是非常赞赏的! / p>

Any clarification is much appreciated!

推荐答案

不幸的是,CMake的语言是非常原始的。在这种情况下,局部变量的命名可能与外部作用域中具有相同名称的变量交互。

Unfortunately, the language of CMake is extremely primitive. In this case, the naming of local variables may interact with variables with the same name in outer scopes.

具体来说,在两个调用 $ { $ {name}} 扩展为 $ {name} $ {anothername} 分别。在前者 name 是使用其值的局部变量的名称。在后者中,使用外部范围中的 anothername

Concretely, in the two calls ${${name}} expands to ${name} and ${anothername}, respectively. In the former name is the name of a local variable whose value is used. In the latter, the anothername from the outer scope is used.

我不知道

也许我们应该请求一个 $ {name:PARENT_SCOPE} 来自CMake小组?

Maybe we should petition for a ${name:PARENT_SCOPE} from the CMake team?

这篇关于Cmake - 奇怪的函数参数名行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆