cmake_minimum_required(VERSION 3.22)
message("循环获取变量值的方式")
set(a 1)
foreach(currentElement ${a} b c) # 获取变量值的方式
# 循环遍历列表
message("foreach loop value is ${currentElement}")
endforeach()
message("双重循环获取变量值的方式")
set(a 1 2 3 4) # 双重循环
foreach(currentElement ${a} b c)
# 循环遍历列表
message("foreach loop value is ${currentElement}")
endforeach()
message("循环列表获取变量值的方式")
set(listA 1 2 3 4)
foreach(currentElement IN LISTS listA)
# 循环遍历列表
message("foreach loop value is ${currentElement}")
endforeach()
message("按顺序循环两个列表获取变量值的方式")
message("结尾添加单项")
set(listA 1 2 3 4)
set(listB a b c d)
foreach(currentElement IN LISTS listA listB ITEMS x y)
# 循环遍历列表
message("foreach loop value is ${currentElement}")
endforeach()
message("循环获取值ZIP_LISTS")
set(listA 1 2 3 4)
set(listB a b c d)
foreach(val IN ZIP_LISTS listA listB )
# 循环遍历列表
message("foreach loop value is ${val_0} ${val_1}")
endforeach()
message("for循环RANGE")
foreach(val RANGE 0 6)
# 循环遍历列表
message("foreach loop value is ${val}")
endforeach()
标签:set,cmake,value,currentElement,foreach,message,循环
From: https://www.cnblogs.com/starcos/p/16856484.html