mirror of https://github.com/ARMmbed/mbed-os.git
CMake: Add support for printf lib selection
parent
18345795cd
commit
3b8aba1dce
|
@ -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})
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue