将常量列表传递到 cmake 宏的方法?
我有一个像这样的 CMake 宏:
macro( foo a b )
list( FIND b ${a} is_found )
endmacro()
我尝试像这样调用它:
foo( "test" foo;bar;test )
这不起作用。这也不起作用:
foo( "test" "foo;bar;test" )
在所有情况下,我得到的 is_found
等于 -1
,而实际上它应该已经找到了。我怎样才能像我想要的那样即时传递列表?
I have a CMake macro like so:
macro( foo a b )
list( FIND b ${a} is_found )
endmacro()
And I try to call it like so:
foo( "test" foo;bar;test )
This doesn't work. Also this does not work:
foo( "test" "foo;bar;test" )
In all cases I get is_found
equal to -1
, when in fact it should have been found. How can I pass in a list on-the-fly like I want to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况是因为宏的参数和特殊值(例如
ARGN
)不是通常 CMake 意义上的变量。它们是字符串替换,就像 c 预处理器对宏所做的那样。您可以将输入参数复制到变量,然后将该变量传递到列表查找:
因此,以下所有变体都有效:
更新,更通用的版本 - 在由“NEXTLIST”单词分隔的多个列表中搜索:
This happens because parameters of a macro and special values such as
ARGN
are not variables in the usual CMake sense. They are string replacements much like the c preprocessor would do with a macro.You can copy input arguments to the variable and next pass that variable to list find:
As result all the following variants work:
Update, more generic version - search in several lists separated by "NEXTLIST" word: