gpt4 book ai didi

cmake - 调用 CMake 函数 : number of arguments

转载 作者:行者123 更新时间:2023-12-05 08:22:49 24 4
gpt4 key购买 nike

有一个名为myfunc 的函数定义为

function (myfunc var1 var2 var3)
...
endfunction()

然后,我看到一个函数调用

myfunc(custom hahaha platform ALL
COMMAND echo "hello world"
SOURCES ${some_var} )

我的问题是

The function myfunc takes 3 variables. In the above function call, which are the 3 variables? Also, how can there be additional commands COMMAND and SOURCES within the function call?

最佳答案

3 个变量将是前 3 个参数。

如果你的函数定义如下:

function (myfunc var1 var2 var3)
message ("var1: ${var1}")
message ("var2: ${var2}")
message ("var3: ${var3}")
message ("number of arguments sent to function: ${ARGC}")
message ("all function arguments: ${ARGV}")
message ("all arguments beyond defined: ${ARGN}")
endfunction()

按照你所说的调用它之后:

set (some_var "some var")
myfunc(custom hahaha platform ALL
COMMAND echo "hello world"
SOURCES ${some_var} )

输出将是:

var1: custom
var2: hahaha
var3: platform
number of arguments sent to function: 9
all function arguments: custom;hahaha;platform;ALL;COMMAND;echo;hello world;SOURCES;some var
all arguments beyond defined: ALL;COMMAND;echo;hello world;SOURCES;some var

所以你用 9 个参数调用你的函数,用 ${ARGV} 引用,所有未定义的参数也可以用变量 ${ARGN} 引用.

请注意,在调用函数时,ALL、COMMAND 和 SOURCES 只是函数的参数,没有其他内容。

最后,这里是关于 cmake functions and arguments 的完整文档

关于cmake - 调用 CMake 函数 : number of arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57415761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com