CMake: Add support for printf lib selection

pull/13566/head
Hugues Kamba 2020-09-15 12:18:00 +01:00
parent 18345795cd
commit 3b8aba1dce
4 changed files with 45 additions and 0 deletions

View File

@ -48,9 +48,18 @@ elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
)
endif()
# Validate selected printf library
set(MBED_PRINTF_LIB_TYPES std minimal-printf)
if(NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
message(FATAL_ERROR
"Invalid printf library type '${MBED_PRINTF_LIB}'. Possible values:\n ${MBED_PRINTF_LIB_TYPES}"
)
endif()
mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN})
mbed_set_toolchain_options(mbed-os)
mbed_set_c_lib(mbed-os ${MBED_C_LIB})
mbed_set_printf_lib(mbed-os ${MBED_PRINTF_LIB})
mbed_set_language_standard(mbed-os)
mbed_set_profile_options(mbed-os ${MBED_TOOLCHAIN})

View File

@ -98,6 +98,7 @@ This will output `mbed_config.cmake` in a directory named `.mbedbuild` at the ro
* `MBED_CPU_CORE`
* `MBED_C_LIB`
* `MBED_TARGET_SUPPORTED_C_LIBS`
* `MBED_PRINTF_LIB`
The tools also generate an `MBED_TARGET_LABELS` variable, containing the labels, components and feature definitions from `targets.json`, used to select the required Mbed OS components to be built.

View File

@ -79,3 +79,13 @@ function(mbed_set_c_lib target lib_type)
)
endif()
endfunction()
# Configure the toolchain to select the selected printf library
function(mbed_set_printf_lib target lib_type)
if (${lib_type} STREQUAL "minimal-printf")
target_compile_definitions(${target}
PUBLIC
MBED_MINIMAL_PRINTF
)
endif()
endfunction()

View File

@ -91,3 +91,28 @@ function(mbed_set_c_lib target lib_type)
)
endif()
endfunction()
# Configure the toolchain to select the selected printf library
function(mbed_set_printf_lib target lib_type)
if (${lib_type} STREQUAL "minimal-printf")
target_compile_definitions(${target}
PUBLIC
MBED_MINIMAL_PRINTF
)
list(APPEND link_options
"-Wl,--wrap,printf"
"-Wl,--wrap,sprintf"
"-Wl,--wrap,snprintf"
"-Wl,--wrap,vprintf"
"-Wl,--wrap,vsprintf"
"-Wl,--wrap,vsnprintf"
"-Wl,--wrap,fprintf"
"-Wl,--wrap,vfprintf"
)
target_link_options(${target}
PUBLIC
${link_options}
)
endif()
endfunction()