Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 0d044a8

Browse files
committed
Added sketch header resolving, updated library resolving to use it
1 parent 98abedc commit 0d044a8

File tree

4 files changed

+22
-34
lines changed

4 files changed

+22
-34
lines changed
Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
#=============================================================================#
2-
# Resolves the header files included in a sketch by linking their appropriate library if necessary
3-
# or by validating they're included by the sketch target.
4-
# _target_name - Name of the target to add the sketch file to.
5-
# _sketch_file - Path to a sketch file to add to the target.
2+
# Resolves all headers used by a given sketch file by searching its 'include lines', recursively.
3+
# _target_name - Name of the sketch's target created earlier.
4+
# _sketch_file - Path to the sketch file which its' headers should be resolved.
65
# _return_var - Name of variable in parent-scope holding the return value.
76
# Returns - List of all unique header files used by the sketch file, recursively.
87
#=============================================================================#
98
function(resolve_sketch_headers _target_name _sketch_file _return_var)
109

11-
_get_source_included_headers("${_sketch_file}" sketch_headers)
12-
13-
foreach (header ${sketch_headers})
14-
15-
# Header name without extension (such as '.h') can represent an Arduino/Platform library
16-
# So first we should check whether it's a library
17-
get_name_without_file_extension("${header}" header_we)
18-
19-
is_header_discoverable_by_target(${header_we} ${_target_name} known_header)
20-
21-
if (NOT ${known_header})
22-
message(STATUS "The '${header_we}' header used by the '${_sketch_file}' sketch can't be resolved. "
23-
"It's probably a user-header which location is unknown to the framework.")
24-
endif ()
25-
26-
endforeach ()
10+
get_target_include_directories(${_target_name} target_include_dirs)
11+
get_source_headers("${_sketch_file}" ${target_include_dirs} sketch_headers RECURSIVE)
2712

2813
endfunction()

cmake/Platform/Sketches/SketchLibrariesResolver.cmake

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#=============================================================================#
2-
# Resolves the header files included in a sketch by linking their appropriate library if necessary
3-
# or by validating they're included by the sketch target.
4-
# _target_name - Name of the target to add the sketch file to.
5-
# _sketch_file - Path to a sketch file to add to the target.
2+
# Resolves the libraries used by a sketch file. It's possible that not all libraries will be resolved,
3+
# as the current algorithm relies on the name of the included headers to match a library name.
4+
# _target_name - Name of the sketch's target created earlier.
5+
# _sketch_file - Path to the sketch file which its' libraries should be resolved.
6+
# _sketch_headers - List of headers files used by the sketch, directly or indirectly.
67
#=============================================================================#
7-
function(resolve_sketch_libraries _target_name _sketch_file)
8+
function(resolve_sketch_libraries _target_name _sketch_file _sketch_headers)
89

9-
_get_source_included_headers("${_sketch_file}" sketch_headers)
10-
11-
foreach (header ${sketch_headers})
10+
foreach (header ${_sketch_headers})
1211

1312
# Header name without extension (such as '.h') can represent an Arduino/Platform library
14-
# So first we should check whether it's a library
1513
get_name_without_file_extension("${header}" header_we)
1614

1715
# Pass the '3RD_PARTY' option to avoid name-conversion

cmake/Platform/Sketches/SketchManager.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ function(add_sketch_to_target _target_name _sketch_file)
3030
# Only perform conversion if policy is set or if sketch hasn't been converted yet
3131
if (CONVERT_SKETCHES_IF_CONVERTED_SOURCES_EXISTS OR NOT EXISTS ${sketch_converted_source_path})
3232

33-
resolve_sketch_libraries(${_target_name} ${_sketch_file})
33+
resolve_sketch_headers(${_target_name} ${_sketch_file} sketch_headers)
34+
35+
resolve_sketch_libraries(${_target_name} ${_sketch_file} "${sketch_headers}")
3436

3537
convert_sketch_to_source(${_sketch_file} ${sketch_converted_source_path})
3638

cmake/Platform/Sources/SourceHeadersRetriever.cmake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,36 @@ endfunction()
3636
#=============================================================================#
3737
# Retrieves all headers used by a source file, possibly recursively (Headers used by headers).
3838
# _source_file - Path to a source file to get its' used headers.
39+
# _search_dirs - List of directories where headers should be searched at.
3940
# [RECURSIVE] - Whether to search for headers recursively.
4041
# _return_var - Name of variable in parent-scope holding the return value.
4142
# Returns - List of full paths to the headers that are used by the given source file.
4243
#=============================================================================#
43-
function(get_source_headers _source_file _include_dirs _return_var)
44+
function(get_source_headers _source_file _search_dirs _return_var)
4445

4546
cmake_parse_arguments(parsed_args "RECURSIVE" "" "" ${ARGN})
4647

4748
_get_source_included_headers(${_source_file} included_headers WE)
4849

4950
foreach (header ${included_headers})
5051

51-
get_header_file(${header} ${_include_dirs} header_path)
52+
get_header_file(${header} ${_search_dirs} header_path)
5253
if (NOT header_path OR "${header_path}" MATCHES "NOTFOUND")
5354
continue()
5455
endif ()
5556

5657
list(APPEND final_included_headers ${header_path})
5758

5859
if (parsed_args_RECURSIVE)
59-
get_source_headers(${header_path} ${_include_dirs} recursive_included_headers RECURSIVE)
60+
get_source_headers(${header_path} ${_search_dirs} recursive_included_headers RECURSIVE)
6061
list(APPEND final_included_headers ${recursive_included_headers})
6162
endif ()
6263

6364
endforeach ()
6465

65-
list(REMOVE_DUPLICATES final_included_headers)
66+
if (final_included_headers)
67+
list(REMOVE_DUPLICATES final_included_headers)
68+
endif ()
6669

6770
set(${_return_var} ${final_included_headers} PARENT_SCOPE)
6871

0 commit comments

Comments
 (0)