Created
November 29, 2016 15:12
-
-
Save elda27/a33c31bf8f1bae3e0ed073ec4e5ad832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# \brief ディレクトリを再帰的に走査し,全てのディレクトリからファイルを探索する | |
# \param[in] root_dir 探索対象のルートディレクトリ.このディレクトリからの相対パスがフィルタとして追加される. | |
# \param[in] find_directory 探索ディレクトリが保存されたリストの変数名 | |
# \param[out] header_files ヘッダーファイルを保存する変数名 | |
# \param[out] source_files ソースファイルを保存する変数名 | |
# \param[in] optional 除外するディレクトリの指定 | |
FUNCTION(RecursiveGroupingWithFileSet root_dir find_directory header_files source_files ) | |
FILE(GLOB_RECURSE local_headers ${root_dir}/*.hpp ${root_dir}/*.hxx ${root_dir}/*.h) | |
FILE(GLOB_RECURSE local_sources ${root_dir}/*.cpp ${root_dir}/*.cxx ${root_dir}/*.c ${root_dir}/*.inl) | |
IF(${ARGC} GREATER 4) | |
MATH(EXPR arg_num "${ARGC} - 1") | |
FOREACH(i RANGE 4 ${arg_num}) | |
LIST(GET ARGV ${i} tmp) | |
LIST(APPEND ignore_directories ${tmp}) | |
ENDFOREACH() | |
FOREACH(file ${local_headers}) | |
SET(BREAK_FLAG OFF) | |
FOREACH(ig_dir ${ignore_directories}) | |
FILE(RELATIVE_PATH relative_path ${ig_dir} ${file}) | |
IF(NOT ${relative_path} MATCHES "^\\.\\.") | |
SET(BREAK_FLAG ON) | |
BREAK() | |
ENDIF() | |
ENDFOREACH() | |
IF(NOT ${BREAK_FLAG}) | |
LIST(APPEND tmp_headers ${file}) | |
ELSE() | |
MESSAGE(Remove Header:${file}) | |
ENDIF() | |
ENDFOREACH() | |
FOREACH(file ${local_sources}) | |
SET(BREAK_FLAG OFF) | |
FOREACH(ig_dir ${ignore_directories}) | |
FILE(RELATIVE_PATH relative_path ${ig_dir} ${file}) | |
IF(NOT ${relative_path} MATCHES "^\\.\\.") | |
SET(BREAK_FLAG ON) | |
BREAK() | |
ENDIF() | |
ENDFOREACH() | |
IF(NOT ${BREAK_FLAG}) | |
LIST(APPEND tmp_sources ${file}) | |
ELSE() | |
MESSAGE(Remove Source:${file}) | |
ENDIF() | |
ENDFOREACH() | |
SET(local_sources ${tmp_sources}) | |
SET(local_headers ${tmp_headers}) | |
ENDIF() | |
SET(${source_files} ${local_sources} PARENT_SCOPE) | |
SET(${header_files} ${local_headers} PARENT_SCOPE) | |
FOREACH(file ${local_sources}) | |
# FOREACH(dir ${${find_directory}}) | |
file(RELATIVE_PATH relative ${root_dir} ${file}) | |
STRING(REGEX MATCHALL "[^/]+" filters "${relative}") | |
LIST(LENGTH filters output_length) | |
MATH(EXPR iteration "${output_length} - 2") | |
IF(${iteration} LESS 0) | |
continue() | |
ENDIF() | |
SET(group_string "") | |
FOREACH(i RANGE 0 ${iteration}) | |
LIST(GET filters ${i} g) | |
set(group_string "${group_string}\\${g}") | |
# MESSAGE(${i},${output_length}:${g}) | |
ENDFOREACH() | |
SOURCE_GROUP("Source Files${group_string}" FILES ${file}) | |
# ENDFOREACH() | |
ENDFOREACH() | |
FOREACH(file ${local_headers}) | |
# FOREACH(dir ${${find_directory}}) | |
file(RELATIVE_PATH relative ${root_dir} ${file}) | |
STRING(REGEX MATCHALL "[^/]+" filters "${relative}") | |
LIST(LENGTH filters output_length) | |
MATH(EXPR iteration "${output_length} - 2") | |
IF(${iteration} LESS 0) | |
continue() | |
ENDIF() | |
SET(group_string "") | |
FOREACH(i RANGE 0 ${iteration}) | |
LIST(GET filters ${i} g) | |
set(group_string "${group_string}\\${g}") | |
# MESSAGE(${i},${output_length}:${g}) | |
ENDFOREACH() | |
SOURCE_GROUP("Header Files${group_string}" FILES ${file}) | |
# ENDFOREACH() | |
ENDFOREACH() | |
ENDFUNCTION() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment