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

Commit 26b3981

Browse files
committed
Documented many new functions and renamed a few, all related to architecture.
1 parent e7d46d3 commit 26b3981

File tree

5 files changed

+97
-54
lines changed

5 files changed

+97
-54
lines changed

cmake/Platform/Arduino.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ include(TargetFlagsManager)
2121
include(SourcesManager)
2222
include(SketchManager)
2323
include(DefaultsManager)
24-
include(SupportedArchitecturesRetriever)
24+
include(ArchitectureSupportQuery)
2525

2626
include(Libraries)
2727

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
1+
#=============================================================================#
2+
# Gets a list of architectures supported by a library.
3+
# The list is read from the given properties file, which includes metadata about the library.
4+
# _library_properties_file - Full path to a library's properties file
5+
# (usually named 'library,propertie').
6+
# _return_var - Name of variable in parent-scope holding the return value.
7+
# Returns - List of architectures supported by the library or '*'
8+
# if it's architecture-agnostic (Supports all arhcitectures).
9+
#=============================================================================#
110
function(get_arduino_library_supported_architectures _library_properties_file _return_var)
211

312
file(STRINGS ${_library_properties_file} library_properties)
413

514
list(FILTER library_properties INCLUDE REGEX "arch")
15+
616
_get_property_value("${library_properties}" _library_arch_list)
17+
718
string(REPLACE "," ";" _library_arch_list ${_library_arch_list}) # Turn into a valid list
819

920
set(${_return_var} ${_library_arch_list} PARENT_SCOPE)
1021

1122
endfunction()
12-
13-
#=============================================================================#
14-
# Gets the library architecure if any, read from the given library properties file
15-
# which includes this information.
16-
# _library_arch_list - List of architectures supported by the library,
17-
# inferred from its' 'library.properties' file.
18-
# _return_var - Name of variable in parent-scope holding the return value.
19-
# Returns - If library is architecure agnostic (Supports all), nothing is returned.
20-
# If library doesn't support the current platform's architecture,
21-
# "UNSUPPORTED" string is returned.
22-
# Otherwise, the platform's architecture is returned.
23-
#=============================================================================#
24-
function(is_library_supports_platform_architecture _library_arch_list _return_var)
25-
26-
if ("${_library_arch_list}" MATCHES "\\*") # Any architecture is supported
27-
set(result TRUE)
28-
else ()
29-
if (${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE} IN_LIST _library_arch_list)
30-
set(result TRUE) # Our platform's arch is supported
31-
else ()
32-
set(result FALSE) # Our arch isn't supported
33-
endif ()
34-
endif ()
35-
36-
set(${_return_var} ${result} PARENT_SCOPE)
37-
38-
endfunction()

cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
1-
function(_filter_unsupported_arch_sources _unsupported_archs_regex _sources _return_var)
1+
#=============================================================================#
2+
# Attempts to retrieve a library's properties file based on its' root directory.
3+
# If couldn't be found, CMake generates a warning and returns an empty string.
4+
# _library_root_directory - Path to library's root directory. Can be relative.
5+
# _return_var - Name of variable in parent-scope holding the return value.
6+
# Returns - Full path to library's properties file.
7+
#=============================================================================#
8+
function(_get_library_properties_file _library_root_directory _return_var)
9+
10+
# Get the absolute root directory (full path)
11+
get_filename_component(absolute_lib_root_dir ${_library_root_directory} ABSOLUTE)
12+
13+
if (EXISTS ${absolute_lib_root_dir}/library.properties)
14+
set(lib_props_file ${absolute_lib_root_dir}/library.properties)
15+
else () # Properties file can't be found
16+
17+
# Warn user and assume library is arch-agnostic
18+
get_filename_component(library_name ${absolute_lib_root_dir} NAME)
19+
message(WARNING "\"${library_name}\" library's properties file can't be found "
20+
"under its' root directory - Assuming the library "
21+
"is architecture-agnostic (supports all architectures)")
22+
set(lib_props_file "")
23+
24+
endif ()
25+
26+
set(${_return_var} ${lib_props_file} PARENT_SCOPE)
227

3-
#string(LENGTH _unsupported_archs_regex num_of_unsupported_archs)
28+
endfunction()
29+
30+
#=============================================================================#
31+
# Filters sources that relate to an architecture from the given list of unsupported architectures.
32+
# _unsupported_archs_regex - List of unsupported architectures as a regex-pattern string.
33+
# _sources - List of sources to check and potentially filter.
34+
# _return_var - Name of variable in parent-scope holding the return value.
35+
# Returns - Filtered list of sources containing only those that don't relate to
36+
# any unsupported architecture.
37+
#=============================================================================#
38+
function(_filter_unsupported_arch_sources _unsupported_archs_regex _sources _return_var)
439

