简体   繁体   English

CMake Glob文件列表,没有目录路径

[英]CMake glob list of files without directory path

I searched estensively on this site and beyond, but i can't seem to find the solution to this problem: 我在该网站上进行了广泛的搜索,但似乎找不到解决此问题的方法:

If you glob a list of files with file(GLOB..) in CMake, the files are all listed with their full path attached. 如果您在CMake中使用文件(GLOB ..)列出文件列表,则所有文件都将列出其完整路径。

How can i glob a group of files in CMake saving only the name of the files? 我如何在CMake中全局保存一组文件,仅保存文件名?

I read the official manual and here i found this: 我阅读了官方手册 ,在这里我发现了这一点:

 file(GLOB <variable>
 [LIST_DIRECTORIES true|false] [RELATIVE <path>]
 [<globbing-expressions>...])

and

 By default GLOB lists directories - directories are omitted in result 
 if LIST_DIRECTORIES is set to false.

I tried these solutions, but none of them works: 我尝试了这些解决方案,但是它们都不起作用:

file(GLOB_RECURSE src_files LIST_DIRECTORIES false ${SRC})

file(GLOB_RECURSE src_files LIST_DIRECTORIES=false ${SRC})

file(GLOB_RECURSE src_files LIST_DIRECTORIES(false) ${SRC})

set(LIST_DIRECTORIES false)
file(GLOB_RECURSE src_files ${SRC})

But none of these seems to work. 但是这些似乎都不起作用。 My output is always the list of the files with full path attached. 我的输出始终是带有完整路径的文件列表。 I know i could use RELATIVE to set the path accordingly, but i would prefer to avoid it if i can. 我知道我可以使用RELATIVE来相应地设置路径,但是如果可以的话,我宁愿避免使用它。

Thank you for your answers! 谢谢您的回答!

LIST_DIRECTORIES is used to include/exclude directories in your results in situation when given location ${SRC} contains both files and directories. 在给定位置${SRC}包含文件和目录的情况下, LIST_DIRECTORIES用于在结果中包括/排除目录。

If you want to get rid of path, use foreach along with get_filename_component on results from file(GLOB_RECURSE...) 如果要摆脱路径,请对file(GLOB_RECURSE...)结果file(GLOB_RECURSE...)使用foreach以及get_filename_component

Try 尝试

file(GLOB_RECURSE LIST_DIRECTORIES false src_files ${SRC})

Documentation is erroneous, LIST_DIRECTORIES comes before variable 文档是错误的, LIST_DIRECTORIES在变量之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM