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

Commit ecaa1aa

Browse files
committed
Renamed check_header_existence function to get_header_file
This is because the function returns the path to the header file and not just whether is exists or not. This change also caused separation of the function into a dedicated file
1 parent 01b31b3 commit ecaa1aa

File tree

6 files changed

+71
-22
lines changed

6 files changed

+71
-22
lines changed

cmake/Platform/Sources/HeaderExistanceChecker.cmake

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
function(_check_header_existance _header_we _dir_list _return_var)
2-
3-
foreach (include_dir ${_dir_list})
4-
5-
find_header_files("${include_dir}" include_dir_headers RECURSE)
6-
7-
foreach (included_header ${include_dir_headers})
8-
get_name_without_file_extension(${included_header} included_header_we)
9-
if ("${included_header_we}" STREQUAL "${_header_we}")
10-
set(_return_var ${included_header} PARENT_SCOPE)
11-
return()
12-
endif ()
13-
endforeach ()
14-
15-
endforeach ()
16-
17-
set(_return_var NOTFOUND PARENT_SCOPE)
18-
19-
endfunction()
20-
1+
#=============================================================================#
2+
# Checks whether the given header name is discoverable by the given target,
3+
# i.e. whether it's part of the target's 'INCLUDE_DIRECTORIES' property.
4+
# _header_we - Name of a header to check its' discoverability.
5+
# _target_name - Name of a target to check discoverability against.
6+
# _return_var - Name of variable in parent-scope holding the return value.
7+
# Returns - True if discoverable, false otherwise.
8+
#=============================================================================#
219
function(is_header_discoverable_by_target _header_we _target_name _return_var)
2210

2311
# Get target's direct include dirs
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#=============================================================================#
2+
# Retrieves full path to the file associated with the given header name,
3+
# which should be located under one of the directories in the given list.
4+
# The search is performed recursively (i.e. including sub-dirs) by default.
5+
# If the header can't be found, "NOTFOUND" string is returned.
6+
# _header_we - Name of a header file which should be retrieved.
7+
# _dir_list - List of directories which could contain the searched header file.
8+
# _return_var - Name of variable in parent-scope holding the return value.
9+
# Returns - Full path to the header file associated with the given header name, "NOTFOUND" if can't be found.
10+
#=============================================================================#
11+
function(get_header_file _header_we _dir_list _return_var)
12+
13+
foreach (include_dir ${_dir_list})
14+
15+
find_header_files("${include_dir}" include_dir_headers RECURSE)
16+
17+
foreach (included_header ${include_dir_headers})
18+
get_name_without_file_extension(${included_header} included_header_we)
19+
if ("${included_header_we}" STREQUAL "${_header_we}")
20+
set(_return_var ${included_header} PARENT_SCOPE)
21+
return()
22+
endif ()
23+
endforeach ()
24+
25+
endforeach ()
26+
27+
set(_return_var NOTFOUND PARENT_SCOPE)
28+
29+
endfunction()

cmake/Platform/Sources/IncludedHeadersRetriever.cmake renamed to cmake/Platform/Sources/SourceHeadersRetriever.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function(get_source_headers _source_file _include_dirs _return_var)
4848

4949
foreach (header ${included_headers})
5050

51-
_check_header_existance(${header} ${_include_dirs} header_path)
51+
get_header_file(${header} ${_include_dirs} header_path)
5252
if (NOT header_path OR "${header_path}" MATCHES "NOTFOUND")
5353
continue()
5454
endif ()
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include(SourceSeeker)
22
include(ExampleSourcesSeeker)
33
include(ArduinoLibrarySourcesSeeker)
4+
include(HeaderRetriever)
45
include(HeaderExistanceChecker)
5-
include(IncludedHeadersRetriever)
6+
include(SourceHeadersRetriever)
7+
include(SourcesManager)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function(get_target_include_directories _target_name _return_var)
2+
3+
# Get target's direct include dirs
4+
get_target_property(target_include_dirs ${_target_name} INCLUDE_DIRECTORIES)
5+
6+
# Get include dirs of targets linked to the given target
7+
get_target_property(target_linked_libs ${_target_name} LINK_LIBRARIES)
8+
9+
# Explictly add include dirs of all linked libraries (given they're valid cmake targets)
10+
foreach (linked_lib ${target_linked_libs})
11+
12+
if (NOT TARGET ${linked_lib}) # Might be a command-line linked library (such as 'm'/math)
13+
continue()
14+
endif ()
15+
16+
get_target_include_directories(${linked_lib} lib_include_dirs)
17+
set(include_dirs ${lib_include_dirs}) # Update list with recursive call results
18+
19+
endforeach ()
20+
21+
if (NOT "${target_include_dirs}" MATCHES "NOTFOUND") # Target has direct include dirs
22+
list(APPEND include_dirs ${target_include_dirs})
23+
endif ()
24+
25+
list(REMOVE_DUPLICATES include_dirs)
26+
27+
set(${_return_var} ${include_dirs} PARENT_SCOPE)
28+
29+
endfunction()

cmake/Platform/Utilities/Utilities.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ include(StringUtils)
44
include(PathUtils)
55
include(PropertyUtils)
66
include(LibraryUtils)
7+
include(TargetUtils)
78
include(PlatformLibraryUtils)
89
include(CMakeArgumentsUtils)

0 commit comments

Comments
 (0)