以获取包含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()