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
1247endfunction ()
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 )
0 commit comments