Skip to content

Commit 1f33f26

Browse files
committed
Change to create only one of mbed-os/mbed-baremteal
Dependent on target config option application-profile, this changes to create only one of distributed cmake library targets mbed-os/ mbed-baremteal, not both. This is to guard from mismatch of application profile selection (target config option application-profile and link of mbed-os/mbed-baremetal).
1 parent 219c536 commit 1f33f26

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,11 @@ if(NOT MBED_IS_NATIVE_BUILD)
289289
# mbed-os will be a superset of mbed-baremetal, also containing the RTOS sources and RTOS flags.
290290
# Note that many different source files will compile differently depending on if the RTOS is in use.
291291
# So, it's needed to compile the core sources twice, once for RTOS and once for non-RTOS.
292-
mbed_create_distro(mbed-baremetal ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)
293-
mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
292+
if("MBED_CONF_TARGET_APPLICATION_PROFILE=bare-metal" IN_LIST MBED_CONFIG_DEFINITIONS)
293+
mbed_create_distro(mbed-baremetal ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)
294+
elseif("MBED_CONF_TARGET_APPLICATION_PROFILE=full" IN_LIST MBED_CONFIG_DEFINITIONS)
295+
mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
296+
endif()
294297

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

tools/cmake/mbed_set_linker_script.cmake

+16-6
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ endfunction(mbed_set_linker_script)
2828
function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_defines_header)
2929

3030
# Find the path to the desired linker script
31-
# (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)
33-
if(NOT RAW_LINKER_SCRIPT_PATHS_SET)
34-
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")
31+
if(TARGET ${mbed_os_target})
32+
get_property(RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_os_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
33+
if(NOT RAW_LINKER_SCRIPT_PATHS_SET)
34+
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")
35+
endif()
36+
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_os_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
37+
elseif (TARGET ${mbed_baremetal_target})
38+
get_property(RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
39+
if(NOT RAW_LINKER_SCRIPT_PATHS_SET)
40+
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")
41+
endif()
42+
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
3543
endif()
3644

37-
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
38-
3945
# Check if two (or more) different linker scripts got used
4046
list(REMOVE_DUPLICATES RAW_LINKER_SCRIPT_PATHS)
4147
list(LENGTH RAW_LINKER_SCRIPT_PATHS NUM_RAW_LINKER_SCRIPT_PATHS)
@@ -83,6 +89,10 @@ function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_de
8389
# by the time we need it.
8490
add_custom_target(mbed-linker-script DEPENDS ${LINKER_SCRIPT_PATH} VERBATIM)
8591
foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target})
92+
if(NOT TARGET ${TARGET})
93+
continue()
94+
endif()
95+
8696
add_dependencies(${TARGET} mbed-linker-script)
8797

8898
# When building the Mbed internal tests, the tests get created before the mbed-os target does. So, the normal logic

tools/cmake/mbed_target_functions.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,14 @@ function(mbed_set_post_build target)
137137
if("${ARGN}" STREQUAL "")
138138
get_target_property(POST_BUILD_TARGET_LINK_LIBRARIES ${target} LINK_LIBRARIES)
139139
if("mbed-os" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
140+
if(NOT TARGET mbed-os)
141+
message(FATAL_ERROR "Link target \"mbed-os\" doesn't match target config option \"target.application-profile\"")
142+
endif()
140143
get_target_property(LINKER_SCRIPT_PATH mbed-os LINKER_SCRIPT_PATH)
141144
elseif("mbed-baremetal" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
145+
if(NOT TARGET mbed-baremetal)
146+
message(FATAL_ERROR "Link target \"mbed-baremetal\" doesn't match target config option \"target.application-profile\"")
147+
endif()
142148
get_target_property(LINKER_SCRIPT_PATH mbed-baremetal LINKER_SCRIPT_PATH)
143149
else()
144150
message(FATAL_ERROR "Target ${target} used with mbed_set_post_build() but does not link to mbed-os or mbed-baremetal!")

0 commit comments

Comments
 (0)