2020-07-23 13:13:14 +00:00
|
|
|
# Copyright (c) 2020 ARM Limited. All rights reserved.
|
2020-07-20 16:52:23 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2020-07-23 19:23:56 +00:00
|
|
|
# This is the boilerplate for Mbed OS
|
2020-07-20 16:52:23 +00:00
|
|
|
|
2020-07-27 10:24:30 +00:00
|
|
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
2020-07-20 16:52:23 +00:00
|
|
|
|
|
|
|
# Using relative paths behavior
|
|
|
|
if(POLICY CMP0076)
|
|
|
|
cmake_policy(SET CMP0076 NEW)
|
|
|
|
endif()
|
|
|
|
|
2020-07-30 11:51:46 +00:00
|
|
|
# Create Mbed OS library
|
|
|
|
add_library(mbed-os OBJECT)
|
|
|
|
|
|
|
|
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
|
2020-08-04 18:23:25 +00:00
|
|
|
|
2020-07-30 11:51:46 +00:00
|
|
|
include(${MBED_ROOT}/cmake/core.cmake)
|
2020-08-04 18:23:25 +00:00
|
|
|
mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN})
|
|
|
|
|
2020-07-31 17:39:57 +00:00
|
|
|
include(${MBED_ROOT}/cmake/toolchain.cmake)
|
2020-08-04 18:34:31 +00:00
|
|
|
mbed_set_toolchain_options(mbed-os)
|
2020-08-10 09:42:22 +00:00
|
|
|
mbed_set_language_standard(mbed-os)
|
2020-08-04 18:23:25 +00:00
|
|
|
|
2020-07-30 11:51:46 +00:00
|
|
|
include(${MBED_ROOT}/cmake/profile.cmake)
|
2020-08-04 18:38:17 +00:00
|
|
|
mbed_set_profile_options(mbed-os ${MBED_TOOLCHAIN})
|
2020-08-04 18:23:25 +00:00
|
|
|
|
2020-07-30 11:51:46 +00:00
|
|
|
include(${MBED_ROOT}/cmake/util.cmake)
|
|
|
|
|
2020-08-06 15:41:48 +00:00
|
|
|
set_target_properties(mbed-os
|
|
|
|
PROPERTIES
|
|
|
|
MBED_TARGET_LABELS "${MBED_TARGET_LABELS}"
|
|
|
|
)
|
|
|
|
|
|
|
|
target_compile_definitions(mbed-os
|
|
|
|
PUBLIC
|
|
|
|
${MBED_TARGET_DEFINITIONS}
|
|
|
|
${MBED_CONFIG_DEFINITIONS}
|
|
|
|
)
|
2020-07-30 11:51:46 +00:00
|
|
|
|
2020-07-20 16:52:23 +00:00
|
|
|
# Include mbed.h and config from generate folder
|
2020-08-06 15:41:48 +00:00
|
|
|
target_include_directories(mbed-os
|
|
|
|
PUBLIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
)
|
2020-07-20 16:52:23 +00:00
|
|
|
|
|
|
|
# Default build
|
|
|
|
add_subdirectory(cmsis)
|
|
|
|
add_subdirectory(components)
|
|
|
|
add_subdirectory(connectivity)
|
|
|
|
add_subdirectory(drivers)
|
|
|
|
add_subdirectory(events)
|
|
|
|
add_subdirectory(features)
|
|
|
|
add_subdirectory(hal)
|
|
|
|
add_subdirectory(platform)
|
|
|
|
add_subdirectory(rtos)
|
|
|
|
add_subdirectory(storage)
|
|
|
|
add_subdirectory(targets)
|
2020-07-30 11:51:46 +00:00
|
|
|
|
|
|
|
|
2020-08-10 09:42:22 +00:00
|
|
|
#
|
|
|
|
# Configures the application
|
|
|
|
#
|
2020-08-12 12:11:16 +00:00
|
|
|
function(mbed_configure_app_target target)
|
2020-08-10 09:42:22 +00:00
|
|
|
mbed_set_language_standard(${target})
|
|
|
|
endfunction()
|
|
|
|
|
2020-07-30 15:42:41 +00:00
|
|
|
#
|
|
|
|
# Specifies linker script used for linking `target`.
|
|
|
|
#
|
2020-08-12 12:11:16 +00:00
|
|
|
function(mbed_set_mbed_target_linker_script target)
|
2020-07-30 15:42:41 +00:00
|
|
|
get_property(mbed_target_startup GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
|
2020-07-30 11:51:46 +00:00
|
|
|
|
2020-07-30 15:42:41 +00:00
|
|
|
# TODO: @mbed-os-tools This pre-build commands should get details from target + profile.
|
|
|
|
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
|
|
|
|
set(CMAKE_PRE_BUILD_COMMAND
|
|
|
|
COMMAND "arm-none-eabi-cpp" -E -P
|
|
|
|
-Wl,--gc-sections -Wl,--wrap,main -Wl,--wrap,_malloc_r -Wl,--wrap,_free_r
|
|
|
|
-Wl,--wrap,_realloc_r -Wl,--wrap,_memalign_r -Wl,--wrap,_calloc_r
|
|
|
|
-Wl,--wrap,exit -Wl,--wrap,atexit -Wl,-n
|
|
|
|
-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
|
|
|
|
-DMBED_ROM_START=0x0 -DMBED_ROM_SIZE=0x100000 -DMBED_RAM_START=0x20000000
|
|
|
|
-DMBED_RAM_SIZE=0x30000 -DMBED_RAM1_START=0x1fff0000
|
|
|
|
-DMBED_RAM1_SIZE=0x10000 -DMBED_BOOT_STACK_SIZE=1024
|
|
|
|
-DXIP_ENABLE=0
|
|
|
|
${mbed_target_startup} -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-os
|
|
|
|
PUBLIC
|
|
|
|
"--scatter=${mbed_target_startup}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
add_custom_command(
|
|
|
|
TARGET
|
|
|
|
${target}
|
|
|
|
PRE_LINK
|
|
|
|
${CMAKE_PRE_BUILD_COMMAND}
|
|
|
|
COMMENT
|
|
|
|
"Link line:"
|
|
|
|
VERBATIM
|
2020-07-30 11:51:46 +00:00
|
|
|
)
|
2020-07-30 15:42:41 +00:00
|
|
|
endfunction()
|
2020-07-30 11:51:46 +00:00
|
|
|
|
2020-07-30 15:42:41 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Converts output file of `target` to binary file and to Intel HEX file.
|
|
|
|
#
|
2020-08-12 12:11:16 +00:00
|
|
|
function(mbed_generate_bin_hex target)
|
2020-07-30 15:42:41 +00:00
|
|
|
get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN)
|
|
|
|
# TODO: @mbed-os-tools This post-build commands should get details from target + profile.
|
|
|
|
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
|
|
|
|
set(CMAKE_POST_BUILD_COMMAND
|
|
|
|
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> $<TARGET_FILE:${target}>.bin
|
2020-08-10 10:44:45 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "-- built: $<TARGET_FILE:${target}>.bin"
|
2020-07-30 15:42:41 +00:00
|
|
|
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> $<TARGET_FILE:${target}>.hex
|
2020-08-10 10:44:45 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "-- built: $<TARGET_FILE:${target}>.hex"
|
2020-07-30 15:42:41 +00:00
|
|
|
)
|
|
|
|
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 $<TARGET_FILE:${target}>.bin $<TARGET_FILE:${target}>
|
2020-08-10 10:44:45 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "-- built: $<TARGET_FILE:${target}>.bin"
|
2020-07-30 15:42:41 +00:00
|
|
|
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o $<TARGET_FILE:${target}>.hex $<TARGET_FILE:${target}>
|
2020-08-10 10:44:45 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "-- built: $<TARGET_FILE:${target}>.hex"
|
2020-07-30 15:42:41 +00:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
add_custom_command(
|
|
|
|
TARGET
|
|
|
|
${target}
|
|
|
|
POST_BUILD
|
|
|
|
${CMAKE_POST_BUILD_COMMAND}
|
|
|
|
COMMENT
|
|
|
|
"executable:"
|
|
|
|
VERBATIM
|
|
|
|
)
|
|
|
|
endfunction()
|