- Split mbed-core and mbed-rtos into -sources and -flags targets

- Fix some logic errors in top level cmakelists related to building greentea tests
- Fix mbed_create_distro() for OBJECT libraries
pull/15339/head
Jamie Smith 2022-04-03 17:38:18 -07:00 committed by Jay Sridharan
parent 63aa3360c0
commit c11d32fbf4
29 changed files with 155 additions and 112 deletions

View File

@ -11,7 +11,8 @@ cmake_policy(VERSION 3.16...3.22)
# - MBED_OS_IS_STANDALONE: True if Mbed OS is the top-level project. False if Mbed is being built as part of an application. # - MBED_OS_IS_STANDALONE: True if Mbed OS is the top-level project. False if Mbed is being built as part of an application.
# - MBED_IS_NATIVE_BUILD: True if we are building for the host machine. False if we are building for a microcontroller # - MBED_IS_NATIVE_BUILD: True if we are building for the host machine. False if we are building for a microcontroller
# - MBED_OS_ENABLE_TESTS: True if we are building *any* internal Mbed OS tests at all. Enabled by -DBUILD_TESTING=TRUE (which is enabled by default when standalone). # - MBED_OS_ENABLE_TESTS: True if we are building *any* internal Mbed OS tests at all. Enabled by -DBUILD_TESTING=TRUE (which is enabled by default when standalone).
# - BUILD_GREENTEA_TESTS: True to build greentea on-target tests. False to build host UNITTESTS. # - BUILD_GREENTEA_TESTS: True to build greentea on-target tests. False to build host UNITTESTS. Defaults to false when standalone.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# We are the top level project, so tests or unittests are being built. # We are the top level project, so tests or unittests are being built.
@ -21,37 +22,41 @@ else()
set(MBED_OS_IS_STANDALONE FALSE) set(MBED_OS_IS_STANDALONE FALSE)
endif() endif()
# Set up options for testing
option(BUILD_TESTING "Whether to enable CTest tests in this project" ${MBED_OS_IS_STANDALONE}) # This option is also created by include(CTest) but we need it here earlier on.
if(MBED_OS_IS_STANDALONE AND BUILD_TESTING)
set(MBED_OS_ENABLE_TESTS TRUE)
option(BUILD_GREENTEA_TESTS "Build greentea tests instead of unit tests" FALSE)
endif()
# Figure out if this is a native build
if(MBED_OS_IS_STANDALONE)
# Standalone build, use BUILD_GREENTEA_TESTS to determine if we are building for native or not (user can select)
if(BUILD_GREENTEA_TESTS)
set(MBED_IS_NATIVE_BUILD FALSE)
else()
set(MBED_IS_NATIVE_BUILD TRUE)
endif()
else()
# Building as a subdir. This means that the top-level project will already have called project(), so we can
# rely on CMake's platform detection.
if(CMAKE_CROSSCOMPILING) if(CMAKE_CROSSCOMPILING)
set(MBED_IS_NATIVE_BUILD FALSE) set(MBED_IS_NATIVE_BUILD FALSE)
else() else()
set(MBED_IS_NATIVE_BUILD TRUE) set(MBED_IS_NATIVE_BUILD TRUE)
endif() endif()
if(MBED_IS_NATIVE_BUILD)
# Pick up some include files that are needed later
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/tools/cmake)
endif() endif()
if(MBED_IS_NATIVE_BUILD) if(MBED_OS_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD)
# Pick up some include files that are needed later # For standalone builds, default to looking for mbed-config.cmake in the binary dir
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/tools/cmake)
include(mbed_create_distro)
else()
# Grab the Mbed configs for this target
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(mbed_set_linker_script)
endif()
# Set up options for testing
option(BUILD_TESTING "Whether to enable CTest tests in this project" ${MBED_OS_IS_STANDALONE}) # This option is also created by include(CTest) but we need it here earlier on.
if(MBED_OS_IS_STANDALONE AND BUILD_TESTING)
set(MBED_OS_ENABLE_TESTS TRUE)
option(BUILD_GREENTEA_TESTS "Build greentea tests instead of unit tests" ${CMAKE_CROSSCOMPILING})
endif()
if(MBED_OS_IS_STANDALONE)
# For standalong builds, look for mbed-config.cmake in the top level mbed os dir
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "") set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "")
# Initialize Mbed build system
include(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/app.cmake)
endif() endif()
if(MBED_IS_NATIVE_BUILD) if(MBED_IS_NATIVE_BUILD)
@ -77,7 +82,8 @@ endif()
# Create core Mbed OS targets and set up build flags ---------------------------------------------------------------------------------- # Create core Mbed OS targets and set up build flags ----------------------------------------------------------------------------------
project(mbed-os) # Create project and find compilers (if not already found)
project(mbed-os LANGUAGES C CXX ASM)
# Add all paths to the list files within Mbed OS # Add all paths to the list files within Mbed OS
list(APPEND CMAKE_MODULE_PATH list(APPEND CMAKE_MODULE_PATH
@ -100,8 +106,10 @@ endif()
# are spread in different directories can be referenced and can be linked against # are spread in different directories can be referenced and can be linked against
# by libraries that depend on them. # by libraries that depend on them.
add_library(mbed-device_key INTERFACE) add_library(mbed-device_key INTERFACE)
add_library(mbed-rtos INTERFACE) # Collects source files and flags that are in mbed-os but not mbed-baremetal add_library(mbed-rtos-flags INTERFACE) # Collects source files that are in mbed-os but not mbed-baremetal
add_library(mbed-core INTERFACE) # Collects source files and flags common to mbed-baremetal and mbed-os 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
# Validate selected C library type # Validate selected C library type
# The C library type selected has to match the library that the target can support # The C library type selected has to match the library that the target can support
@ -132,13 +140,13 @@ if(NOT MBED_IS_NATIVE_BUILD)
) )
endif() endif()
mbed_set_cpu_core_definitions(mbed-core) mbed_set_cpu_core_definitions(mbed-core-flags)
if(${MBED_TOOLCHAIN_FILE_USED}) if(${MBED_TOOLCHAIN_FILE_USED})
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN}) mbed_set_profile_options(mbed-core-flags ${MBED_TOOLCHAIN})
mbed_set_c_lib(mbed-core ${MBED_C_LIB}) mbed_set_c_lib(mbed-core-flags ${MBED_C_LIB})
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB}) mbed_set_printf_lib(mbed-core-flags ${MBED_PRINTF_LIB})
target_compile_features(mbed-core target_compile_features(mbed-core-flags
INTERFACE INTERFACE
c_std_11 c_std_11
cxx_std_14 cxx_std_14
@ -146,7 +154,7 @@ if(NOT MBED_IS_NATIVE_BUILD)
endif() endif()
target_compile_definitions(mbed-core target_compile_definitions(mbed-core-flags
INTERFACE INTERFACE
TARGET_NAME=${MBED_TARGET} TARGET_NAME=${MBED_TARGET}
) )
@ -172,24 +180,31 @@ if(NOT MBED_IS_NATIVE_BUILD)
# #
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without # TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
# using response files or global properties. # using response files or global properties.
mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH) mbed_generate_options_for_linker(mbed-core-flags RESPONSE_FILE_PATH)
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH}) set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH})
# Add compile definitions for backward compatibility with the toolchain # Add compile definitions for backward compatibility with the toolchain
# supported. New source files should instead check for __GNUC__ and __clang__ # supported. New source files should instead check for __GNUC__ and __clang__
# for the GCC_ARM and ARM toolchains respectively. # for the GCC_ARM and ARM toolchains respectively.
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_compile_definitions(mbed-core target_compile_definitions(mbed-core-flags
INTERFACE INTERFACE
TOOLCHAIN_GCC_ARM TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC TOOLCHAIN_GCC
) )
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM") elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_compile_definitions(mbed-core target_compile_definitions(mbed-core-flags
INTERFACE INTERFACE
TOOLCHAIN_ARM TOOLCHAIN_ARM
) )
endif() endif()
# Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
string(TOLOWER ${MBED_TARGET} MBED_TARGET_CMAKE_NAME)
string(REPLACE "_" "-" MBED_TARGET_CMAKE_NAME ${MBED_TARGET_CMAKE_NAME})
string(PREPEND MBED_TARGET_CMAKE_NAME "mbed-")
endif() endif()
if(MBED_IS_NATIVE_BUILD) if(MBED_IS_NATIVE_BUILD)
@ -202,11 +217,11 @@ endif()
# Generate target config header and include it in all files # Generate target config header and include it in all files
if(NOT MBED_IS_NATIVE_BUILD) if(NOT MBED_IS_NATIVE_BUILD)
mbed_write_target_config_header(${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h MBED_TARGET_DEFINITIONS MBED_CONFIG_DEFINITIONS) mbed_write_target_config_header(${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h MBED_TARGET_DEFINITIONS MBED_CONFIG_DEFINITIONS)
target_compile_options(mbed-core INTERFACE -include ${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h) target_compile_options(mbed-core-flags INTERFACE -include ${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h)
endif() endif()
# Include mbed.h and config from generate folder # Include mbed.h and config from generate folder
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
@ -237,20 +252,20 @@ add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
# Create top-level targets ---------------------------------------------------------------------------------- # Create top-level targets ----------------------------------------------------------------------------------
if(NOT MBED_IS_NATIVE_BUILD) if(NOT MBED_IS_NATIVE_BUILD)
# Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
string(TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED)
string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED})
string(PREPEND MBED_TARGET_CONVERTED "mbed-")
endif()
if(NOT MBED_IS_NATIVE_BUILD) # Create a distro for the microcontroller cmake target, ensuring its sources are only compiled once
# Core Mbed OS library mbed_create_distro(${MBED_TARGET_CMAKE_NAME}-obj ${MBED_TARGET_CMAKE_NAME} mbed-core-flags)
# Now make core flags depend on that distro, ensuring everything has access to the uC's flags and objects.
target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-obj)
# Core Mbed OS libraries
# mbed-baremetal contains baremetal sources + target sources + target compile flags. # 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. # 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. # 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. # So, it's needed to compile the core sources twice, once for RTOS and once for non-RTOS.
mbed_create_distro(mbed-baremetal mbed-core ${MBED_TARGET_CONVERTED}) mbed_create_distro(mbed-baremetal mbed-core-flags mbed-core-sources)
mbed_create_distro(mbed-os mbed-core mbed-rtos ${MBED_TARGET_CONVERTED}) mbed_create_distro(mbed-os mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
endif() endif()
# Ninja requires to be forced for response files # Ninja requires to be forced for response files

View File

@ -3,12 +3,12 @@
add_subdirectory(RTX) add_subdirectory(RTX)
target_include_directories(mbed-rtos target_include_directories(mbed-rtos-flags
INTERFACE INTERFACE
Include Include
) )
target_sources(mbed-rtos target_sources(mbed-rtos-sources
INTERFACE INTERFACE
Source/os_systick.c Source/os_systick.c
Source/os_tick_ptim.c Source/os_tick_ptim.c

View File

@ -22,7 +22,7 @@ if(${CMAKE_CROSSCOMPILING})
set(STARTUP_RTX_FILE TARGET_RTOS_M4_M7/irq_cm4f.S) set(STARTUP_RTX_FILE TARGET_RTOS_M4_M7/irq_cm4f.S)
endif() endif()
target_sources(mbed-rtos target_sources(mbed-rtos-sources
INTERFACE INTERFACE
Source/${toolchain_dir}/${STARTUP_RTX_FILE} Source/${toolchain_dir}/${STARTUP_RTX_FILE}
) )
@ -42,7 +42,7 @@ if(${CMAKE_CROSSCOMPILING})
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_GCC) _mbed_get_cortex_m_exception_handlers(TOOLCHAIN_GCC)
endif() endif()
target_include_directories(mbed-rtos target_include_directories(mbed-rtos-flags
INTERFACE INTERFACE
Config Config
Include Include
@ -50,7 +50,7 @@ target_include_directories(mbed-rtos
Source Source
) )
target_sources(mbed-rtos target_sources(mbed-rtos-sources
INTERFACE INTERFACE
Config/RTX_Config.c Config/RTX_Config.c

View File

@ -3,7 +3,7 @@
add_subdirectory(RTE) add_subdirectory(RTE)
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
. .
) )

View File

@ -1,7 +1,7 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
include include
) )

View File

@ -3,24 +3,24 @@
if(${CMAKE_CROSSCOMPILING}) if(${CMAKE_CROSSCOMPILING})
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_sources(mbed-rtos target_sources(mbed-rtos-sources
INTERFACE INTERFACE
TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c
) )
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM") elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_sources(mbed-rtos target_sources(mbed-rtos-sources
INTERFACE INTERFACE
TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c
) )
endif() endif()
endif() endif()
target_include_directories(mbed-rtos target_include_directories(mbed-rtos-flags
INTERFACE INTERFACE
include include
) )
target_sources(mbed-rtos target_sources(mbed-rtos-sources
INTERFACE INTERFACE
source/mbed_boot.c source/mbed_boot.c
source/mbed_rtos_rtx.c source/mbed_rtos_rtx.c
@ -28,7 +28,7 @@ target_sources(mbed-rtos
source/mbed_rtx_idle.cpp source/mbed_rtx_idle.cpp
) )
target_compile_definitions(mbed-rtos target_compile_definitions(mbed-rtos-flags
INTERFACE INTERFACE
MBED_CONF_RTOS_PRESENT=1 MBED_CONF_RTOS_PRESENT=1
) )

View File

@ -31,5 +31,5 @@ target_compile_definitions(mbed-cellular
target_link_libraries(mbed-cellular target_link_libraries(mbed-cellular
INTERFACE INTERFACE
mbed-netsocket mbed-netsocket
mbed-core mbed-core-flags
) )

View File

@ -14,5 +14,5 @@ target_sources(mbed-ble
target_link_libraries(mbed-ble target_link_libraries(mbed-ble
INTERFACE INTERFACE
mbed-core mbed-core-flags
) )

View File

@ -22,16 +22,16 @@ target_sources(mbed-nanostack-libservice
# The definition, source files and include directories below # The definition, source files and include directories below
# are needed by mbed-trace which is part of the mbed-core CMake target # are needed by mbed-trace which is part of the mbed-core CMake target
target_compile_definitions(mbed-core target_compile_definitions(mbed-core-flags
INTERFACE INTERFACE
MBED_CONF_NANOSTACK_LIBSERVICE_PRESENT=1 MBED_CONF_NANOSTACK_LIBSERVICE_PRESENT=1
) )
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
. .
./mbed-client-libservice ./mbed-client-libservice
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
source/libBits/common_functions.c source/libBits/common_functions.c
source/libip6string/ip6tos.c source/libip6string/ip6tos.c

View File

@ -9,7 +9,7 @@ if(MBED_OS_ENABLE_TESTS)
endif() endif()
endif() endif()
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
. .
./include ./include
@ -17,7 +17,7 @@ target_include_directories(mbed-core
./include/drivers/internal ./include/drivers/internal
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
source/AnalogIn.cpp source/AnalogIn.cpp
source/AnalogOut.cpp source/AnalogOut.cpp

View File

@ -4,8 +4,8 @@
# List of all features libraries available. # List of all features libraries available.
add_library(mbed-fpga-ci-test-shield INTERFACE) add_library(mbed-fpga-ci-test-shield INTERFACE)
add_library(mbed-client-cli INTERFACE) add_library(mbed-client-cli INTERFACE)
add_library(mbed-unity INTERFACE) add_library(mbed-unity OBJECT EXCLUDE_FROM_ALL)
add_library(mbed-utest INTERFACE) add_library(mbed-utest OBJECT EXCLUDE_FROM_ALL)
add_subdirectory(frameworks/COMPONENT_FPGA_CI_TEST_SHIELD) add_subdirectory(frameworks/COMPONENT_FPGA_CI_TEST_SHIELD)
add_subdirectory(frameworks/mbed-client-cli) add_subdirectory(frameworks/mbed-client-cli)

View File

@ -1,14 +1,17 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
add_library(mbed-greentea OBJECT EXCLUDE_FROM_ALL)
target_include_directories(mbed-greentea target_include_directories(mbed-greentea
INTERFACE PUBLIC
. .
greentea-client greentea-client
) )
target_sources(mbed-greentea target_sources(mbed-greentea
INTERFACE PRIVATE
source/greentea_metrics.cpp source/greentea_metrics.cpp
source/greentea_test_env.cpp source/greentea_test_env.cpp
) )
target_link_libraries(mbed-greentea PUBLIC mbed-core-flags)

View File

@ -1,6 +1,6 @@
# Copyright (c) 2021 ARM Limited. All rights reserved. # Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
add_library(mbed-greentea-io INTERFACE) add_library(mbed-greentea-io OBJECT EXCLUDE_FROM_ALL)
target_sources(mbed-greentea-io INTERFACE mbed_io.cpp) target_sources(mbed-greentea-io PRIVATE mbed_io.cpp)
target_link_libraries(mbed-greentea-io INTERFACE mbed-core) target_link_libraries(mbed-greentea-io PUBLIC mbed-core-flags)

View File

@ -2,12 +2,14 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
target_include_directories(mbed-unity target_include_directories(mbed-unity
INTERFACE PUBLIC
. .
unity unity
) )
target_sources(mbed-unity target_sources(mbed-unity
INTERFACE PRIVATE
source/unity.c source/unity.c
) )
target_link_libraries(mbed-unity PUBLIC mbed-core-flags mbed-utest)

View File

@ -2,13 +2,14 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
target_include_directories(mbed-utest target_include_directories(mbed-utest
INTERFACE PUBLIC
. .
utest utest
../greentea-client
) )
target_sources(mbed-utest target_sources(mbed-utest
INTERFACE PRIVATE
mbed-utest-shim.cpp mbed-utest-shim.cpp
source/unity_handler.cpp source/unity_handler.cpp
source/utest_case.cpp source/utest_case.cpp
@ -20,3 +21,5 @@ target_sources(mbed-utest
source/utest_stack_trace.cpp source/utest_stack_trace.cpp
source/utest_types.cpp source/utest_types.cpp
) )
target_link_libraries(mbed-utest PUBLIC mbed-core-flags)

View File

@ -13,13 +13,13 @@ add_subdirectory(TARGET_FLASH_CMSIS_ALGO EXCLUDE_FROM_ALL)
add_subdirectory(usb) add_subdirectory(usb)
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
include include
include/hal include/hal
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
source/LowPowerTickerWrapper.cpp source/LowPowerTickerWrapper.cpp
source/mbed_compat.c source/mbed_compat.c

View File

@ -1,13 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
include include
include/usb include/usb
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
source/mbed_usb_phy.cpp source/mbed_usb_phy.cpp
) )

View File

@ -21,7 +21,7 @@ add_subdirectory(mbed-trace)
add_subdirectory(randlib) add_subdirectory(randlib)
add_subdirectory(source) add_subdirectory(source)
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
include include
include/platform include/platform

View File

@ -20,7 +20,7 @@ target_sources(mbed-psa
src/psa_hrng.c src/psa_hrng.c
) )
target_link_libraries(mbed-core target_link_libraries(mbed-core-flags
INTERFACE INTERFACE
mbed-psa mbed-psa
) )

View File

@ -1,12 +1,12 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
. .
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
mstd_mutex.cpp mstd_mutex.cpp
) )

View File

@ -3,13 +3,13 @@
add_subdirectory(source) add_subdirectory(source)
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
include include
include/mbed-trace include/mbed-trace
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
source/mbed_trace.c source/mbed_trace.c
) )

