|
| 1 | +#=============================================================================# |
| 2 | +# Filters sources that relate to an architecture from the given list of unsupported architectures. |
| 3 | +# _unsupported_archs_regex - List of unsupported architectures as a regex-pattern string. |
| 4 | +# _sources - List of sources to check and potentially filter. |
| 5 | +# _return_var - Name of variable in parent-scope holding the return value. |
| 6 | +# Returns - Filtered list of sources containing only those that don't relate to |
| 7 | +# any unsupported architecture. |
| 8 | +#=============================================================================# |
| 9 | +function(_filter_unsupported_arch_sources _unsupported_archs_regex _sources _return_var) |
| 10 | + |
| 11 | + if (NOT "${_unsupported_archs_regex}" STREQUAL "") # Not all architectures are supported |
| 12 | + # Filter sources dependant on unsupported architectures |
| 13 | + list(FILTER _sources EXCLUDE REGEX ${_unsupported_archs_regex}) |
| 14 | + endif () |
| 15 | + |
| 16 | + set(${_return_var} ${_sources} PARENT_SCOPE) |
| 17 | + |
| 18 | +endfunction() |
| 19 | + |
| 20 | +#=============================================================================# |
| 21 | +# Resolves library's architecture-related elements by doing several things: |
| 22 | +# 1. Checking whether the platform's architecture is supported by the library |
| 23 | +# 2. Filtering out any library sources that relate to unsupported architectures, i.e |
| 24 | +# architectures other than the platform's. |
| 25 | +# If the platform's architecture isn't supported by the library, CMake generates an error and stops. |
| 26 | +# _library_sources - List of library's sources to check and potentially filter. |
| 27 | +# [LIB_PROPS_FILE] - Full path to the library's properties file. Optional. |
| 28 | +# _return_var - Name of variable in parent-scope holding the return value. |
| 29 | +# Returns - Filtered list of sources containing only those that don't relate to |
| 30 | +# any unsupported architecture. |
| 31 | +#=============================================================================# |
| 32 | +function(resolve_library_architecture _library_sources _return_var) |
| 33 | + |
| 34 | + cmake_parse_arguments(parsed_args "" "LIB_PROPS_FILE" "" ${ARGN}) |
| 35 | + |
| 36 | + if (parsed_args_LIB_PROPS_FILE) # Library properties file is given |
| 37 | + set(lib_props_file ${parsed_args_LIB_PROPS_FILE}) |
| 38 | + else () |
| 39 | + |
| 40 | + # Warn user and assume library is arch-agnostic |
| 41 | + message(STATUS "Library's properties file can't be found " |
| 42 | + "under its' root directory - Assuming the library " |
| 43 | + "is architecture-agnostic (supports all architectures)") |
| 44 | + set(${_return_var} "${_library_sources}" PARENT_SCOPE) |
| 45 | + return() |
| 46 | + |
| 47 | + endif () |
| 48 | + |
| 49 | + get_arduino_library_supported_architectures("${lib_props_file}" lib_archs) |
| 50 | + |
| 51 | + # Check if the platform's architecture is supported by the library |
| 52 | + is_platform_architecture_supported(${lib_archs} arch_supported_by_lib) |
| 53 | + |
| 54 | + if (NOT ${arch_supported_by_lib}) |
| 55 | + message(SEND_ERROR "The platform's architecture, ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE}, " |
| 56 | + "isn't supported by the ${_library_name} library") |
| 57 | + endif () |
| 58 | + |
| 59 | + get_unsupported_architectures("${lib_archs}" unsupported_archs REGEX) |
| 60 | + |
| 61 | + # Filter any sources that aren't supported by the platform's architecture |
| 62 | + _filter_unsupported_arch_sources("${unsupported_archs}" "${_library_sources}" valid_sources) |
| 63 | + |
| 64 | + set(${_return_var} "${valid_sources}" PARENT_SCOPE) |
| 65 | + |
| 66 | +endfunction() |
0 commit comments