Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,28 @@ endif()
# These targets are made visible here so their source files which
# are spread in different directories can be referenced and can be linked against
# by libraries that depend on them.
add_library(mbed-rtos-flags INTERFACE) # Collects source files that are in mbed-os but not mbed-baremetal
add_library(mbed-rtos-sources INTERFACE) # Collects flags that are in mbed-os but not mbed-baremetal
add_library(mbed-core-flags INTERFACE) # Collects flags common to mbed-baremetal and mbed-os
add_library(mbed-core-sources INTERFACE) # Collects source files common to mbed-baremetal and mbed-os
add_library(mbed-rtos-flags INTERFACE) # Collects flags that are in mbed-os but not mbed-baremetal
add_library(mbed-rtos-sources INTERFACE) # Collects source files that are in mbed-os but not mbed-baremetal
add_library(mbed-core-flags INTERFACE) # Collects flags that are in mbed-os or mbed-baremetal
# depending on target.application-profile setting
add_library(mbed-core-sources INTERFACE) # Collects source files that are in mbed-os or mbed-baremetal
# depending on target.application-profile setting

if("MBED_CONF_TARGET_APPLICATION_PROFILE=full" IN_LIST MBED_CONFIG_DEFINITIONS)
set(APPLICATION_PROFILE_CONFIG_FULL TRUE)
endif()
if("MBED_CONF_TARGET_APPLICATION_PROFILE=bare-metal" IN_LIST MBED_CONFIG_DEFINITIONS)
set(APPLICATION_PROFILE_CONFIG_BAREMETAL TRUE)
endif()
if(NOT APPLICATION_PROFILE_CONFIG_FULL AND NOT APPLICATION_PROFILE_CONFIG_BAREMETAL)
set(APPLICATION_PROFILE_CONFIG_AUTO TRUE)
endif()

# mbed-core-flags/mbed-core-sources link mbed-rtos-flags/mbed-rtos-sources or not
if(APPLICATION_PROFILE_CONFIG_AUTO OR APPLICATION_PROFILE_CONFIG_FULL)
target_link_libraries(mbed-core-flags INTERFACE mbed-rtos-flags)
target_link_libraries(mbed-core-sources INTERFACE mbed-rtos-sources)
endif()

# Validate selected C library type
# The C library type selected has to match the library that the target can support
Expand Down Expand Up @@ -282,10 +300,10 @@ if(NOT MBED_IS_NATIVE_BUILD)
# Note that many different source files will compile differently depending on if the RTOS is in use.
# So, it's needed to compile the core sources twice, once for RTOS and once for non-RTOS.
mbed_create_distro(mbed-baremetal ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)
mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)