540
if (NOT "${_unsupported_archs_regex}" STREQUAL "") # Not all architectures are supported
641
# Filter sources dependant on unsupported architectures
@@ -11,42 +46,42 @@ function(_filter_unsupported_arch_sources _unsupported_archs_regex _sources _ret
1146

1247
endfunction()
1348

14-
function(resolve_library_sources_by_architecture _library_root_dir _library_sources _return_var)
49+
#=============================================================================#
50+
# Resolves library's architecture-related elements by doing several things:
51+
# 1. Checking whether the platform's architecture is supported by the library
52+
# 2. Filtering out any library sources that relate to unsupported architectures, i.e
53+
# architectures other than the platform's.
54+
# If the platform's architecture isn't supported by the library, CMake generates an error and stops.
55+
# _library_root_dir - Path to library's root directory. Can be relative.
56+
# _library_sources - List of library's sources to check and potentially filter.
57+
# _return_var - Name of variable in parent-scope holding the return value.
58+
# Returns - Filtered list of sources containing only those that don't relate to
59+
# any unsupported architecture.
60+
#=============================================================================#
61+
function(resolve_library_architecture _library_root_dir _library_sources _return_var)
1562

1663
cmake_parse_arguments(parsed_args "" "LIB_PROPS_FILE" "" ${ARGN})
1764

1865
if (parsed_args_LIB_PROPS_FILE) # Library properties file is given
1966
set(lib_props_file ${parsed_args_LIB_PROPS_FILE})
20-
else () # Try to automatically find file from sources
67+
else ()
68+
# Try to automatically find file from sources
69+
_get_library_properties_file(${_library_root_dir} lib_props_file)
2170

22-
# Get the absolute root directory (full path)
23-
get_filename_component(absolute_lib_root_dir ${_library_root_dir} ABSOLUTE)
24-
25-
if (EXISTS ${absolute_lib_root_dir}/library.properties)
26-
set(lib_props_file ${absolute_lib_root_dir}/library.properties)
27-
28-
else () # Properties file can't be found - Warn user and assume library is arch-agnostic
29-
30-
get_filename_component(library_name ${absolute_lib_root_dir} NAME)
31-
message(WARNING "\"${library_name}\" library's properties file can't be found "
32-
"under its' root directory - Assuming the library "
33-
"is architecture-agnostic (supports all architectures)")
34-
set(${_return_var} ${_library_sources} PARENT_SCOPE)
71+
if ("${lib_props_file}" STREQUAL "") # Properties file couldn't be found
72+
set(${_return_var} "${_library_sources}" PARENT_SCOPE)
3573
return()
36-
3774
endif ()
38-
3975
endif ()
4076

4177
get_arduino_library_supported_architectures("${lib_props_file}" lib_archs)
42-
is_library_supports_platform_architecture(${lib_archs} arch_supported_by_lib)
78+
79+
# Check if the platform's architecture is supported by the library
80+
is_platform_architecture_supported(${lib_archs} arch_supported_by_lib)
4381

4482
if (NOT ${arch_supported_by_lib})
45-
string(CONCAT error_message
46-
"The ${_library_name} "
47-
"library isn't supported on the platform's architecture "
48-
"${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE}")
49-
message(SEND_ERROR ${error_message})
83+
message(SEND_ERROR "The platform's architecture, ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE}, "
84+
"isn't supported by the ${_library_name} library")
5085
endif ()
5186

5287
get_unsupported_architectures("${lib_archs}" unsupported_archs REGEX)

cmake/Platform/Other/SupportedArchitecturesRetriever.cmake renamed to cmake/Platform/Other/ArchitectureSupportQuery.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
#=============================================================================#
2+
# Checks whether the platform's architecture is supported in the context of the given list
3+
# of architectures, i.e If the list contains the platform's architecture.
4+
# _arch_list - List of architectures supported by the library,
5+
# inferred from its' 'library.properties' file.
6+
# _return_var - Name of variable in parent-scope holding the return value.
7+
# Returns - True if supported, false otherwise.
8+
#=============================================================================#
9+
function(is_platform_architecture_supported _arch_list _return_var)
10+
11+
if ("${_arch_list}" MATCHES "\\*") # Any architecture is supported
12+
set(result TRUE)
13+
else ()
14+
if (${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE} IN_LIST _arch_list)
15+
set(result TRUE) # Our platform's arch is supported
16+
else ()
17+
set(result FALSE) # Our arch isn't supported
18+
endif ()
19+
endif ()
20+
21+
set(${_return_var} ${result} PARENT_SCOPE)
22+
23+
endfunction()
24+
125
#=============================================================================#
226
# Gets a filtered list of architectures that aren't compliant with the platform's architecture.
327
# e.g If a list contains 'avr' and 'nrf52', while our arch is 'avr', 'nrf52' will be returned.

cmake/Platform/Targets/ArduinoLibraryTarget.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#=============================================================================#
99
function(add_arduino_library _target_name _board_id _library_root_dir _sources)
1010

11-
resolve_library_sources_by_architecture(${_library_root_dir} "${_sources}" arch_resolved_sources
11+
resolve_library_architecture(${_library_root_dir} "${_sources}" arch_resolved_sources
1212
"${ARGN}")
1313

1414
_add_arduino_cmake_library(${_target_name} ${_board_id} "${arch_resolved_sources}" "${ARGN}")

0 commit comments

Comments
 (0)