Phil Howard | 0cf12dd | 2021-02-23 22:57:14 +0000 | [diff] [blame] | 1 | # Create a target for all user modules to link against. |
| 2 | add_library(usermod INTERFACE) |
| 3 | |
| 4 | function(usermod_gather_sources SOURCES_VARNAME INCLUDE_DIRECTORIES_VARNAME INCLUDED_VARNAME LIB) |
| 5 | if (NOT ${LIB} IN_LIST ${INCLUDED_VARNAME}) |
| 6 | list(APPEND ${INCLUDED_VARNAME} ${LIB}) |
| 7 | |
| 8 | # Gather library sources |
| 9 | get_target_property(lib_sources ${LIB} INTERFACE_SOURCES) |
| 10 | if (lib_sources) |
| 11 | list(APPEND ${SOURCES_VARNAME} ${lib_sources}) |
| 12 | endif() |
| 13 | |
| 14 | # Gather library includes |
| 15 | get_target_property(lib_include_directories ${LIB} INTERFACE_INCLUDE_DIRECTORIES) |
| 16 | if (lib_include_directories) |
| 17 | list(APPEND ${INCLUDE_DIRECTORIES_VARNAME} ${lib_include_directories}) |
| 18 | endif() |
| 19 | |
| 20 | # Recurse linked libraries |
| 21 | get_target_property(trans_depend ${LIB} INTERFACE_LINK_LIBRARIES) |
| 22 | if (trans_depend) |
| 23 | foreach(SUB_LIB ${trans_depend}) |
| 24 | usermod_gather_sources( |
| 25 | ${SOURCES_VARNAME} |
| 26 | ${INCLUDE_DIRECTORIES_VARNAME} |
| 27 | ${INCLUDED_VARNAME} |
| 28 | ${SUB_LIB}) |
| 29 | endforeach() |
| 30 | endif() |
| 31 | |
| 32 | set(${SOURCES_VARNAME} ${${SOURCES_VARNAME}} PARENT_SCOPE) |
| 33 | set(${INCLUDE_DIRECTORIES_VARNAME} ${${INCLUDE_DIRECTORIES_VARNAME}} PARENT_SCOPE) |
| 34 | set(${INCLUDED_VARNAME} ${${INCLUDED_VARNAME}} PARENT_SCOPE) |
| 35 | endif() |
| 36 | endfunction() |
| 37 | |
| 38 | # Include CMake files for user modules. |
| 39 | if (USER_C_MODULES) |
| 40 | foreach(USER_C_MODULE_PATH ${USER_C_MODULES}) |
| 41 | message("Including User C Module(s) from ${USER_C_MODULE_PATH}") |
| 42 | include(${USER_C_MODULE_PATH}) |
| 43 | endforeach() |
| 44 | endif() |
| 45 | |
| 46 | # Recursively gather sources for QSTR scanning - doesn't support generator expressions. |
| 47 | usermod_gather_sources(MICROPY_SOURCE_USERMOD MICROPY_INC_USERMOD found_modules usermod) |
| 48 | |
| 49 | # Report found modules. |
| 50 | list(REMOVE_ITEM found_modules "usermod") |
| 51 | list(JOIN found_modules ", " found_modules) |
| 52 | message("Found User C Module(s): ${found_modules}") |