# Set up the linker script and hook it up to the top-level OS targets
mbed_setup_linker_script(mbed-baremetal mbed-os ${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h)
mbed_setup_linker_script(mbed-os mbed-baremetal ${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h)

# Make sure that things linking mbed-core-flags can also get the target-specific include dirs and flags.
mbed_extract_flags(${MBED_TARGET_CMAKE_NAME}-flags ${MBED_TARGET_CMAKE_NAME})
Expand Down
3 changes: 2 additions & 1 deletion TESTS/configs/greentea_baremetal.json5
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"target_overrides": {
"*": {
"target.c_lib": "small"
"target.c_lib": "small",
"target.application-profile": "bare-metal"
}
},
"overrides": {
Expand Down
1 change: 0 additions & 1 deletion connectivity/cellular/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ target_link_libraries(mbed-cellular
PUBLIC
mbed-netsocket-api
mbed-core-flags
mbed-rtos-flags
mbed-randlib
)
2 changes: 1 addition & 1 deletion connectivity/drivers/802.15.4_RF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro(create_mbed_802_15_4_target)
add_library(mbed-802.15.4-rf STATIC EXCLUDE_FROM_ALL)

# Nanostack drivers always require Mbed RTOS
target_link_libraries(mbed-802.15.4-rf PUBLIC mbed-core-flags mbed-rtos-flags)
target_link_libraries(mbed-802.15.4-rf PUBLIC mbed-core-flags)

# For NanostackRfPhy.h
target_link_libraries(mbed-802.15.4-rf PUBLIC mbed-nanostack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ target_link_libraries(mbed-bluenrg2
PUBLIC
mbed-core-flags
mbed-ble
PRIVATE
mbed-rtos-flags)
)

# circular dependency between mbed-ble and the BlueNRG driver, because of the ble_cordio_get_hci_driver() implementation
target_link_libraries(mbed-ble PUBLIC mbed-bluenrg2)
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ target_link_libraries(mbed-bluenrg-ms
PUBLIC
mbed-core-flags
mbed-ble
PRIVATE
mbed-rtos-flags)
)


# circular dependency between mbed-ble and the BlueNRG driver, because of the ble_cordio_get_hci_driver() implementation
Expand Down
2 changes: 1 addition & 1 deletion connectivity/drivers/emac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ target_link_libraries(mbed-emac
PUBLIC
mbed-netsocket-api
PRIVATE
mbed-rtos-flags
mbed-core-flags
)
2 changes: 1 addition & 1 deletion connectivity/drivers/wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ macro(create_mbed_wifi_target)

target_link_libraries(mbed-wifi
PUBLIC
mbed-rtos-flags
mbed-core-flags
mbed-netsocket-api
)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ target_sources(mbed-wifi
target_link_libraries(mbed-wifi
PUBLIC
mbed-lwipstack
mbed-rtos-flags
mbed-core-flags
)

if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS)
Expand Down
2 changes: 1 addition & 1 deletion connectivity/libraries/ppp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ target_link_libraries(mbed-ppp
PUBLIC
mbed-netsocket-api
PRIVATE
mbed-rtos-flags
mbed-core-flags
)
2 changes: 1 addition & 1 deletion connectivity/lwipstack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ target_link_libraries(mbed-lwipstack
mbed-ppp
mbed-randlib
PRIVATE
mbed-rtos-flags
mbed-core-flags
)

2 changes: 0 additions & 2 deletions connectivity/nanostack/mbed-mesh-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ target_link_libraries(mbed-nanostack-mbed_mesh_api
mbed-nanostack
mbed-netsocket-api
mbed-core-flags
PRIVATE
mbed-rtos-flags
)

# Since there are a lot of circular references between this library and mbed-netsocket-api,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ target_link_libraries(mbed-nanostack-hal_mbed_cmsis_rtos
mbed-nanostack-sal_stack-event_loop
mbed-nanostack-libservice
mbed-nanostack-sal_stack
PRIVATE
mbed-rtos-flags
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ target_sources(mbed-emac-test-utils PRIVATE
target_include_directories(mbed-emac-test-utils PUBLIC .)
target_link_libraries(mbed-emac-test-utils PUBLIC
mbed-core-flags
mbed-rtos-flags
mbed-netsocket-api
mbed-nanostack-libservice
mbed-nanostack-hal_mbed_cmsis_rtos)
2 changes: 1 addition & 1 deletion drivers/usb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ if("DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)
include/usb/cdc_ecm
)

target_link_libraries(mbed-usb-cdc-ecm PUBLIC mbed-usb mbed-rtos-flags)
target_link_libraries(mbed-usb-cdc-ecm PUBLIC mbed-usb mbed-core-flags)
endif()
7 changes: 7 additions & 0 deletions targets/targets.json5
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
"semihosting-enabled": {
"help": "Enable ARM Semihosting protocol. This uses a magic breakpoint instruction to enable the MCU to print data to and access files on a host machine. However, it can interfere with debuggers that are not semihost aware.",
"value": false
},
"application-profile": {
"help": "Select application profile. Options: auto, full, bare-metal. 'auto' mode will check other build options and resolve to\
'full' mode by default or 'bare-metal' mode. 'full' mode enables the real-time OS and enables all features of Mbed to be used.\
'bare-metal' mode disables the real-time OS, preventing you from using threads and libraries that depend on them. 'bare-metal'\
mode is recommended for target MCUs with small amounts of flash and RAM.",
"value": "auto"
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ function(mbed_greentea_add_test)
${MBED_GREENTEA_TEST_SOURCES}
)

if(MBED_GREENTEA_TEST_BAREMETAL)
# Resolve link library based on target.application-profile setting
get_target_property(MBED_CORE_FLAGS_TARGET_LINK_LIBRARIES mbed-core-flags INTERFACE_LINK_LIBRARIES)
if(NOT "mbed-rtos-flags" IN_LIST MBED_CORE_FLAGS_TARGET_LINK_LIBRARIES)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal)
else()
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os)
Expand Down
11 changes: 11 additions & 0 deletions tools/cmake/mbed_target_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,20 @@ function(mbed_set_post_build target)
if (NOT MBED_IS_STANDALONE)
if("${ARGN}" STREQUAL "")
get_target_property(POST_BUILD_TARGET_LINK_LIBRARIES ${target} LINK_LIBRARIES)
get_target_property(MBED_CORE_FLAGS_TARGET_LINK_LIBRARIES mbed-core-flags INTERFACE_LINK_LIBRARIES)
if("mbed-os" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
if(NOT "mbed-rtos-flags" IN_LIST MBED_CORE_FLAGS_TARGET_LINK_LIBRARIES)
message(FATAL_ERROR
"Target ${target} links to mbed-os, but Mbed is configured for a baremetal build. Please set \"target.application-profile\": \"full\" in JSON to enable the mbed-os target, or link your application to mbed-baremetal instead of mbed-os."
)
endif()
get_target_property(LINKER_SCRIPT_PATH mbed-os LINKER_SCRIPT_PATH)
elseif("mbed-baremetal" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
if("mbed-rtos-flags" IN_LIST MBED_CORE_FLAGS_TARGET_LINK_LIBRARIES)
message(FATAL_ERROR
"Target ${target} links to mbed-baremetal, but Mbed is configured for a full build. Please set \"target.application-profile\": \"bare-metal\" in JSON to enable the mbed-baremetal target, or link your application to mbed-os instead of mbed-baremetal."
)
endif()
get_target_property(LINKER_SCRIPT_PATH mbed-baremetal LINKER_SCRIPT_PATH)
else()
message(FATAL_ERROR "Target ${target} used with mbed_set_post_build() but does not link to mbed-os or mbed-baremetal!")
Expand Down
Loading