Skip to content

Commit

Permalink
CMake: Add support for printf lib selection
Browse files Browse the repository at this point in the history
  • Loading branch information
hugueskamba committed Nov 6, 2020
1 parent 1834579 commit 3b8aba1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
1 change: 1 addition & 0 deletions docs/design-documents/tools/cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions tools/cmake/toolchains/ARM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
25 changes: 25 additions & 0 deletions tools/cmake/toolchains/GCC_ARM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 3b8aba1

Please sign in to comment.