标记为

时间:2016-09-06 04:45:52

标签: cmake

是否可以在cmake add_library函数中放置一个标志,以便减少重复的代码。 e.g。

add_library(somename SHARED

    $<TARGET_OBJECTS:xxx_objs>
    $<TARGET_OBJECTS:yyy_objs>
    $<TARGET_OBJECTS:zzz_objs>
    #if(INCLUDE_SOME_FLAG)
    $<TARGET_OBJECTS:aaa_objs>
    $<TARGET_OBJECTS:bbb_objs>
    $<TARGET_OBJECTS:ccc_objs>
    #endif(INCLUDE_SOME_FLAG)
)

如果我尝试收到错误:&#34;找不到源文件:&#34; 如果我删除标志它可以正常工作。我猜它认为该标志是一个源文件,任何方式?

1 个答案:

答案 0 :(得分:2)

set(somename_objs
    $<TARGET_OBJECTS:xxx_objs>
    $<TARGET_OBJECTS:yyy_objs>
    $<TARGET_OBJECTS:zzz_objs>)
if (INCLUDE_SOME_FLAG)
    list(APPEND somename_objs
        $<TARGET_OBJECTS:aaa_objs>
        $<TARGET_OBJECTS:bbb_objs>
        $<TARGET_OBJECTS:ccc_objs>)
endif ()
add_library(somename SHARED ${somename_objs})