在makefile或CMake文件中的列表上并行迭代 [英] Parallel iteration over lists in makefile or CMake file

查看:110
本文介绍了在makefile或CMake文件中的列表上并行迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Makefile或CMake文件中并行循环多个列表?

Is there a way to loop over multiple lists in parallel in a makefile or CMake file?

除了AFAICT之外,我想在CMake中执行以下操作:不支持以下语法:

I would like to do something like the following in CMake, except AFAICT this syntax isn't supported:

set(a_values a0 a1 a2)
set(b_values b0 b1 b2)
foreach(a in a_values b in b_values)
  do_something_with(a b)
endforeach(a b)

这将执行:

do_something_with(a0 b0)
do_something_with(a1 b1)
do_something_with(a2 b2)

我会接受CMake或Make的答案,尽管CMake将是首选。谢谢!

I would accept an answer in either CMake or Make, though CMake would be preferred. Thanks!

推荐答案

在这里,您要去:

set(list1 1 2 3 4 5)
set(list2 6 7 8 9 0)

list(LENGTH list1 len1)
math(EXPR len2 "${len1} - 1")

foreach(val RANGE ${len2})
  list(GET list1 ${val} val1)
  list(GET list2 ${val} val2)
  message(STATUS "${val1}  ${val2}")
endforeach()

这篇关于在makefile或CMake文件中的列表上并行迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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