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

Mbed OS components as OBJECT libs #21

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
caa5f58
CMake: turn mbed-core into interface + obj libraries
0xc0170 Feb 22, 2021
afd2d1f
Events: create interface + obj library
0xc0170 Feb 22, 2021
51e447a
cmsis: fix private link for core
0xc0170 Feb 22, 2021
8c33c43
Maxim: turn max32630 into interface + object libraries
0xc0170 Feb 22, 2021
3db33b2
CMake: fix deps on other libraries
0xc0170 Feb 22, 2021
cad59f7
CMake: mbed target converted is cached variable
0xc0170 Feb 23, 2021
b1caf5e
CMake Maxim: fix private obj files
0xc0170 Feb 23, 2021
231dec4
CMake: hit object library cyclic deps error
0xc0170 Feb 23, 2021
6c6fa3d
CMake: provide util function to connect object with interface lib
0xc0170 Feb 23, 2021
8ed00d8
CMake: expose what core needs from a target via MBED_TARGET_CONVERTED…
0xc0170 Feb 23, 2021
9175aa1
CMake cmsis: use util function
0xc0170 Feb 23, 2021
e13e7c9
CMake Maxim: turn maxim targets to interface libs
0xc0170 Feb 23, 2021
8bea02d
CMake cmsis: add only headers from targets, not everything
0xc0170 Feb 23, 2021
3a0ba44
CMake: use Jamies trick to copy core files and build with Mbed OS
0xc0170 Feb 23, 2021
e7bf3a7
Maxim: revert unrelated change
0xc0170 Feb 23, 2021
38d684a
CMake: add util.cmake file
0xc0170 Feb 23, 2021
890f897
CMake: fix baremetal build
0xc0170 Feb 24, 2021
336b4b1
events: remove target, core should get these in
0xc0170 Feb 24, 2021
5006d46
CMake: core exports target includes for other components to be available
0xc0170 Feb 24, 2021
6b9baa4
CMake: fix exposing target includes for mbed-os/baremetal
0xc0170 Feb 24, 2021
d93fbcf
CMake readme: add libraries section
0xc0170 Feb 25, 2021
ec0e1c4
CMake: copy compile defs and link options to core from targets
0xc0170 Feb 25, 2021
cd1475a
CMake linker: move linker to mbed-core - upstream it to an app
0xc0170 Feb 25, 2021
a969d78
CMake readme: fix typos in the comment
0xc0170 Feb 25, 2021
63d1935
events: use OBJECT library
0xc0170 Feb 25, 2021
cfddd24
CMake linker: fix change from the latest rebase
0xc0170 Mar 1, 2021
5c86b46
CMake: add comments for the magic we do around core/rtos libraries
0xc0170 Mar 1, 2021
dac0ab0
CMake: simplify internal object libraries
0xc0170 Mar 1, 2021
f972aab
CMake: remove util function, link object libs regularly
0xc0170 Mar 1, 2021
fa85e39
CMake: expose targets includes to mbed-core
0xc0170 Mar 1, 2021
7ba307d
CMake: core should expose also compile defs from target
0xc0170 Mar 1, 2021
1896097
CMake: fix baremetal, core-obj links to core and target
0xc0170 Mar 1, 2021
a06f7a8
CMake: add comments to internal mbed-os libraries
0xc0170 Mar 2, 2021
03fe4b1
CMake readme: fix libraries details
0xc0170 Mar 2, 2021
1d3e74f
CMake rtos: we link rtos in mbed-os where it gets all flags
0xc0170 Mar 2, 2021
869ad21
CMake cmsis: remove unused linking
0xc0170 Mar 2, 2021
98e05bf
CMake Maxim: remove util
0xc0170 Mar 2, 2021
f9a4f01
CMake cmsis: revert object for cmsis-cortex-x libs
0xc0170 Mar 2, 2021
1ebbd57
CMake: rename -obj to -objects libraries
0xc0170 Mar 2, 2021
6856558
CMake readme: split the table to user-facing and internal libs
0xc0170 Mar 2, 2021
d36dc4d
CMake: add comment about OBJECT limitation and our source tree deps
0xc0170 Mar 2, 2021
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
49 changes: 44 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,34 @@ cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(tools/cmake/set_linker_script.cmake)

# Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
set(MBED_TARGET_CONVERTED "" CACHE STRING "" FORCE)
string(TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED)
string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED})
string(PREPEND MBED_TARGET_CONVERTED "mbed-")

# The main issue not using OBJECT for core/rtos and target libraries is their circular dependencies.
# They were always consider to be part of the Mbed OS as whole. To illustrate, rtos requires some
# core (tickers, critical section, etc) and target (MCU capabilities) functionalities. Core declares functionality that
# target implements (hal <-> target).
# Known CMake issue: https://gitlab.kitware.com/cmake/cmake/-/issues/17905 for details
#
# We provide the main two libraries for an application: `mbed-os` and `mbed-baremetal`
# The other libraries below like `mbed-core`, `mbed-rtos` and their `-objects` parts are internal libraries to address the above
# limitation.
#
# mbed-core - flags for hal/driver/platform and MBED_TARGET
# mbed-core-objects - only source files
add_library(mbed-core INTERFACE)
add_library(mbed-core-objects OBJECT EXCLUDE_FROM_ALL)
target_link_libraries(mbed-core-objects mbed-core ${MBED_TARGET_CONVERTED})

# mbed-os - application library
# mbed-os-objects - core + rtos objects to build all together
add_library(mbed-os INTERFACE)
add_library(mbed-os-objects OBJECT EXCLUDE_FROM_ALL)

target_sources(mbed-os INTERFACE $<TARGET_OBJECTS:mbed-os-objects> $<TARGET_OBJECTS:mbed-rtos-objects>)