View File

@ -7,12 +7,12 @@ endif()
add_subdirectory(minimal-printf) add_subdirectory(minimal-printf)
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
. .
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
ATCmdParser.cpp ATCmdParser.cpp
CThunkBase.cpp CThunkBase.cpp
@ -50,7 +50,7 @@ target_sources(mbed-core
) )
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM" AND MBED_C_LIB STREQUAL "small") if(MBED_TOOLCHAIN STREQUAL "GCC_ARM" AND MBED_C_LIB STREQUAL "small")
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
newlib_nano_malloc_workaround.c newlib_nano_malloc_workaround.c
) )

View File

@ -1,9 +1,9 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved. # Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
target_sources(mbed-core INTERFACE TOOLCHAIN_GCC/except.S) target_sources(mbed-core-sources INTERFACE TOOLCHAIN_GCC/except.S)
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
mbed_fault_handler.c mbed_fault_handler.c
) )

View File

@ -1,12 +1,12 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
. .
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
mbed_printf_armlink_overrides.c mbed_printf_armlink_overrides.c
mbed_printf_implementation.c mbed_printf_implementation.c

View File

@ -9,7 +9,7 @@ if(MBED_OS_ENABLE_TESTS)
endif() endif()
endif() endif()
target_include_directories(mbed-core target_include_directories(mbed-core-flags
INTERFACE INTERFACE
. .
./include ./include
@ -18,7 +18,7 @@ target_include_directories(mbed-core
./source ./source
) )
target_sources(mbed-core target_sources(mbed-core-sources
INTERFACE INTERFACE
source/EventFlags.cpp source/EventFlags.cpp
source/Kernel.cpp source/Kernel.cpp
@ -30,7 +30,7 @@ target_sources(mbed-core
) )
target_compile_definitions(mbed-core target_compile_definitions(mbed-core-flags
INTERFACE INTERFACE
MBED_CONF_RTOS_API_PRESENT=1 MBED_CONF_RTOS_API_PRESENT=1
) )

View File

@ -13,6 +13,7 @@ endif()
include(${MBED_CONFIG_PATH}/mbed_config.cmake) include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(mbed_set_post_build) include(mbed_set_post_build)
include(mbed_generate_config_header) include(mbed_generate_config_header)
include(mbed_create_distro)
# Load toolchain file # Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED) if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
@ -62,6 +63,3 @@ else()
message(STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed") message(STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed")
endif() endif()
# load mbed_create_distro
include(${CMAKE_CURRENT_LIST_DIR}/create_distro.cmake)

View File

@ -34,9 +34,6 @@ endfunction(copy_append_property)
function(mbed_create_distro NAME) # ARGN: modules... function(mbed_create_distro NAME) # ARGN: modules...
add_library(${NAME} OBJECT EXCLUDE_FROM_ALL) add_library(${NAME} OBJECT EXCLUDE_FROM_ALL)
# First link as private dependencies
target_link_libraries(${NAME} PRIVATE ${ARGN})
# Now copy include dirs, compile defs, and compile options (but NOT interface source files) over # Now copy include dirs, compile defs, and compile options (but NOT interface source files) over
# to the distribution target so they will be passed into things that link to it. # to the distribution target so they will be passed into things that link to it.
# To do this, we need to recursively traverse the tree of dependencies. # To do this, we need to recursively traverse the tree of dependencies.
@ -51,6 +48,27 @@ function(mbed_create_distro NAME) # ARGN: modules...
copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME}) copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME})
copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME}) copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME})
# Make sure that linking to the distro pulls in the compiled code from CURR_MODULE
target_link_libraries(${NAME} PRIVATE ${CURR_MODULE})
# CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries
# via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/.
# see: https://cmake.org/pipermail/cmake/2019-May/069453.html
# Once the INTERFACE_LINK_LIBRARIES_DIRECT property becomes widely available we could use that instead to fix this.
get_property(CURR_MODULE_TYPE TARGET ${CURR_MODULE} PROPERTY TYPE)
if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY")
target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:${CURR_MODULE}>)
# Check if this object library has any other libraries exported through its INTERFACE_SOURCES.
# If it does, we need to propagate those too.
get_property(OBJ_INTERFACE_SOURCES TARGET ${NAME} PROPERTY INTERFACE_SOURCES)
foreach(INTERFACE_SOURCE ${OBJ_INTERFACE_SOURCES})
if(INTERFACE_SOURCE MATCHES "\\$<TARGET_OBJECTS:.*>")
target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE})
endif()
endforeach()
endif()
list(REMOVE_AT REMAINING_MODULES 0) list(REMOVE_AT REMAINING_MODULES 0)
list(APPEND COMPLETED_MODULES ${CURR_MODULE}) list(APPEND COMPLETED_MODULES ${CURR_MODULE})
@ -58,10 +76,14 @@ function(mbed_create_distro NAME) # ARGN: modules...
get_property(SUBMODULES TARGET ${CURR_MODULE} PROPERTY INTERFACE_LINK_LIBRARIES) get_property(SUBMODULES TARGET ${CURR_MODULE} PROPERTY INTERFACE_LINK_LIBRARIES)
foreach(SUBMODULE ${SUBMODULES}) foreach(SUBMODULE ${SUBMODULES})
if(NOT "${SUBMODULE}" MATCHES "::@") # remove CMake internal CMAKE_DIRECTORY_ID_SEP markers if(NOT "${SUBMODULE}" MATCHES "::@") # remove CMake internal CMAKE_DIRECTORY_ID_SEP markers
# Remove LINK_ONLY genexes from target_link_libraries(... PRIVATE). We can ignore things wrapped in these
# because they will already have been handled by the target_link_libraries earlier on.
if(NOT "${SUBMODULE}" MATCHES "\\$<LINK_ONLY:.*>")
if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES) if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES)
list(APPEND REMAINING_MODULES ${SUBMODULE}) list(APPEND REMAINING_MODULES ${SUBMODULE})
endif() endif()
endif() endif()
endif()
endforeach() endforeach()
endwhile() endwhile()

