Skip to content

Commit 9a94405

Browse files
committed
Extract __arduino_collect_source_files() function
1 parent 7488ad4 commit 9a94405

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

toolchain/arduino-cli-toolchain.cmake

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,33 @@ function(__arduino_find_libraries)
612612
set(__ARDUINO_INSTALLED_LIBRARIES_CACHE "${_arduino_cache_filepath}" PARENT_SCOPE)
613613
endfunction()
614614

615+
# ======================================================================================================================
616+
# Internal utility functions that inspect CMake targets.
617+
# ======================================================================================================================
618+
619+
# ----------------------------------------------------------------------------------------------------------------------
620+
# Finds all C, C++ and Assembler sources in `DIRECTORY`, and lists them in `OUTPUT_VARIABLE`.
621+
# ----------------------------------------------------------------------------------------------------------------------
622+
function(__arduino_collect_source_files OUTPUT_VARIABLE DIRECTORY) # [DIRECTORY...]
623+
unset(_glob_pattern_list)
624+
625+
foreach(_dirpath IN ITEMS "${DIRECTORY}" LISTS ARGN)
626+
list(APPEND _glob_pattern_list
627+
"${_dirpath}/*.[cC]"
628+
"${_dirpath}/*.[cC][cC]"
629+
"${_dirpath}/*.[cC][pP][pP]"
630+
"${_dirpath}/*.[cC][xX][xX]"
631+
"${_dirpath}/*.[hH]"
632+
"${_dirpath}/*.[hH][hH]"
633+
"${_dirpath}/*.[hH][pP][pP]"
634+
"${_dirpath}/*.[hH][xX][xX]"
635+
"${_dirpath}/*.[sS]")
636+
endforeach()
637+
638+
file(GLOB_RECURSE _source_file_list ${_glob_pattern_list})
639+
set("${OUTPUT_VARIABLE}" ${_source_file_list} PARENT_SCOPE)
640+
endfunction()
641+
615642
# ======================================================================================================================
616643
# Internal utility functions that manipulate CMake targets.
617644
# ======================================================================================================================
@@ -634,22 +661,7 @@ function(__arduino_add_import_library NAME SOURCE_DIR) # [SOURCE_DIR...]
634661
list(REMOVE_DUPLICATES _library_directories)
635662
list(SORT _library_directories)
636663

637-
set(_library_glob_patterns) # <-------------------------------------------------- collect the library's source files
638-
639-
foreach(_dirpath IN LISTS _library_directories)
640-
list(APPEND _library_glob_patterns
641-
"${_dirpath}/*.[cC]"
642-
"${_dirpath}/*.[cC][cC]"
643-
"${_dirpath}/*.[cC][pP][pP]"
644-
"${_dirpath}/*.[cC][xX][xX]"
645-
"${_dirpath}/*.[hH]"
646-
"${_dirpath}/*.[hH][hH]"
647-
"${_dirpath}/*.[hH][pP][pP]"
648-
"${_dirpath}/*.[hH][xX][xX]"
649-
"${_dirpath}/*.[sS]")
650-
endforeach()
651-
652-
file(GLOB_RECURSE _library_sources ${_library_glob_patterns})
664+
__arduino_collect_source_files(_library_sources ${_library_directories}) # <----- collect the library's source files
653665

654666
list(LENGTH _library_sources _source_file_count)
655667
list(LENGTH _library_directories _source_dir_count)

0 commit comments

Comments
 (0)