在CMake中,如何将命令的多行输出转换为列表? [英] In CMake how do turn a multi line output of a command into a list?

查看:52
本文介绍了在CMake中,如何将命令的多行输出转换为列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情

execute_process(
    COMMAND bash -c "git --git-dir ${CMAKE_SOURCE_DIR}/.git ls-files"
OUTPUT_VARIABLE TRACKED_FILES)

add_custom_target(all_file_project SOURCES ${TRACKED_FILES})

命令本身似乎按预期工作,但是生成的变量"TRACKED_FILES"仅包含一个逻辑条目(一个多行字符串),而不是文件列表.

And the command itself seems to work as expected but the generated variable "TRACKED_FILES" contains only one logical entry (one multi line string) rather than a list of files.

我可以以某种方式将包含用换行符("\ n")分隔的多行的字符串转换为CMake中的列表吗?

Can I somehow turn a string containing multiple lines separated by a newline ("\n") into a list in CMake?

推荐答案

一个选项(正如我的问题的标题所示)是手动主动拆分字符串,而不是首先将变量解释为列表:

One option (as the title of my question suggests) is to actively split the string manually rather than interpreting a variable as list in the first place:

string(REPLACE "\n" ";" ADDITIONAL_PROJECT_FILES_LIST ${ADDITIONAL_PROJECT_FILES})

这对我有用,但是拥有更抽象,更少平台特定的东西(例如,我不知道这是否适用于包括Windows在内的所有操作系统)将是非常好的

This works for me but it would be very nice to have something more abstract and less platform specific (e.g. I don't know whether this works on all OSes including Windows)

类似于 execute_process(COMMAND find -type f OUTPUT_LIST_VARIABLE MY_LIST)

或至少 set(MY_LIST FROM_MULTILINE MY_MULTILINE_STRING)

这篇关于在CMake中,如何将命令的多行输出转换为列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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