Skip to content

Commit e712230

Browse files
author
Jamie Smith
authored
Tweaks to how target.application-profile works (#425)
* Tweaks to how target.application-profile works * Try and fix native tests
1 parent 6368e52 commit e712230

File tree

5 files changed

+44
-163
lines changed

5 files changed

+44
-163
lines changed

CMakeLists.txt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,17 @@ add_library(mbed-core-flags INTERFACE) # Collects flags that are in mbed-os or m
127127
add_library(mbed-core-sources INTERFACE) # Collects source files that are in mbed-os or mbed-baremetal
128128
# depending on target.application-profile setting
129129

130-
if("MBED_CONF_TARGET_APPLICATION_PROFILE=full" IN_LIST MBED_CONFIG_DEFINITIONS)
130+
if("MBED_CONF_TARGET_APPLICATION_PROFILE=full" IN_LIST MBED_CONFIG_DEFINITIONS OR MBED_IS_NATIVE_BUILD)
131131
set(APPLICATION_PROFILE_CONFIG_FULL TRUE)
132-
endif()
133-
if("MBED_CONF_TARGET_APPLICATION_PROFILE=bare-metal" IN_LIST MBED_CONFIG_DEFINITIONS)
132+
elseif("MBED_CONF_TARGET_APPLICATION_PROFILE=bare-metal" IN_LIST MBED_CONFIG_DEFINITIONS)
134133
set(APPLICATION_PROFILE_CONFIG_BAREMETAL TRUE)
135-
endif()
136-
if(NOT APPLICATION_PROFILE_CONFIG_FULL AND NOT APPLICATION_PROFILE_CONFIG_BAREMETAL)
137-
set(APPLICATION_PROFILE_CONFIG_AUTO TRUE)
134+
else()
135+
message(FATAL_ERROR "target.application-profile must be set to either 'full' or 'bare-metal'!")
138136
endif()
139137

140-
# mbed-core-flags/mbed-core-sources link mbed-rtos-flags/mbed-rtos-sources or not
141-
if(APPLICATION_PROFILE_CONFIG_AUTO OR APPLICATION_PROFILE_CONFIG_FULL)
138+
# mbed-core-flags/mbed-core-sources link mbed-rtos-flags/mbed-rtos-sources or not depending on
139+
# target.application-profile setting
140+
if(APPLICATION_PROFILE_CONFIG_FULL)
142141
target_link_libraries(mbed-core-flags INTERFACE mbed-rtos-flags)
143142
target_link_libraries(mbed-core-sources INTERFACE mbed-rtos-sources)
144143
endif()
@@ -298,16 +297,16 @@ add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
298297
# Create top-level targets ----------------------------------------------------------------------------------
299298

300299
if(NOT MBED_IS_NATIVE_BUILD)
301-
# Core Mbed OS libraries
302-
# mbed-baremetal contains baremetal sources + target sources + target compile flags.
303-
# mbed-os will be a superset of mbed-baremetal, also containing the RTOS sources and RTOS flags.
304-
# Note that many different source files will compile differently depending on if the RTOS is in use.
305-
# So, it's needed to compile the core sources twice, once for RTOS and once for non-RTOS.
306-
mbed_create_distro(mbed-baremetal ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)
307-
mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)
308-
309-
# Set up the linker script and hook it up to the top-level OS targets
310-
mbed_setup_linker_script(mbed-os mbed-baremetal ${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h)
300+
# Core Mbed OS library
301+
if(APPLICATION_PROFILE_CONFIG_FULL)
302+
set(MBED_OS_CORE_LIB_NAME mbed-os)
303+
else()
304+
set(MBED_OS_CORE_LIB_NAME mbed-baremetal)
305+
endif()
306+
mbed_create_distro(${MBED_OS_CORE_LIB_NAME} ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)
307+
308+
# Set up the linker script and hook it up to the top-level OS target
309+
mbed_setup_linker_script(${MBED_OS_CORE_LIB_NAME} ${CMAKE_CURRENT_BINARY_DIR}/generated-headers/mbed-target-config.h)
311310

312311
# Make sure that things linking mbed-core-flags can also get the target-specific include dirs and flags.
313312
mbed_extract_flags(${MBED_TARGET_CMAKE_NAME}-flags ${MBED_TARGET_CMAKE_NAME})

targets/targets.json5

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@
102102
"value": false
103103
},
104104
"application-profile": {
105-
"help": "Select application profile. Options: auto, full, bare-metal. 'auto' mode will check other build options and resolve to\
106-
'full' mode by default or 'bare-metal' mode. 'full' mode enables the real-time OS and enables all features of Mbed to be used.\
107-
'bare-metal' mode disables the real-time OS, preventing you from using threads and libraries that depend on them. 'bare-metal'\
108-
mode is recommended for target MCUs with small amounts of flash and RAM.",
109-
"value": "auto"
105+
"help": "Select application profile. Options: 'full', 'bare-metal'. 'full' mode enables the real-time \
106+
OS and enables all features of Mbed to be used. \
107+
'bare-metal' mode disables the real-time OS, preventing you from using threads and libraries that depend on them. 'bare-metal' \
108+
mode is recommended for target MCUs with small amounts of flash and RAM.",
109+
"value": "full"
110110
}
111111
}
112112
},

