@@ -623,29 +623,32 @@ function(__arduino_add_import_library NAME SOURCE_DIR) # [SOURCE_DIR...]
623623 set (_library_source_dir "${CMAKE_BINARY_DIR} /ArduinoFiles/${NAME} " )
624624 set (_library_template "${ARDUINO_TOOLCHAIN_DIR} /Templates/ArduinoLibraryCMakeLists.txt.in" )
625625 set (_library_filepath "${_library_binary_dir} /lib${_libname} .a" )
626- set (_source_dir_list "${SOURCE_DIR} " ${ARGN} )
626+
627+ set (_library_directories "${SOURCE_DIR} " ${ARGN} )
628+ list (FILTER _library_directories EXCLUDE REGEX "^ *\$ " )
629+ list (REMOVE_DUPLICATES _library_directories)
630+ list (SORT _library_directories)
627631
628632 set (_library_glob_patterns) # <-------------------------------------------------- collect the library's source files
629633
630634 foreach (_dirpath IN LISTS _library_directories)
631- if (_dirpath)
632- list (APPEND _library_glob_patterns
633- "${_dirpath} /*.[cC]"
634- "${_dirpath} /*.[cC][cC]"
635- "${_dirpath} /*.[cC][pP][pP]"
636- "${_dirpath} /*.[cC][xX][xX]"
637- "${_dirpath} /*.[hH]"
638- "${_dirpath} /*.[hH][hH]"
639- "${_dirpath} /*.[hH][pP][pP]"
640- "${_dirpath} /*.[hH][xX][xX]"
641- "${_dirpath} /*.[sS]" )
642- endif ()
635+ list (APPEND _library_glob_patterns
636+ "${_dirpath} /*.[cC]"
637+ "${_dirpath} /*.[cC][cC]"
638+ "${_dirpath} /*.[cC][pP][pP]"
639+ "${_dirpath} /*.[cC][xX][xX]"
640+ "${_dirpath} /*.[hH]"
641+ "${_dirpath} /*.[hH][hH]"
642+ "${_dirpath} /*.[hH][pP][pP]"
643+ "${_dirpath} /*.[hH][xX][xX]"
644+ "${_dirpath} /*.[sS]" )
643645 endforeach ()
644646
645647 file (GLOB_RECURSE _library_sources ${_library_glob_patterns} )
646648
647649 list (LENGTH _library_sources _source_file_count)
648- message (STATUS "${_source_file_count} source files found for ${_target} " )
650+ list (LENGTH _library_directories _source_dir_count)
651+ message (STATUS "${_source_file_count} source files found for ${_target} in ${_source_dir_count} directories" )
649652
650653 list (JOIN _library_sources "\"\n \" " _quoted_library_sources) # <--------- prepare CMake to build out of tree
651654 list (JOIN _library_directories "\"\n \" " _quoted_library_directories)
@@ -679,7 +682,7 @@ function(__arduino_add_import_library NAME SOURCE_DIR) # [SOURCE_DIR...]
679682 target_link_libraries ("${_target} " INTERFACE Arduino::Core)
680683 endif ()
681684
682- target_include_directories ("${_target} " INTERFACE ${_source_dir_list } )
685+ target_include_directories ("${_target} " INTERFACE ${_library_directories } )
683686 set_property (TARGET "${_target} " PROPERTY IMPORTED_LOCATION "${_library_filepath} " )
684687 set_property (TARGET "${_target} " PROPERTY SYSTEM NO ) # otherwise AVR builds will fail
685688
0 commit comments