cmake MATCHES不像我认为的那样工作

时间:2017-10-02 21:34:25

标签: cmake

在我的父母CMakeLists.txt中:

set(PROGRAMS "CCHIF;CCWIF;FXTINT;FXTCLI")

在我的孩子CMakeLists.txt:

set (PROJ_LIST "CCHIF;FXTCLI")
MESSAGE(STATUS "Programs is ${PROGRAMS}")
foreach (PROJ ${PROJ_LIST})
if (";${PROJ};" MATCHES ";${PROGRAMS};")
    project(${PROJ})
    add_executable(${PROJ} ${PROJ}.c)
    target_link_libraries(${PROJ} LINK_PUBLIC pthread dl)
    install(TARGETS ${PROJ} DESTINATION ${BIN_DIR})
endif()
    Message ( STATUS "${PROJ} is NOT in the programs list!!!  **********")
endforeach()

来自cmake的输出..

-- Programs is CCHIF;CCWIF;FXTINT;FXTCLI
-- CCHIF is NOT in the programs list!!!  **********
-- FXTCLI is NOT in the programs list!!!  **********

我试过有没有“; ....;” (quote /分号)用于MATCHES的参数。我之前成功使用过MATCHES。在这种情况下它不起作用。 我有超过50个子程序,我正在为许多网站建设。有些网站需要全部50个,有些只需要其中的一部分。所以我想把Parent的CMakeLists.txt中需要的程序放到每个站点。感谢

1 个答案:

答案 0 :(得分:1)

我可能会使用子命令list(FIND)来执行相同的任务:

cmake_minimum_required(VERSION 3.9)  # put your version...
set(PROGRAMS CCHIF CCWIF FXTINT FXTCLI)
set(PROJ_LIST CCHIF FXTCLI JACK)  # added JACK to see that it will not match any element in the list
foreach(PROJ ${PROJ_LIST})
    list (FIND PROGRAMS ${PROJ} _index)
    if(${_index} GREATER -1)
        message("Project selected: ${PROJ} in programs list")
        project(${PROJ})
        add_executable(${PROJ} ${PROJ}.c)
        target_link_libraries(${PROJ} LINK_PUBLIC pthread dl)
        install(TARGETS ${PROJ} DESTINATION ${BIN_DIR})
    else(${_index} GREATER -1)
        message(STATUS "${PROJ} is NOT in the programs list!!! ******")
    endif(${_index} GREATER -1)
endforeach()