From feff049df1dab831fc0389c369273cc1cf6cc7ea Mon Sep 17 00:00:00 2001 From: Alister Date: Thu, 11 Nov 2021 21:12:23 +0000 Subject: [PATCH] Create cmake_function.cmake --- cmake/cmake_function.cmake | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 cmake/cmake_function.cmake diff --git a/cmake/cmake_function.cmake b/cmake/cmake_function.cmake new file mode 100644 index 00000000..0fdf286c --- /dev/null +++ b/cmake/cmake_function.cmake @@ -0,0 +1,40 @@ +#collect source files from given directory +FUNCTION(collect_files output base_dir do_recurse globbing_exprs exclude_dirs) + IF("${do_recurse}") + SET(glob GLOB_RECURSE) + ELSE() + SET(glob GLOB) + ENDIF() + + SET(base_dir "${CMAKE_SOURCE_DIR}/${base_dir}") + LIST(TRANSFORM globbing_exprs PREPEND "${base_dir}/") + FILE(${glob} files CONFIGURE_DEPENDS ${globbing_exprs}) + + FOREACH(file IN LISTS files) + SET(match FALSE) + + FOREACH(dir IN LISTS exclude_dirs) + IF("${file}" MATCHES "/${dir}/") + SET(match TRUE) + ENDIF() + ENDFOREACH() + + IF(NOT ${match}) + LIST(APPEND result "${file}") + ENDIF() + + ENDFOREACH() + SET(${output} "${result}" PARENT_SCOPE) +ENDFUNCTION() + +FUNCTION(contains_filter output files regex) + + FOREACH(file IN LISTS files) + FILE(STRINGS "${file}" contents REGEX "${regex}") + IF("${contents}") + LIST(APPEND result "${file}") + MESSAGE("Moced: ${file}") + ENDIF() + ENDFOREACH() + SET(${output} "${result}" PARENT_SCOPE) +ENDFUNCTION() \ No newline at end of file