Skip to content

CMake: Add initial support #13566

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

Merged
merged 164 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
52dd933
CMake: Add design document
hugueskamba Jul 20, 2020
f4e4012
CMake: Intentionally untrack CMake generated files
hugueskamba Jul 20, 2020
6dc5f5a
CMake: Add CMake scripts
hugueskamba Jul 20, 2020
d836489
CMake: Add support for cmsis dir
hugueskamba Jul 20, 2020
311b2ca
CMake: Add support for components dir
hugueskamba Jul 20, 2020
59a7d77
CMake: Add support for connectivity dir
hugueskamba Jul 20, 2020
8408289
CMake: Add support for drivers dir
hugueskamba Jul 20, 2020
a63fa60
CMake: Add support for events dir
hugueskamba Jul 20, 2020
1d6f86f
CMake: Add support for features dir
hugueskamba Jul 20, 2020
8f9bf40
CMake: Add support for hal dir
hugueskamba Jul 20, 2020
929adbe
CMake: Add support for platform dir
hugueskamba Jul 20, 2020
5c453e5
CMake: Add support for rtos dir
hugueskamba Jul 20, 2020
a08be8c
CMake: Add support for storage dir
hugueskamba Jul 20, 2020
70d9229
CMake: Add support for K64F target
hugueskamba Jul 20, 2020
8a74bf1
CMake: Add support for NRF52840_DK target
hugueskamba Jul 20, 2020
30e8886
CMake: Add support for DISCO_L475VG_IOT01A target
hugueskamba Jul 20, 2020
53d7128
CMake: Add support for WIO_3G target
hugueskamba Jul 20, 2020
5709dd2
CMake: Add Travis script to run a basic CI check for PRs
hugueskamba Jul 20, 2020
554a5d3
CMake: Fix failure due to restructure of rtos and ppp directories
hugueskamba Jul 21, 2020
b78ef7a
CMake: Fix CI error due to dir restruct of rtos and storage dirs
hugueskamba Jul 22, 2020
71c48e0
CMake: remove version number from ARM toolchain
hugueskamba Jul 20, 2020
6b5ef8a
cmake: Stringify develop.cmake
urutva Jul 21, 2020
915d552
cmake: Re-order cmake script inclusions
urutva Jul 23, 2020
f18622e
cmake: Fix arm compiler build failures
urutva Jul 23, 2020
10f4212
cmake: Using Arm compiler from Mbed Studio
urutva Jul 21, 2020
f0072e7
CMake design doc: update to the latest mbed-tools updates
0xc0170 Jul 21, 2020
8dabb28
cmake: Remove IAR support
Patater Jul 23, 2020
bd45acb
CMake: Fix failure due to kvstore and cellular dirs changes
hugueskamba Jul 23, 2020
b03e94f
CMake env: fix copyright
0xc0170 Jul 23, 2020
e2f38ab
CMake env: remove components, needs design first
0xc0170 Jul 23, 2020
08eb1e3
CMake: fix missing copyright
0xc0170 Jul 23, 2020
1bb6be3
CMake util: fix copyright
0xc0170 Jul 23, 2020
7dd7337
CMake: Remove unsupported ARM toolchain support
hugueskamba Jul 23, 2020
debffb6
cmake: Armclang - Fix assembler and linker flags
urutva Jul 23, 2020
e172eb3
CMake: Use modern CMake techniques to set toolchain options
hugueskamba Jul 23, 2020
2d1508d
CMake: Ensure targets creation before usage in `target_` functions
hugueskamba Jul 27, 2020
4b13332
CMake: Issue a fatal error if a lower version of CMake is used
hugueskamba Jul 27, 2020
396ddc7
CMake: Fix build due to system_storage and netsocket dir move in master
hugueskamba Jul 27, 2020
0e1770d
Remove gen_config interface library target
rwalton-arm Jul 27, 2020
335dfdd
Add tools generated definitions and properties
rwalton-arm Jul 28, 2020
ecfee28
CMake: move env to toolchain file (#13369)
0xc0170 Jul 29, 2020
8b21238
CMake: Fix failure due to events and netsocket dirs changes
hugueskamba Jul 29, 2020
3952212
Travis cmake: add testing all profiles
0xc0170 Jul 28, 2020
24c79a4
CMake: Fix build failure due to nanostack drivers move
hugueskamba Jul 30, 2020
2efe469
CMake toolchain: set optimization in profiles
0xc0170 Jul 28, 2020
d3d88e3
CMake: set debug optimizations
0xc0170 Jul 28, 2020
5128b02
CMake: set develop optimizations
0xc0170 Jul 28, 2020
67c364d
CMake: set release optimizations
0xc0170 Jul 28, 2020
fa8d9fd
CMake GCC ARM: add -g3 to the common
0xc0170 Jul 30, 2020
c05170f
CMake: Remove app.cmake module
hugueskamba Jul 30, 2020
ef11e06
CMake: Remove add_executable
hugueskamba Jul 30, 2020
06f4e1b
CMake: Break down RTX CMake source file into 2 source files
hugueskamba Jul 31, 2020
100be3d
CMake: Fix ARM toolchain compilation
hugueskamba Jul 31, 2020
1b52415
CMake: Move MBED_STUDIO_ARM_COMPILER to ARM.cmake module
hugueskamba Jul 31, 2020
4af48a3
CMake: Remove MCU core specific option from ARM ASM options
hugueskamba Jul 31, 2020
42cd929
CMake: Fix detection of RTX assembly file
hugueskamba Jul 31, 2020
4f8568c
CMake: using CMAKE_BUILD_TYPE for choosing a profile
0xc0170 Jul 27, 2020
2f89e99
CMake build type: set default Develop profile
0xc0170 Jul 28, 2020
18a1380
CMake profile: fix alignment
0xc0170 Jul 28, 2020
894f8cc
Travis: use build type for cmake
0xc0170 Jul 28, 2020
02c0154
CMake profile: fix comments
0xc0170 Jul 28, 2020
90e5d3a
CMake toolchain: clear flags to be able to overwrite them
0xc0170 Jul 28, 2020
1ebedf2
CMake GCC ARM: use nosys specs for linker
0xc0170 Jul 29, 2020
57f39ae
CMake toolchain: fix options comment
0xc0170 Jul 31, 2020
aac5e80
CMake: Profile comments update
0xc0170 Jul 31, 2020
8b3cec2
Update cmake/toolchain.cmake
0xc0170 Aug 2, 2020
e744208
CMake: Fix build failure due to drivers and lwipstack dirs move
hugueskamba Aug 5, 2020
c876bc1
CMake: Fix build issue due to platform changes
hugueskamba Aug 5, 2020
76fd50a
CMake: Fix access to cellular drivers
hugueskamba Aug 6, 2020
5f53181
CMake: Fix access to usb hal source file
hugueskamba Aug 6, 2020
f1a3d69
CMake: Fix WIO_3G scatter file shebang to work with ARM Compiler 6
hugueskamba Aug 6, 2020
c1fa350
CMake: Minor formatting of top level CMakeLists.txt source file
hugueskamba Aug 6, 2020
c30d925
CMake: Fix build failure due to nanostack dir move
hugueskamba Aug 7, 2020
de3462d
CMake: Remove default build type selection from top level source file
hugueskamba Aug 10, 2020
20e19de
CMake: Fix breakage due to BLE dir move
hugueskamba Aug 10, 2020
400211c
CMake: Do not hard code target in CPU core CMake module
hugueskamba Aug 4, 2020
c8b4822
CMake: Remove toolchain module dependency on cpu core CMake modules
hugueskamba Aug 4, 2020
cb9960c
CMake: Do not hard code target in toolchain CMake module
hugueskamba Aug 4, 2020
dde395c
CMake: Do not hard code target in build profile CMake module
hugueskamba Aug 4, 2020
a1259ec
CMake: Remove utility function dependency on mbed-os target
hugueskamba Aug 4, 2020
933b1db
CMake: Set language std per target using properties
hugueskamba Aug 10, 2020
eb4102b
CMake: Fix failure due to BLE component dir move
hugueskamba Aug 11, 2020
fbaeae5
CMake: Fix failure due to MbedTLS rdir relocation
hugueskamba Aug 12, 2020
7343ad6
CMake: Use `mbed_` prefix for CMake functions
hugueskamba Aug 12, 2020
6687a6b
CMake: Check CMake builds CMake-capable targets in Travis
rwalton-arm Aug 13, 2020
67a2058
CMake: Fix build failure due to lora, cryptocell, and nfc dirs move
hugueskamba Aug 15, 2020
f856d6b
CMake: Fix include path for Cryptocell
0xc0170 Aug 17, 2020
01ddb7d
CMake: Fix NRF52840_DK build failure
hugueskamba Aug 17, 2020
b3c614e
CMake: Fix CORDIO_LL build failure
hugueskamba Aug 17, 2020
f12f9ad
CMake: Fix failures due to device_key and storage dirs move
hugueskamba Aug 24, 2020
14c6af1
cmake: fix sd component recent dir structure
0xc0170 Aug 25, 2020
5a1d64a
CMake: Fix blockdevice components source and include paths
0xc0170 Aug 25, 2020
0c8cb31
CMake: Fix build failure due to PSA dir move
hugueskamba Aug 25, 2020
ec376fb
CMake: List missing files in sal-stack-nanostack
hugueskamba Aug 27, 2020
3ab8179
CMake: Add support for K66F
hugueskamba Aug 27, 2020
4fc678c
CMake: Correct file listing for PSA
hugueskamba Aug 27, 2020
0ba0524
CMake: Fix selection of scatter file and startup file for DISCO_L475_…
hugueskamba Aug 27, 2020
458ce2a
Travis: add more examples we should support
0xc0170 Jul 22, 2020
a0fbe29
CMake: Fix build failure due to CMSIS restructure
hugueskamba Sep 2, 2020
3be2d15
CMake ARMClang6: use armclang for asm
0xc0170 Sep 1, 2020
4c89f67
CMake cores: fix flag mpcu for asm
0xc0170 Sep 1, 2020
0902a17
CMake ARMClang: use -masm=auto
0xc0170 Sep 3, 2020
44f9d17
CMake: Fix build due to hal dir move
hugueskamba Sep 3, 2020
8aa4a85
CMake: use CMAKE_TOOLCHAIN_FILE
0xc0170 Aug 25, 2020
e7caa89
CMake: use response files
0xc0170 Aug 13, 2020
9d1ae52
CMake: 3.18.2 minimum version set
0xc0170 Sep 4, 2020
30ec7fa
CMake: mbed_add_cmake_directory_if_labels checks presence of CMakeLis…
hugueskamba Sep 7, 2020
18cb55a
CMake: Add information about the current state of support (#13551)
0xc0170 Sep 7, 2020
9b8c5ac
CMake: Fix build failure due to mbed-trace, mbed-client-randlib, and …
hugueskamba Sep 7, 2020
1b576c3
CMake: Clean up platform
hugueskamba Sep 8, 2020
47f6148
CMake: Fix GCC_ARM pre-linking stage (#13575)
0xc0170 Sep 8, 2020
0f7d03a
CMake: Revert mbed-trace CMake input source file to match upstream re…
hugueskamba Sep 11, 2020
042e9c7
CMake: Remove TOOLCHAIN_ARM_STD dir for TARGET_STM32F439xI
hugueskamba Sep 11, 2020
e22b19d
CMake: Fix build failure due to BLE dir changes
hugueskamba Sep 11, 2020
37dd6d6
CMake: Fix ARM toolchain configuration
hugueskamba Sep 11, 2020
043cb37
CMake: Fix DISCO_L475VG_IOT01A ARM toolchain support
hugueskamba Sep 11, 2020
ae60c65
CMake: Add background and future plans to README (#13589)
hugueskamba Sep 14, 2020
cac1b25
CMake: Move modules under tools subdirectory
hugueskamba Sep 14, 2020
4ec13d7
CMake design: update to the latest version of feature-cmake branch (#…
0xc0170 Sep 16, 2020
1834579
CMake: Add support for C lib selection
hugueskamba Sep 15, 2020
3b8aba1
CMake: Add support for printf lib selection
hugueskamba Sep 15, 2020
0e257b0
CMake: Fix location of M33 exception handler source file
hugueskamba Sep 17, 2020
4c22554
CMake: Fix TFM targets build
hugueskamba Sep 17, 2020
22dd57b
CMake: Add support for NUCLEO_F401RE
hugueskamba Sep 18, 2020
d84baa8
CMake: Add a function to generate executable artifacts with memap (#1…
rajkan01 Oct 8, 2020
fa98689
CMake: Componentize Mbed OS into multiple CMake targets (#13732)
hugueskamba Oct 12, 2020
8016a53
CMake: replace usage of the mbed_add_cmake_directory_if_labels() func…
rajkan01 Oct 13, 2020
8529e88
cmake: fix present inclusion
0xc0170 Oct 14, 2020
8328963
CMake: Replace tested BLE application in CI description
hugueskamba Oct 15, 2020
662e32f
CMake: Fix travis fetch PR (#13763)
0xc0170 Oct 15, 2020
0ddc75a
CMake: Fix BLE private address linker error
hugueskamba Oct 15, 2020
448986f
CMake: remove string.h in STM32 usb, already included (#13773)
0xc0170 Oct 16, 2020
c82e8c2
CMake: Restore rtos api and netsocket presence macro names
hugueskamba Oct 16, 2020
d283e69
CMake: fix for Gcc Arm preprocessing linker file
0xc0170 Oct 15, 2020
a42ad9d
Update CMake based on new STM32L4 directory structure
rajkan01 Oct 20, 2020
e0eee75
CMake: remove TODO as it is not valid anymore
0xc0170 Oct 22, 2020
c9cacaf
CMake: fix application config
0xc0170 Oct 21, 2020
bf84a5b
CMake: Rename CMake targets
hugueskamba Oct 22, 2020
2bab2ba
CMake: Create a mbed-os alias library
hugueskamba Oct 22, 2020
d2be577
CMake: split rtos from core target
rajkan01 Oct 16, 2020
e7c0d93
CMake: add mbed-os and mbed-baremetal targets
rajkan01 Oct 26, 2020
f8a02ce
Update rtos/CMakeLists.txt
0xc0170 Oct 27, 2020
e0aa49f
CMake: Add support for NUCLEO_F303K8
hugueskamba Oct 28, 2020
7171f62
Replace PUBLIC to INTERFACE keyword
rajkan01 Oct 28, 2020
52bc5b5
CMake: fix the output bin-hex file
0xc0170 Oct 27, 2020
062bb5f
Update CMakeLists.txt
0xc0170 Oct 27, 2020
2d67c67
TEST: update example scripts for cmake
Oct 26, 2020
0bb812a
TEST: remove cmake build test from TravisCI
Oct 28, 2020
411ea55
TEST: add BLE example to cmake example json
Oct 28, 2020
c391acc
TEST: fix a bug on example scripts
Oct 28, 2020
3558a7a
restrict BLE example only build BLE_LED
Oct 28, 2020
bf552af
TEST: use mbed-tools build wrapper replace cmake build commands
Oct 29, 2020
9faeadc
CMake: ninja reponse files disabled for ARMClang on Windows
0xc0170 Oct 28, 2020
e77c532
CMake: 3.19.0 update to fix ARMClang ASM defines
0xc0170 Oct 29, 2020
7a32e42
CMake readme: update mbed-tools to 3.4
0xc0170 Oct 29, 2020
76cf2f7
Activate ccache for CMake
ladislas Oct 28, 2020
e80fa8b
CMake: Rename Mbed OS path variable for consistency
hugueskamba Nov 5, 2020
d48415c
CMake nrf52480: fix startup/linker inclusion
0xc0170 Nov 4, 2020
3fa52b9
CMake: Fix Microlib selection (#13871)
hugueskamba Nov 6, 2020
76f4953
CMake: Remove depth level argument to match map console prints the sa…
rajkan01 Nov 4, 2020
46c3596
CMake: Create separate function to set MCU core compile defintions
hugueskamba Oct 28, 2020
0bf4683
CMake: Set compile defintions for supported toolchain at top level in…
hugueskamba Oct 28, 2020
66f65c0
CMake: Fix third party toolchain file suppport
hugueskamba Oct 28, 2020
073ae1d
CMake: Validate selected application profile (#13856)
rajkan01 Nov 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ DELIVERY/

# Directory used to clone and build TF-M
features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_IGNORE/

# CMake
CMakeCache.txt
cmake_install.cmake
CMakeFiles/
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ env:

cache:
pip: true
ccache: true
directories:
- ${HOME}/.cache/deps
- ${HOME}/.ccache


before_install:
- source tools/test/travis-ci/functions.sh

addons:
apt:
packages:
- ninja-build

matrix:
include:
Expand Down Expand Up @@ -106,7 +109,6 @@ matrix:
':!*tests/*' ':!*targets/*' ':!*TARGET_*' ':!*unsupported/*' \
':!*events/tests/*' ':!*drivers/tests/*'


### Docs Tests ###
- &docs-vm
stage: "Docs"
Expand Down
249 changes: 249 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# This is the boilerplate for Mbed OS

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add an item on our backlog to only require this version if armclang is being used? I don't believe gcc needs this new of a CMake verison.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
A ticket has been added to the backlog.

Copy link
Contributor

@Patater Patater Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you link me to the ticket please? I couldn't find after a GitHub search. Thanks.


# Using relative paths behavior
if(POLICY CMP0076)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set this policy if we force the cmake version to 3.19.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create a ticket, we got some relative paths and somewhere using source dir variable. I recall we added this long time ago to suppress Cmake warning. We'll test with the current code base, to check if this can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOTOSM-2643 created

cmake_policy(SET CMP0076 NEW)
endif()

include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(${MBED_PATH}/tools/cmake/core.cmake)

add_library(mbed-core INTERFACE)

add_library(mbed-os INTERFACE)

target_link_libraries(mbed-os
INTERFACE
mbed-rtos
mbed-core
)

add_library(mbed-baremetal INTERFACE)

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")
if(NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
if("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
message(WARNING
"We noticed that target.c_lib is set to `${MBED_C_LIB}`."
" As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
" we are using the standard C library instead."
)
set(MBED_C_LIB "std" CACHE STRING "")
endif()
endif()
elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
message(FATAL_ERROR
"Invalid `target.c_lib` ('${MBED_C_LIB}') for '${MBED_TARGET}' target."
"\nPossible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS}"
)
endif()

# Validate selected printf library
set(MBED_PRINTF_LIB_TYPES std minimal-printf)
if(NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
message(FATAL_ERROR
"Invalid printf library type '${MBED_PRINTF_LIB}'. Possible values:\n ${MBED_PRINTF_LIB_TYPES}"
)
endif()

mbed_set_cpu_core_definitions(mbed-core)
if(${MBED_TOOLCHAIN_FILE_USED})
mbed_set_cpu_core_options(mbed-core ${MBED_TOOLCHAIN})
mbed_set_toolchain_options(mbed-core)
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN})
mbed_set_c_lib(mbed-core ${MBED_C_LIB})
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB})
endif()


set(MBED_TARGET_LABELS
${MBED_TARGET_LABELS} CACHE INTERNAL ""
)

target_compile_definitions(mbed-core
INTERFACE
${MBED_TARGET_DEFINITIONS}
${MBED_CONFIG_DEFINITIONS}
)

# Add compile definitions for backward compatibility with the toolchain
# supported. New source files should instead check for __GNUC__ and __clang__
# for the GCC_ARM and ARM toolchains respectively.
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_ARM
)
endif()

# Include mbed.h and config from generate folder
target_include_directories(mbed-core
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)

# These targets are made visible here so their source files which
# are spread in different directories can be referenced and can be linked against
# 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_subdirectory(cmsis)
add_subdirectory(drivers)
add_subdirectory(hal)
add_subdirectory(platform)
add_subdirectory(rtos)
add_subdirectory(targets)

# The directories below contain optional target libraries
add_subdirectory(events EXCLUDE_FROM_ALL)
add_subdirectory(connectivity EXCLUDE_FROM_ALL)
add_subdirectory(storage EXCLUDE_FROM_ALL)
add_subdirectory(drivers/device_key EXCLUDE_FROM_ALL)
add_subdirectory(drivers/source/usb EXCLUDE_FROM_ALL)
add_subdirectory(features EXCLUDE_FROM_ALL)
add_subdirectory(platform/FEATURE_EXPERIMENTAL_API EXCLUDE_FROM_ALL)
add_subdirectory(cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL)
add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)

#
# Configures the application
#
function(mbed_configure_app_target target)
mbed_set_language_standard(${target})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just use target_compile_features(cxx_std_xx) here?

Copy link
Contributor

@rajkan01 rajkan01 Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in PR #13870

endfunction()

#
# Specifies linker script used for linking `target`.
#
function(mbed_set_mbed_target_linker_script target)
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions)
set(CMAKE_PRE_BUILD_COMMAND
COMMAND "arm-none-eabi-cpp" ${_linker_preprocess_definitions} -x assembler-with-cpp -E -Wp,-P
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS "${CMAKE_BINARY_DIR}/${target}.link_script.ld"
)
elseif(MBED_TOOLCHAIN STREQUAL "ARM")
set(CMAKE_PRE_BUILD_COMMAND COMMAND "")
target_link_options(mbed-core
INTERFACE
"--scatter=${mbed_target_linker_script}"
)
endif()
add_custom_command(
TARGET
${target}
PRE_LINK
${CMAKE_PRE_BUILD_COMMAND}
COMMENT
"Link line:"
VERBATIM
)
endfunction()

#
# Converts output file of `target` to binary file and to Intel HEX file.
#
function(mbed_generate_bin_hex target)
get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN)
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
set(CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_BINARY_DIR}/${target}.bin
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_BINARY_DIR}/${target}.bin"
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_BINARY_DIR}/${target}.hex
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_BINARY_DIR}/${target}.hex"
)
elseif(MBED_TOOLCHAIN STREQUAL "ARM")
get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER)
set(CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_BINARY_DIR}/${target}.bin $<TARGET_FILE:${target}>
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_BINARY_DIR}/${target}.bin"
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_BINARY_DIR}/${target}.hex $<TARGET_FILE:${target}>
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_BINARY_DIR}/${target}.hex"
)
endif()
add_custom_command(
TARGET
${target}
POST_BUILD
${CMAKE_POST_BUILD_COMMAND}
COMMENT
"executable:"
VERBATIM
)
endfunction()

