|
| 1 | +#=============================================================================# |
| 2 | +# Parses the given arguments for sources, stopping when all arguments have been read or |
| 3 | +# when at least one reserved argument/option has been encountered. |
| 4 | +# _reserved_options - Reserved option arguments. |
| 5 | +# _reserved_single_values - Reserved single-value arguments. |
| 6 | +# _reserved_multi_values - Reserved multi-value arguments. |
| 7 | +# _cmake_args - Arguments to parse. Usually function's unparsed arguments - ${ARGN}. |
| 8 | +# _return_var - Name of a CMake variable that will hold the extraction result. |
| 9 | +# Returns - Parsed sources. |
| 10 | +#=============================================================================# |
| 11 | +function(parse_sources_arguments _return_var _reserved_options _reserved_single_values |
| 12 | + _reserved_multi_values _cmake_args) |
| 13 | + |
| 14 | + # Prepare arguments for further inspection - Somewhat croocked logic due to CMake's limitations |
| 15 | + # If an argument is an empty string, populate it with a theoritcally impossible value. |
| 16 | + # just to have some value in it |
| 17 | + if ("${_reserved_options}" STREQUAL "") |
| 18 | + set(_reserved_options "+-*/") |
| 19 | + endif () |
| 20 | + if ("${_reserved_single_values}" STREQUAL "") |
| 21 | + set(_reserved_single_values "+-*/") |
| 22 | + endif () |
| 23 | + if ("${_reserved_multi_values}" STREQUAL "") |
| 24 | + set(_reserved_multi_values "+-*/") |
| 25 | + endif () |
| 26 | + |
| 27 | + set(sources "") # Clear list because cmake preserves scope in nested functions |
| 28 | + |
| 29 | + foreach (arg ${_cmake_args}) |
| 30 | + |
| 31 | + if (${arg} IN_LIST _reserved_options OR |
| 32 | + ${arg} IN_LIST _reserved_single_values OR |
| 33 | + ${arg} IN_LIST _reserved_multi_values) |
| 34 | + break() |
| 35 | + else () |
| 36 | + list(APPEND sources ${arg}) |
| 37 | + endif () |
| 38 | + |
| 39 | + endforeach () |
| 40 | + |
| 41 | + set(${_return_var} ${sources} PARENT_SCOPE) |
| 42 | + |
| 43 | +endfunction() |
| 44 | + |
1 | 45 | #=============================================================================# |
2 | 46 | # Parses the given arguments for scope-controlling arguments, which are PUBLIC|INTERFACE|PRIVATE. |
3 | 47 | # If none is found, CMake generates an error, unless - The DEFAULT_SCOPE argument is passed. |
|
0 commit comments