vs下cmake遍历文件夹并建立过滤器
function(retrieve_files out_files)
set(source_list)
foreach(dirname ${
ARGN})
file(GLOB_RECURSE files RELATIVE ${
CMAKE_CURRENT_SOURCE_DIR}
"${dirname}/*.cmake"
"${dirname}/*.h"
"${dirname}/*.hpp"
"${dirname}/*.c"
"${dirname}/*.cpp"
"${dirname}/*.cc"
)
foreach(filename ${
files})
list(APPEND source_list "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
set(file_abs_path "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
get_filename_component(source_path "${filename}" PATH)
string(REPLACE "/" "\\" filter_dir "${source_path}")
source_group("${filter_dir}" FILES "${filename}")
endforeach()
endforeach()
set(${
out_files} ${
source_list} PARENT_SCOPE)
endfunction()