Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks to how target.application-profile works #425

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 17 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,17 @@ add_library(mbed-core-flags INTERFACE) # Collects flags that are in mbed-os or m
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)
if("MBED_CONF_TARGET_APPLICATION_PROFILE=full" IN_LIST MBED_CONFIG_DEFINITIONS OR MBED_IS_NATIVE_BUILD)
set(APPLICATION_PROFILE_CONFIG_FULL TRUE)
endif()
if("MBED_CONF_TARGET_APPLICATION_PROFILE=bare-metal" IN_LIST MBED_CONFIG_DEFINITIONS)
elseif("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)
else()
message(FATAL_ERROR "target.application-profile must be set to either 'full' or 'bare-metal'!")
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)
# mbed-core-flags/mbed-core-sources link mbed-rtos-flags/mbed-rtos-sources or not depending on
# target.application-profile setting
if(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()
Expand Down Expand Up @@ -298,16 +297,16 @@ add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
# Create top-level targets ----------------------------------------------------------------------------------

if(NOT MBED_IS_NATIVE_BUILD)
# Core Mbed OS libraries
# mbed-baremetal contains baremetal sources + target sources + target compile flags.
# mbed-os will be a superset of mbed-baremetal, also containing the RTOS sources and RTOS flags.
# 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)

# Set up the linker script and hook it up to the top-level OS targets
mbed_setup_linker_script(mbed-os mbed-baremetal ${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h)
# Core Mbed OS library
if(APPLICATION_PROFILE_CONFIG_FULL)
set(MBED_OS_CORE_LIB_NAME mbed-os)
else()
set(MBED_OS_CORE_LIB_NAME mbed-baremetal)
endif()
mbed_create_distro(${MBED_OS_CORE_LIB_NAME} ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)

# Set up the linker script and hook it up to the top-level OS target
mbed_setup_linker_script(${MBED_OS_CORE_LIB_NAME} ${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
10 changes: 5 additions & 5 deletions targets/targets.json5
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@
"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"
"help": "Select application profile. Options: 'full', 'bare-metal'. '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": "full"
}
}
},
Expand Down
113 changes: 0 additions & 113 deletions tools/cmake/README.md

This file was deleted.

6 changes: 2 additions & 4 deletions tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

option(MBED_GREENTEA_TEST_BAREMETAL "Select baremetal greentea tests" OFF)

set(MBED_HTRUN_ARGUMENTS "" CACHE STRING "Argument list to forward to htrun.")
set(MBED_GREENTEA_SERIAL_PORT "" CACHE STRING "Serial port name to talk to the Mbed device on. Should look like 'COM3' on Windows or '/dev/ttyACM1' on Linux.")

Expand All @@ -17,8 +15,8 @@ set(MBED_GREENTEA_SERIAL_PORT "" CACHE STRING "Serial port name to talk to the M
# TEST_SKIPPED - Reason if suite is skipped
#
# calling the macro:
# if(MBED_GREENTEA_TEST_BAREMETAL)
# set(skip_reason "RTOS required")
# if(some_condition)
# set(skip_reason "some condition not satisfied")
# endif()
# mbed_greentea_add_test(
# TEST_NAME
Expand Down
43 changes: 20 additions & 23 deletions tools/cmake/mbed_set_linker_script.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ endfunction(mbed_set_linker_script)
# Set up the linker script for the top-level Mbed OS targets.
# If needed, this also creates another target to preprocess the linker script.
#
# mbed_os_target: CMake target for Mbed OS
# mbed_baremetal_target: CMake target for Mbed Baremetal
# mbed_os_target: CMake target for Mbed OS core library
# target_defines_header: the full path to the header containing all of the Mbed target defines
#
function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_defines_header)
function(mbed_setup_linker_script mbed_os_target target_defines_header)

# Find the path to the desired linker script
# (the property should be set on both the OS and baremetal targets in a sane world)
get_property(RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
get_property(RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_os_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
if(NOT RAW_LINKER_SCRIPT_PATHS_SET)
message(FATAL_ERROR "No linker script has been set for the Mbed target. Ensure that code is calling mbed_set_linker_script() for the mbed-<your-board-name> target or one of its parents")
endif()

get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_os_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)

# Check if two (or more) different linker scripts got used
list(REMOVE_DUPLICATES RAW_LINKER_SCRIPT_PATHS)
Expand Down Expand Up @@ -82,24 +81,22 @@ function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_de
# which is then added as a dependency of the MCU target. This ensures the linker script will exist
# by the time we need it.
add_custom_target(mbed-linker-script DEPENDS ${LINKER_SCRIPT_PATH} VERBATIM)
foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target})
add_dependencies(${TARGET} mbed-linker-script)

# When building the Mbed internal tests, the tests get created before the mbed-os target does. So, the normal logic
# in mbed_set_post_build() to set the linker script does not work. So, we need to instead attach the linker script to
# the mbed-os and mbed-baremetal libraries themselves, so it will get picked up automatically.
# This prevents a custom linker script from being used in STANDALONE mode, but we don't need to do that.
set_target_properties(${TARGET} PROPERTIES LINKER_SCRIPT_PATH ${LINKER_SCRIPT_PATH})

# add linker script only for tests
if(MBED_IS_STANDALONE)
target_link_options(${TARGET}
INTERFACE
"-T" "${LINKER_SCRIPT_PATH}"
)
set_property(TARGET ${TARGET} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${LINKER_SCRIPT_PATH})
endif()
endforeach()
add_dependencies(${mbed_os_target} mbed-linker-script)

# When building the Mbed internal tests, the tests get created before the mbed-os target does. So, the normal logic
# in mbed_set_post_build() to set the linker script does not work. So, we need to instead attach the linker script to
# the mbed-os and mbed-baremetal libraries themselves, so it will get picked up automatically.
# This prevents a custom linker script from being used in STANDALONE mode, but we don't need to do that.
set_target_properties(${mbed_os_target} PROPERTIES LINKER_SCRIPT_PATH ${LINKER_SCRIPT_PATH})

# add linker script only for tests
if(MBED_IS_STANDALONE)
target_link_options(${mbed_os_target}
INTERFACE
"-T" "${LINKER_SCRIPT_PATH}"
)
set_property(TARGET ${mbed_os_target} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${LINKER_SCRIPT_PATH})
endif()

endfunction(mbed_setup_linker_script)

Expand Down
Loading