#
# Parse toolchain generated map file of `target` and display a readable table format.
#
function(mbed_generate_map_file target)
find_package (Python3)
add_custom_command(
TARGET
${target}
POST_BUILD
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/tools/memap.py -t ${MBED_TOOLCHAIN} ${CMAKE_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
COMMENT
"Displaying memory map for ${target}"
)
endfunction()

#
# Validate selected application profile.
#
function(mbed_validate_application_profile target)
get_target_property(app_link_libraries ${target} LINK_LIBRARIES)
string(FIND "${app_link_libraries}" "mbed-baremetal" string_found_position)
if(${string_found_position} GREATER_EQUAL 0)
if(NOT "bare-metal" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES)
message(FATAL_ERROR
"Use full profile as baremetal profile is not supported for this Mbed target")
endif()
elseif(NOT "full" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES)
message(FATAL_ERROR
"The full profile is not supported for this Mbed target")
endif()
endfunction()

#
# Set post build operations
#
function(mbed_set_post_build target)
mbed_validate_application_profile(${target})
mbed_generate_bin_hex(${target})
mbed_generate_map_file(${target})
endfunction()

# Ninja requires to be forced for response files
if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
# known issue ARMClang and Ninja with response files for windows
# https://gitlab.kitware.com/cmake/cmake/-/issues/21093
if(NOT (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows" AND CMAKE_CXX_COMPILER_ID MATCHES "ARMClang"))
set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "")
endif()
endif()
9 changes: 9 additions & 0 deletions cmsis/CMSIS_5/CMSIS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

if("CORTEX_A" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_CORTEX_A)
elseif("CORTEX_M" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_CORTEX_M)
endif()

15 changes: 15 additions & 0 deletions cmsis/CMSIS_5/CMSIS/RTOS2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(RTX)

target_include_directories(mbed-rtos
INTERFACE
Include
)

target_sources(mbed-rtos
INTERFACE
Source/os_systick.c
Source/os_tick_ptim.c
)
74 changes: 74 additions & 0 deletions cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

function(_mbed_get_cortex_m_exception_handlers toolchain_dir)
foreach(key ${MBED_TARGET_LABELS})
if(${key} STREQUAL CORTEX_A)
set(STARTUP_RTX_FILE TARGET_CORTEX_A/irq_ca.S)
elseif(${key} STREQUAL M0)
set(STARTUP_RTX_FILE TARGET_M0/irq_cm0.S)
elseif(${key} STREQUAL M0P)
set(STARTUP_RTX_FILE TARGET_M0P/irq_cm0.S)
elseif(${key} STREQUAL M23)
set(STARTUP_RTX_FILE TARGET_M23/irq_armv8mbl.S)
elseif(${key} STREQUAL M3)
set(STARTUP_RTX_FILE TARGET_M3/irq_cm3.S)
elseif(${key} STREQUAL M33)
set(STARTUP_RTX_FILE TARGET_M33/irq_armv8mml.S)
elseif(${key} STREQUAL RTOS_M4_M7)
set(STARTUP_RTX_FILE TARGET_RTOS_M4_M7/irq_cm4f.S)
endif()

target_sources(mbed-rtos
INTERFACE
Source/${toolchain_dir}/${STARTUP_RTX_FILE}
)
endforeach()
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)
endif()
endforeach()
endfunction()

_mbed_get_cortex_a_exception_handlers()

if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_GCC)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_ARM)
elseif(${MBED_TOOLCHAIN} STREQUAL "IAR")
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_IAR)
endif()

target_include_directories(mbed-rtos
INTERFACE
Config
Include
Include1
Source
)

target_sources(mbed-rtos
INTERFACE
Config/RTX_Config.c

Library/cmsis_os1.c

Source/rtx_delay.c
Source/rtx_evflags.c
Source/rtx_evr.c
Source/rtx_kernel.c
Source/rtx_lib.c
Source/rtx_memory.c
Source/rtx_mempool.c
Source/rtx_msgqueue.c
Source/rtx_mutex.c
Source/rtx_semaphore.c
Source/rtx_system.c
Source/rtx_thread.c
Source/rtx_timer.c
)
Loading