View File

@ -78,13 +78,6 @@ function(mbed_greentea_add_test)
return() return()
endif() endif()
# TODO: After we convert all greentea tests to use CTest, remove this
# add_subdirectory call. We will attach the tests to the mbed-os project,
# rather than creating a new project for each test that depends on mbed-os.
if(NOT BUILD_GREENTEA_TESTS)
add_subdirectory(${MBED_ROOT} build)
endif()
add_executable(${MBED_GREENTEA_TEST_NAME}) add_executable(${MBED_GREENTEA_TEST_NAME})
target_include_directories(${MBED_GREENTEA_TEST_NAME} target_include_directories(${MBED_GREENTEA_TEST_NAME}
@ -119,6 +112,12 @@ function(mbed_greentea_add_test)
set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.bin") set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.bin")
endif() endif()
# User can set this cache variable to supply extra arguments to greentea.
# such as: -d to set the drive path, -p to set the COM port.
if(DEFINED MBED_GREENTEA_EXTRA_HTRUN_ARGUMENTS)
list(APPEND MBED_HTRUN_ARGUMENTS ${MBED_GREENTEA_EXTRA_HTRUN_ARGUMENTS})
endif()
if(DEFINED MBED_GREENTEA_HOST_TESTS_DIR) if(DEFINED MBED_GREENTEA_HOST_TESTS_DIR)
list(APPEND MBED_HTRUN_ARGUMENTS "-e;${MBED_GREENTEA_HOST_TESTS_DIR}") list(APPEND MBED_HTRUN_ARGUMENTS "-e;${MBED_GREENTEA_HOST_TESTS_DIR}")
endif() endif()

View File

@ -6,6 +6,7 @@
# Called once for each MCU target in the build system. # Called once for each MCU target in the build system.
# #
function(mbed_set_linker_script input_target raw_linker_script_path) function(mbed_set_linker_script input_target raw_linker_script_path)
set(LINKER_SCRIPT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${input_target}.link_script.ld) set(LINKER_SCRIPT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${input_target}.link_script.ld)
# To avoid path limits on Windows, we create a "response file" and set the path to it as a # To avoid path limits on Windows, we create a "response file" and set the path to it as a
# global property. We need this solely to pass the compile definitions to GCC's preprocessor, # global property. We need this solely to pass the compile definitions to GCC's preprocessor,