1+ function (_check_header_existance _header_we _dir_list _return_var)
2+
3+ foreach (include_dir ${_dir_list} )
4+ find_header_files("${include_dir} " include_dir_headers RECURSE)
5+
6+ foreach (included_header ${include_dir_headers} )
7+ get_name_without_file_extension(${included_header} included_header_we)
8+ if ("${included_header_we} " STREQUAL "${_header_we} " )
9+ set (_return_var TRUE PARENT_SCOPE)
10+ return ()
11+ endif ()
12+ endforeach ()
13+
14+ endforeach ()
15+
16+ set (_return_var FALSE PARENT_SCOPE)
17+
18+ endfunction ()
19+
20+ function (_is_known_header _header_we _target_name _return_var)
21+
22+ # Get target's direct include dirs
23+ get_target_property (target_include_dirs ${_target_name} INCLUDE_DIRECTORIES )
24+
25+ # Get include dirs of targets linked to the given target
26+ get_target_property (target_linked_libs ${_target_name} LINK_LIBRARIES )
27+
28+ # Explictly add include dirs of all linked libraries (given they're valid cmake targets)
29+ foreach (linked_lib ${target_linked_libs} )
30+
31+ if (NOT TARGET ${linked_lib} )
32+ continue ()
33+ endif ()
34+
35+ get_target_property (lib_include_dirs ${linked_lib} INCLUDE_DIRECTORIES )
36+ if (NOT "${lib_include_dirs} " MATCHES "NOTFOUND" ) # Library has include dirs
37+ list (APPEND include_dirs ${lib_include_dirs} )
38+ endif ()
39+
40+ endforeach ()
41+
42+ if (NOT "${target_include_dirs} " MATCHES "NOTFOUND" ) # Target has direct include dirs
43+ list (APPEND include_dirs ${target_include_dirs} )
44+ endif ()
45+
46+ _check_header_existance(${_header_we} ${include_dirs} header_found)
47+
48+ set (_return_var ${header_found} PARENT_SCOPE)
49+
50+ endfunction ()
51+
152#=============================================================================#
253# Resolves the header files included in a sketch by linking their appropriate library if necessary
354# or by validating they're included by the sketch target.
@@ -14,32 +65,21 @@ function(resolve_sketch_headers _target_name _sketch_file)
1465 # So first we should check whether it's a library
1566 get_name_without_file_extension("${header} " header_we)
1667
17- is_platform_library(${header_we} is_header_platform_lib)
68+ # Pass the '3RD_PARTY' option to avoid name-conversion
69+ find_arduino_library(${header_we} _sketch_lib ${header_we} 3RD_PARTY QUIET )
1870
19- if (is_header_platform_lib )
71+ if (NOT TARGET ${header_we} _sketch_lib OR "${ ${header_we} _sketch_lib}" MATCHES "NOTFOUND" )
2072
21- string (TOLOWER ${header_we} header_we_lower)
73+ # The header name doesn't conform to a name of a known library, search individual headers instead
74+ _is_known_header(${header_we} ${_target_name} known_header)
2275
23- link_platform_library(${_target_name} ${header_we_lower} )
24-
25- else ()
26-
27- # Pass the '3RD_PARTY' option to avoid name-conversion
28- find_arduino_library(${header_we} _sketch_lib ${header_we} 3RD_PARTY QUIET )
29-
30- # If library isn't found, display a status since it might be a user library
31- if (NOT TARGET ${header_we} _sketch_lib OR
32- "${${header_we} _sketch_lib}" MATCHES "NOTFOUND" )
33-
34- message (STATUS "The header '${header_we} ' is used by the '${_sketch_file} ' sketch, "
35- "but it isn't part of an Arduino nor a Platform library.\n\t "
36- "However, it may be part of a user library but "
37- "you'd have to check this manually!" )
38-
39- else ()
40- link_arduino_library(${_target_name} ${header_we} _sketch_lib)
76+ if (NOT ${known_header} )
77+ message (STATUS "The '${header_we} ' header used by the '${_sketch_file} ' sketch can't be resolved. "
78+ "It's probably a user-header which location is unknown to the framework." )
4179 endif ()
4280
81+ else ()
82+ link_arduino_library(${_target_name} ${header_we} _sketch_lib)
4383 endif ()
4484
4585 endforeach ()
0 commit comments