tools/cmake/README.md

Lines changed: 0 additions & 113 deletions
This file was deleted.

tools/cmake/mbed_greentea.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
option(MBED_GREENTEA_TEST_BAREMETAL "Select baremetal greentea tests" OFF)
5-
64
set(MBED_HTRUN_ARGUMENTS "" CACHE STRING "Argument list to forward to htrun.")
75
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.")
86

@@ -17,8 +15,8 @@ set(MBED_GREENTEA_SERIAL_PORT "" CACHE STRING "Serial port name to talk to the M
1715
# TEST_SKIPPED - Reason if suite is skipped
1816
#
1917
# calling the macro:
20-
# if(MBED_GREENTEA_TEST_BAREMETAL)
21-
# set(skip_reason "RTOS required")
18+
# if(some_condition)
19+
# set(skip_reason "some condition not satisfied")
2220
# endif()
2321
# mbed_greentea_add_test(
2422
# TEST_NAME

tools/cmake/mbed_set_linker_script.cmake

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@ endfunction(mbed_set_linker_script)
2121
# Set up the linker script for the top-level Mbed OS targets.
2222
# If needed, this also creates another target to preprocess the linker script.
2323
#
24-
# mbed_os_target: CMake target for Mbed OS
25-
# mbed_baremetal_target: CMake target for Mbed Baremetal
24+
# mbed_os_target: CMake target for Mbed OS core library
2625
# target_defines_header: the full path to the header containing all of the Mbed target defines
2726
#
28-
function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_defines_header)
27+
function(mbed_setup_linker_script mbed_os_target target_defines_header)
2928

3029
# Find the path to the desired linker script
3130
# (the property should be set on both the OS and baremetal targets in a sane world)
32-
get_property(RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
31+
get_property(RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_os_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
3332
if(NOT RAW_LINKER_SCRIPT_PATHS_SET)
3433
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")
3534
endif()
3635

37-
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
36+
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_os_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
3837

3938
# Check if two (or more) different linker scripts got used
4039
list(REMOVE_DUPLICATES RAW_LINKER_SCRIPT_PATHS)
@@ -82,24 +81,22 @@ function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_de
8281
# which is then added as a dependency of the MCU target. This ensures the linker script will exist
8382
# by the time we need it.
8483
add_custom_target(mbed-linker-script DEPENDS ${LINKER_SCRIPT_PATH} VERBATIM)
85-
foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target})
86-
add_dependencies(${TARGET} mbed-linker-script)
87-
88-
# When building the Mbed internal tests, the tests get created before the mbed-os target does. So, the normal logic
89-
# in mbed_set_post_build() to set the linker script does not work. So, we need to instead attach the linker script to
90-
# the mbed-os and mbed-baremetal libraries themselves, so it will get picked up automatically.
91-
# This prevents a custom linker script from being used in STANDALONE mode, but we don't need to do that.
92-
set_target_properties(${TARGET} PROPERTIES LINKER_SCRIPT_PATH ${LINKER_SCRIPT_PATH})
93-
94-
# add linker script only for tests
95-
if(MBED_IS_STANDALONE)
96-
target_link_options(${TARGET}
97-
INTERFACE
98-
"-T" "${LINKER_SCRIPT_PATH}"
99-
)
100-
set_property(TARGET ${TARGET} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${LINKER_SCRIPT_PATH})
101-
endif()
102-
endforeach()
84+
add_dependencies(${mbed_os_target} mbed-linker-script)
85+
86+
# When building the Mbed internal tests, the tests get created before the mbed-os target does. So, the normal logic
87+
# in mbed_set_post_build() to set the linker script does not work. So, we need to instead attach the linker script to
88+
# the mbed-os and mbed-baremetal libraries themselves, so it will get picked up automatically.
89+
# This prevents a custom linker script from being used in STANDALONE mode, but we don't need to do that.
90+
set_target_properties(${mbed_os_target} PROPERTIES LINKER_SCRIPT_PATH ${LINKER_SCRIPT_PATH})
91+
92+
# add linker script only for tests
93+
if(MBED_IS_STANDALONE)
94+
target_link_options(${mbed_os_target}
95+
INTERFACE
96+
"-T" "${LINKER_SCRIPT_PATH}"
97+
)
98+
set_property(TARGET ${mbed_os_target} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${LINKER_SCRIPT_PATH})
99+
endif()
103100

104101
endfunction(mbed_setup_linker_script)
105102

0 commit comments

Comments
 (0)