mirror of https://github.com/ARMmbed/mbed-os.git
CMake: Add support for C lib selection
Configure the selected toolchain for the selected C librarypull/13566/head
parent
4ec13d7bd5
commit
18345795cd
|
@ -28,8 +28,29 @@ include(${MBED_ROOT}/tools/cmake/profile.cmake)
|
|||
# Create Mbed OS library
|
||||
add_library(mbed-os OBJECT)
|
||||
|
||||
# Validate selected C library type
|
||||
# The C library type selected has to match the library that the target can support
|
||||
if(${MBED_C_LIB} STREQUAL "small")
|
||||
if(NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
|
||||
if("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
|
||||
message(WARNING
|
||||
"We noticed that target.c_lib is set to `${MBED_C_LIB}`."
|
||||
" As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
|
||||
" we are using the standard C library instead."
|
||||
)
|
||||
set(MBED_C_LIB "std" CACHE STRING "")
|
||||
endif()
|
||||
endif()
|
||||
elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
|
||||
message(FATAL_ERROR
|
||||
"Invalid `target.c_lib` ('${MBED_C_LIB}') for '${MBED_TARGET}' target."
|
||||
"\nPossible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS}"
|
||||
)
|
||||
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_language_standard(mbed-os)
|
||||
mbed_set_profile_options(mbed-os ${MBED_TOOLCHAIN})
|
||||
|
||||
|
|
|
@ -96,6 +96,8 @@ This will output `mbed_config.cmake` in a directory named `.mbedbuild` at the ro
|
|||
* `MBED_TOOLCHAIN`
|
||||
* `MBED_TARGET`
|
||||
* `MBED_CPU_CORE`
|
||||
* `MBED_C_LIB`
|
||||
* `MBED_TARGET_SUPPORTED_C_LIBS`
|
||||
|
||||
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.
|
||||
|
||||
|
|
|
@ -10,11 +10,9 @@ We are currently working to break down the `mbed-os` library into several indivi
|
|||
|
||||
The following features are not yet supported and will be progressively added:
|
||||
* Application profile selection (`bare metal`)
|
||||
* C library selection (`small`)
|
||||
* `s/f/v/printf` library selection (`minimal-printf`)
|
||||
* Other features that require altering compiler/linker command line options
|
||||
* Features that require altering compiler/linker command line options (except for printf library and C selections)
|
||||
|
||||
The full profile with the standard printf and C library are selected by default.
|
||||
The full profile with the selected printf and C libraries.
|
||||
|
||||
### Supported targets
|
||||
|
||||
|
|
|
@ -58,3 +58,24 @@ function(mbed_set_toolchain_options target)
|
|||
${MBED_STUDIO_ARM_COMPILER}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# Configure the toolchain to select the selected C library
|
||||
function(mbed_set_c_lib target lib_type)
|
||||
if (${lib_type} STREQUAL "small")
|
||||
target_compile_definitions(${target}
|
||||
PUBLIC
|
||||
MBED_RTOS_SINGLE_THREAD
|
||||
__MICROLIB
|
||||
)
|
||||
|
||||
target_compile_options(${target}
|
||||
PUBLIC
|
||||
$<$<COMPILE_LANGUAGE:ASM>:"--library_type=microlib">
|
||||
)
|
||||
|
||||
target_link_options(${target}
|
||||
PUBLIC
|
||||
"--library_type=microlib"
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
|
|
@ -75,3 +75,19 @@ function(mbed_generate_gcc_options_for_linker target definitions_file linker_opt
|
|||
set(definitions_file @${CMAKE_BINARY_DIR}/compile_time_defs.txt)
|
||||
set(linker_options_file @${CMAKE_BINARY_DIR}/linker_options.txt)
|
||||
endfunction()
|
||||
|
||||
# Configure the toolchain to select the selected C library
|
||||
function(mbed_set_c_lib target lib_type)
|
||||
if (${lib_type} STREQUAL "small")
|
||||
target_compile_definitions(${target}
|
||||
PUBLIC
|
||||
MBED_RTOS_SINGLE_THREAD
|
||||
__NEWLIB_NANO
|
||||
)
|
||||
|
||||
target_link_options(${target}
|
||||
PUBLIC
|
||||
"--specs=nano.specs"
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
|
Loading…
Reference in New Issue