利用文件夹对源文件进行分组
# Organize them into source groups based on their directory
foreach(source ${MY_SOURCES})
# Get the directory of the source file
get_filename_component(source_dir "${source}" PATH)
# Remove common path prefix
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" group "${source_dir}")
string(REPLACE "path_prefix/" "" group "${group}")
# Make sure we use forward slashes even on Windows
string(REPLACE "\\" "/" group "${group}")
# Group by folder
source_group("${group}" FILES "${source}")
endforeach()
参考资料:
- https://blog.csdn.net/qq_40709711/article/details/135040600