1+ #=============================================================================#
2+ # Gets the types of a function's arguments as a list.
3+ # _signature - String representing a full function signature, e.g. 'int main(int argc, char **argv)'
4+ # _return_var - Name of variable in parent-scope holding the return value.
5+ # Returns - List of types, matching the given function-argument string.
6+ #=============================================================================#
7+ function (_get_function_arguments_types _signature _return_var)
8+
9+ string (REGEX MATCH ${ARDUINO_CMAKE_FUNCTION_ARGS_REGEX_PATTERN} function_args_string "${_signature} " )
10+ string (REGEX MATCHALL ${ARDUINO_CMAKE_FUNCTION_SINGLE_ARG_REGEX_PATTERN}
11+ function_arg_list "${_function_args_string} " )
12+
13+ # Iterate through all arguments to extract only their type
14+ foreach (arg ${function_arg_list} )
15+ string (REGEX MATCH ${ARDUINO_CMAKE_FUNCTION_ARG_TYPE_REGEX_PATTERN} arg_type "${arg} " )
16+ string (STRIP "${arg_type} " arg_type) # Strip remaining whitespaces
17+ list (APPEND function_args ${arg_type} )
18+ endforeach ()
19+
20+ set (${_return_var} ${function_args} PARENT_SCOPE)
21+
22+ endfunction ()
23+
24+ #=============================================================================#
25+ # Strips a given function signature to its name and its arguments' types.
26+ # _signature - String representing a full function signature, e.g. 'int main(int argc, char **argv)'
27+ # _return_var - Name of variable in parent-scope holding the return value.
28+ # Returns - List consisting of the function's name and arguments types.
29+ #=============================================================================#
30+ function (strip_function_signature _signature _return_var)
31+
32+ # Strip function's name
33+ string (REGEX MATCH ${ARDUINO_CMAKE_FUNCTION_NAME_REGEX_PATTERN} function_name_match "${_signature} " )
34+ set (function_name ${CMAKE_MATCH_1} )
35+ list (APPEND stripped_signature ${function_name} )
36+
37+ # Strip arguments types , i.e. without names
38+ _get_function_arguments_types("${_signature} " function_args_types)
39+ list (APPEND stripped_signature ${function_args_types} )
40+
41+ set (${_return_var} ${stripped_signature} PARENT_SCOPE)
42+
43+ endfunction ()
0 commit comments