target_link_libraries(mbed-os
INTERFACE
Expand All @@ -20,10 +45,13 @@ target_link_libraries(mbed-os

add_library(mbed-baremetal INTERFACE)

target_sources(mbed-baremetal INTERFACE $<TARGET_OBJECTS:mbed-core-objects>)

target_link_libraries(mbed-baremetal
INTERFACE
mbed-core
)

# Validate selected C library type
# The C library type selected has to match the library that the target can support
if(${MBED_C_LIB} STREQUAL "small")
Expand Down Expand Up @@ -113,13 +141,18 @@ target_include_directories(mbed-core
# by libraries that depend on them.
# TODO CMake: Should the source files be moved?
add_library(mbed-device_key INTERFACE)

add_library(mbed-rtos INTERFACE)
add_library(mbed-rtos-objects OBJECT)

target_link_libraries(mbed-rtos-objects mbed-rtos mbed-core)

add_subdirectory(cmsis)
add_subdirectory(drivers)
add_subdirectory(hal)
add_subdirectory(platform)
add_subdirectory(rtos)

add_subdirectory(targets)

# The directories below contain optional target libraries
Expand All @@ -132,12 +165,18 @@ add_subdirectory(features EXCLUDE_FROM_ALL)
add_subdirectory(cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL)
add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)

# 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-")
# Expose linker option to an application. As we do not directly link to MBED_TARGET_CONVERTED due to built
# object core library
target_link_options(mbed-core INTERFACE $<TARGET_PROPERTY:${MBED_TARGET_CONVERTED},INTERFACE_LINK_OPTIONS>)
# Expose include directories. cmsis.h/device.h and other headers are required by libraries or applications
target_include_directories(mbed-core INTERFACE $<TARGET_PROPERTY:${MBED_TARGET_CONVERTED},INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_definitions(mbed-core INTERFACE $<TARGET_PROPERTY:${MBED_TARGET_CONVERTED},COMPILE_DEFINITIONS>)

# Some of core files require MBED_CONF_RTOS_PRESENT symbol (defined in rtos). For baremetal, it's sufficient to link with mbed-core (symbol undefined = RTOS not present). For Mbed OS, this symbol must be defined and set, therefore we copy sources and build them together in mbed-os-objects
get_property(MBED_CORE_SOURCES TARGET mbed-core-objects PROPERTY SOURCES)
target_sources(mbed-os-objects PRIVATE ${MBED_CORE_SOURCES})

target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
target_link_libraries(mbed-os-objects mbed-core mbed-rtos ${MBED_TARGET_CONVERTED})

#
# Converts output file of `target` to binary file and to Intel HEX file.
Expand Down
4 changes: 2 additions & 2 deletions cmsis/CMSIS_5/CMSIS/RTOS2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ target_include_directories(mbed-rtos
Include
)

target_sources(mbed-rtos
INTERFACE
target_sources(mbed-os-objects
PRIVATE
Source/os_systick.c
Source/os_tick_ptim.c
)
10 changes: 5 additions & 5 deletions cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function(_mbed_get_cortex_m_exception_handlers toolchain_dir)
set(STARTUP_RTX_FILE TARGET_RTOS_M4_M7/irq_cm4f.S)
endif()

target_sources(mbed-rtos
INTERFACE
target_sources(mbed-os-objects
PRIVATE
Source/${toolchain_dir}/${STARTUP_RTX_FILE}
)
endforeach()
Expand All @@ -31,7 +31,7 @@ endfunction()
function(_mbed_get_cortex_a_exception_handlers)
foreach(key ${MBED_TARGET_LABELS})
if(${key} STREQUAL CORTEX_A)
target_sources(mbed-rtos INTERFACE Config/TARGET_CORTEX_A/handlers.c)
target_sources(mbed-os-objects PRIVATE Config/TARGET_CORTEX_A/handlers.c)
endif()
endforeach()
endfunction()
Expand All @@ -52,8 +52,8 @@ target_include_directories(mbed-rtos
Source
)

target_sources(mbed-rtos
INTERFACE
target_sources(mbed-os-objects
PRIVATE
Config/RTX_Config.c

Library/cmsis_os1.c
Expand Down
12 changes: 6 additions & 6 deletions cmsis/device/rtos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# SPDX-License-Identifier: Apache-2.0

if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_sources(mbed-rtos
INTERFACE
target_sources(mbed-rtos-objects
PRIVATE
TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_sources(mbed-rtos
INTERFACE
target_sources(mbed-rtos-objects
PRIVATE
TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c
)
endif()
Expand All @@ -18,8 +18,8 @@ target_include_directories(mbed-rtos
include
)

target_sources(mbed-rtos
INTERFACE
target_sources(mbed-os-objects
PRIVATE
source/mbed_boot.c
source/mbed_rtos_rtx.c
source/mbed_rtx_handlers.c
Expand Down
4 changes: 2 additions & 2 deletions connectivity/libraries/nanostack-libservice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ target_include_directories(mbed-core
.
./mbed-client-libservice
)
target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
source/libBits/common_functions.c
source/libip6string/ip6tos.c
)
4 changes: 2 additions & 2 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ target_include_directories(mbed-core
./include/drivers/internal
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
source/AnalogIn.cpp
source/AnalogOut.cpp
source/BufferedSerial.cpp
Expand Down
10 changes: 6 additions & 4 deletions events/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_library(mbed-events INTERFACE)
add_library(mbed-events OBJECT)

target_include_directories(mbed-events
INTERFACE
PUBLIC
.
./include
./include/events
./include/events/internal
)

target_sources(mbed-events
INTERFACE
PRIVATE
source/EventQueue.cpp
source/equeue.c
source/equeue_mbed.cpp
Expand All @@ -21,6 +21,8 @@ target_sources(mbed-events
)

target_compile_definitions(mbed-events
INTERFACE
PUBLIC
MBED_CONF_EVENTS_PRESENT=1
)

target_link_libraries(mbed-events PRIVATE mbed-core)
4 changes: 2 additions & 2 deletions hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ target_include_directories(mbed-core
include/hal
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
source/LowPowerTickerWrapper.cpp
source/mbed_compat.c
source/mbed_critical_section_api.c
Expand Down
4 changes: 2 additions & 2 deletions hal/usb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ target_include_directories(mbed-core
include/usb
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
source/mbed_usb_phy.cpp
)
4 changes: 2 additions & 2 deletions platform/cxxsupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target_include_directories(mbed-core
.
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
mstd_mutex.cpp
)
4 changes: 2 additions & 2 deletions platform/mbed-trace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target_include_directories(mbed-core
include/mbed-trace
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
source/mbed_trace.c
)
4 changes: 2 additions & 2 deletions platform/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ target_include_directories(mbed-core
.
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
ATCmdParser.cpp
CThunkBase.cpp
CriticalSectionLock.cpp
Expand Down
8 changes: 4 additions & 4 deletions platform/source/TARGET_CORTEX_M/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# SPDX-License-Identifier: Apache-2.0

if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_sources(mbed-core INTERFACE TOOLCHAIN_GCC/except.S)
target_sources(mbed-core-objects PRIVATE TOOLCHAIN_GCC/except.S)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_sources(mbed-core INTERFACE TOOLCHAIN_ARM/except.S)
target_sources(mbed-core-objects PRIVATE TOOLCHAIN_ARM/except.S)
endif()

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
mbed_fault_handler.c
)
4 changes: 2 additions & 2 deletions platform/source/minimal-printf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ target_include_directories(mbed-core
.
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
mbed_printf_armlink_overrides.c
mbed_printf_implementation.c
mbed_printf_wrapper.c
Expand Down
4 changes: 2 additions & 2 deletions rtos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ target_include_directories(mbed-core
./source
)

target_sources(mbed-core
INTERFACE
target_sources(mbed-core-objects
PRIVATE
source/EventFlags.cpp
source/Kernel.cpp
source/Mutex.cpp
Expand Down
1 change: 0 additions & 1 deletion targets/TARGET_Maxim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0


add_subdirectory(TARGET_MAX32620C EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_MAX32625 EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_MAX32630 EXCLUDE_FROM_ALL)
Expand Down
5 changes: 1 addition & 4 deletions targets/TARGET_Maxim/TARGET_MAX32620C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,4 @@ target_sources(mbed-maxim-max32620c
${STARTUP_FILE}
)

target_link_libraries(mbed-maxim-max32620c
INTERFACE
mbed-maxim
)
target_link_libraries(mbed-maxim-max32620c INTERFACE mbed-maxim)
42 changes: 42 additions & 0 deletions tools/cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,45 @@ Notes:
- words separated by hyphens

For example: `mbed-ble-cordio`

## Mbed libraries

This section provides description for all CMake targets within Mbed OS repository.

### mbed-os and mbed-baremetal libraries

An application links to either mbed-os or mbed-baremetal.

| Target | Function |
| ------------- | ------------- |
| mbed-os | Interface library that attaches Mbed OS to a target (objects from mbed-core and mbed-rtos) |
| mbed-baremetal | Interface library that attaches Mbed baremetal to a target (objects from mbed-core) |

These are internal targets. They are subject to change. An application should not link to any of these.

| Target | Function |
| ------------- | ------------- |
| mbed-cmsis-cortex-m | CMSIS library for Cortex-M |
| mbed-cmsis-cortex-a | CMSIS library for Cortex-A |
| mbed-core | Contains flags from Mbed baremetal. All Mbed OS libraries link to this. |
| mbed-core-objects | Builds objects for Mbed baremetal |
| mbed-rtos | Contains flags that turn Mbed baremetal into Mbed OS |
| mbed-rtos-objects | Builds objects for RTOS |
| mbed-os-objects | Build objects for Mbed OS (objects from mbed-core and mbed-rtos) |
| ${MBED_TARGET_CONVERTED} | Contains interface flags and sources that adapt Mbed OS for a target |

### Additional Mbed OS libraries

An application must explicitely link them using `target_link_libraries()`.

| Target | Function |
| ------------- | ------------- |
| mbed-events | Events library
| mbed-ble | Bluetooth library
| mbed-storage | Storage library
| mbed-mbedtls | TLS library
| mbed-nfc | NFC library
| mbed-nanostack | Nanostack library
| mbed-netsocket | Netsocket library
| mbed-lorawan | Lorawan library
| mbed-wifi | Wifi library