|
1 | | -#=============================================================================# |
2 | | -# Retrieves all headers used by a sketch, which is much like extracting the headers included |
3 | | -# by a source file. Headers are returned by their name, with extension (such as '.h'). |
4 | | -# _sketch_file - Path to a sketch file to add to the target. |
5 | | -# _return_var - Name of variable in parent-scope holding the return value. |
6 | | -# Returns - List of headers names with extension that are included by the given sketch file. |
7 | | -#=============================================================================# |
8 | | -function(_get_sketch_headers _sketch_file _return_var) |
9 | | - |
10 | | - file(STRINGS "${_sketch_file}" sketch_loc) # Loc = Lines of code |
11 | | - list(FILTER sketch_loc INCLUDE REGEX ${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN}) |
12 | | - |
13 | | - # Extract header names from inclusion |
14 | | - foreach (loc ${sketch_loc}) |
15 | | - string(REGEX MATCH ${ARDUINO_CMAKE_HEADER_NAME_REGEX_PATTERN} ${loc} match) |
16 | | - list(APPEND headers ${CMAKE_MATCH_1}) |
17 | | - endforeach () |
18 | | - |
19 | | - set(${_return_var} ${headers} PARENT_SCOPE) |
20 | | - |
21 | | -endfunction() |
22 | | - |
23 | 1 | #=============================================================================# |
24 | 2 | # Validates a header file is included by the given target. |
25 | 3 | # i.e The header is located under one of the target's include directories. |
@@ -51,23 +29,24 @@ endfunction() |
51 | 29 | #=============================================================================# |
52 | 30 | function(resolve_sketch_headers _target_name _board_id _sketch_file) |
53 | 31 |
|
54 | | - _get_sketch_headers("${_sketch_file}" sketch_headers) |
| 32 | + get_source_file_included_headers("${_sketch_file}" sketch_headers) |
55 | 33 | foreach (header ${sketch_headers}) |
56 | 34 | # Header name without extension (such as '.h') can represent an Arduino/Platform library |
57 | 35 | # So first we should check whether it's a library |
58 | | - string(REGEX MATCH "(.+)\\." "${header}" header_we_match) |
59 | | - set(header_we ${CMAKE_MATCH_1}) |
| 36 | + get_name_without_file_extension("${header}" header_we) |
60 | 37 |
|
61 | | - if (${header_we} IN_LIST ARDUINO_CMAKE_PLATFORM_LIBRARIES) |
62 | | - link_platform_library(${_target_name} ${header_we} ${_board_id}) |
| 38 | + is_platform_library(${header_we} is_header_platform_lib) |
| 39 | + if (is_header_platform_lib) |
| 40 | + string(TOLOWER ${header_we} header_we_lower) |
| 41 | + link_platform_library(${_target_name} ${header_we_lower} ${_board_id}) |
63 | 42 | else () |
64 | 43 | find_arduino_library(${header_we}_sketch_lib ${header_we} ${_board_id}) |
65 | 44 | # If library isn't found, display a wraning since it might be a user library |
66 | | - if (NOT ${header_we}_sketch_lib OR "${${header_we}_sketch_lib}" MATCHES "NOTFOUND") |
| 45 | + if (NOT TARGET ${header_we}_sketch_lib OR "${${header_we}_sketch_lib}" MATCHES "NOTFOUND") |
67 | 46 | _validate_target_includes_header(${_target_name} ${header} is_header_validated) |
68 | 47 | if (NOT is_header_validated) |
69 | 48 | # Header hasn't been found in any of the target's include directories, Display warning |
70 | | - message(WARNING "The header '${_header}' is used by the \ |
| 49 | + message(WARNING "The header '${header_we}' is used by the \ |
71 | 50 | '${_sketch_file}' sketch \ |
72 | 51 | but it isn't a Arduino/Platform library, nor it's linked \ |
73 | 52 | to the target manually!") |
|
0 commit comments