Parallel iteration over lists in makefile or CMake file

前端 未结 3 691
故里飘歌
故里飘歌 2021-02-12 19:35

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

I would like to do something like the following in CMake, except AFAICT this syntax i

3条回答
  •  遥遥无期
    2021-02-12 20:12

    In make you can use the GNUmake table toolkit to achieve this by handling the two lists as 1-column tables:

    include gmtt/gmtt.mk
    
    # declare the lists as tables with one column
    list_a := 1 a0 a1 a2 a3 a4 a5
    list_b := 1 b0 b1 b2
    
    # note: list_b is shorter and will be filled up with a default value
    joined_list := $(call join-tbl,$(list_a),$(list_b), /*nil*/)
    
    $(info $(joined_list))
    
    # Apply a function (simply output "") on each table row, i.e. tuple
    $(info $(call map-tbl,$(joined_list),))
    

    Output:

    2 a0 b0 a1 b1 a2 b2 a3 /*nil*/ a4 /*nil*/ a5 /*nil*/
    
    

提交回复
热议问题