@@ -27,21 +27,29 @@ function(target_source_directories _target_name)
2727 list (REMOVE_DUPLICATES source_dirs)
2828
2929 if (parsed_args_RECURSE) # Search recursively
30+
3031 foreach (source_dir ${source_dirs} )
32+
3133 find_header_files(${source_dir} headers RECURSE)
3234 find_source_files(${source_dir} sources RECURSE)
3335
3436 list (APPEND collective_headers ${headers} )
3537 list (APPEND collective_sources ${sources} )
38+
3639 endforeach ()
40+
3741 else ()
42+
3843 foreach (source_dir ${source_dirs} )
44+
3945 find_header_files(${source_dir} headers)
4046 find_source_files(${source_dir} sources )
4147
4248 list (APPEND collective_headers ${headers} )
4349 list (APPEND collective_sources ${sources} )
50+
4451 endforeach ()
52+
4553 endif ()
4654
4755 if (collective_headers)
@@ -54,6 +62,7 @@ function(target_source_directories _target_name)
5462
5563 # Treat headers' parent directories as include directories of the target
5664 get_headers_parent_directories("${collective_headers} " include_dirs)
65+
5766 target_include_directories (${_target_name} PUBLIC ${include_dirs} )
5867
5968 target_sources (${_target_name} PUBLIC ${collective_sources} )
@@ -73,6 +82,7 @@ function(get_source_file_includes _source_file _return_var)
7382 endif ()
7483
7584 file (STRINGS "${_source_file} " source_lines)
85+
7686 list (FILTER source_lines INCLUDE REGEX "${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN} " )
7787
7888 set (${_return_var} ${source_lines} PARENT_SCOPE)
@@ -91,17 +101,22 @@ function(get_source_file_included_headers _source_file _return_var)
91101 cmake_parse_arguments (headers "WE" "" "" ${ARGN} )
92102
93103 file (STRINGS "${_source_file} " source_lines) # Loc = Lines of code
104+
94105 list (FILTER source_lines INCLUDE REGEX ${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN} )
95106
96107 # Extract header names from inclusion
97108 foreach (loc ${source_lines} )
109+
98110 string (REGEX MATCH ${ARDUINO_CMAKE_HEADER_NAME_REGEX_PATTERN} match ${loc} )
111+
99112 if (headers_WE)
100113 get_name_without_file_extension("${CMAKE_MATCH_1} " header_name)
101114 else ()
102115 set (header_name ${CMAKE_MATCH_1} )
103116 endif ()
117+
104118 list (APPEND headers ${header_name} )
119+
105120 endforeach ()
106121
107122 set (${_return_var} ${headers} PARENT_SCOPE)
@@ -119,10 +134,15 @@ function(get_headers_parent_directories _sources _return_var)
119134
120135 # Extract header files
121136 list (FILTER _sources INCLUDE REGEX "${ARDUINO_CMAKE_HEADER_FILE_EXTENSION_REGEX_PATTERN} " )
137+
122138 foreach (header_source ${_sources} )
139+
123140 get_filename_component (header_parent_dir ${header_source} DIRECTORY )
141+
124142 list (APPEND parent_dirs ${header_parent_dir} )
143+
125144 endforeach ()
145+
126146 if (parent_dirs) # Check parent dirs, could be none if there aren't any headers amongst sources
127147 list (REMOVE_DUPLICATES parent_dirs)
128148 endif ()
0 commit comments