以获取包含CMakeLists.txt的所有相对路径为例说明 (注意:不包含当前路径,如果要包含当前路径则把首行脚本中的/*去掉)
file(GLOB_RECURSE childrensTemp ${CMAKE_CURRENT_SOURCE_DIR}/*/CMakeLists.txt) # 获取含有文件的子目录路径,绝对路径
set(subdirectoryList "")
foreach(children ${childrensTemp})
string(REPLACE "/CMakeLists.txt" "/" childrenRmTxt ${children})
file(RELATIVE_PATH childrenRmTxtRel ${CMAKE_CURRENT_SOURCE_DIR} ${childrenRmTxt}) # 获取相对路径
message(STATUS "childrenRmTxt = ${childrenRmTxt}")
message(STATUS "childrenRmTxtRel = ${childrenRmTxtRel}")
list(APPEND subdirectoryList ${childrenRmTxtRel})
endforeach()
版权声明:本文为yunxinyi91原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。