-
Notifications
You must be signed in to change notification settings - Fork 3k
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
CMake: Add initial support #13566
Changes from all commits
52dd933
f4e4012
6dc5f5a
d836489
311b2ca
59a7d77
8408289
a63fa60
1d6f86f
8f9bf40
929adbe
5c453e5
a08be8c
70d9229
8a74bf1
30e8886
53d7128
5709dd2
554a5d3
b78ef7a
71c48e0
6b5ef8a
915d552
f18622e
10f4212
f0072e7
8dabb28
bd45acb
b03e94f
e2f38ab
08eb1e3
1bb6be3
7dd7337
debffb6
e172eb3
2d1508d
4b13332
396ddc7
0e1770d
335dfdd
ecfee28
8b21238
3952212
24c79a4
2efe469
d3d88e3
5128b02
67c364d
fa8d9fd
c05170f
ef11e06
06f4e1b
100be3d
1b52415
4af48a3
42cd929
4f8568c
2f89e99
18a1380
894f8cc
02c0154
90e5d3a
1ebedf2
57f39ae
aac5e80
8b3cec2
e744208
c876bc1
76fd50a
5f53181
f1a3d69
c1fa350
c30d925
de3462d
20e19de
400211c
c8b4822
cb9960c
dde395c
a1259ec
933b1db
eb4102b
fbaeae5
7343ad6
6687a6b
67a2058
f856d6b
01ddb7d
b3c614e
f12f9ad
14c6af1
5a1d64a
0c8cb31
ec376fb
3ab8179
4fc678c
0ba0524
458ce2a
a0fbe29
3be2d15
4c89f67
0902a17
44f9d17
8aa4a85
e7caa89
9d1ae52
30ec7fa
18cb55a
9b8c5ac
1b576c3
47f6148
0f7d03a
042e9c7
e22b19d
37dd6d6
043cb37
ae60c65
cac1b25
4ec13d7
1834579
3b8aba1
0e257b0
4c22554
22dd57b
d84baa8
fa98689
8016a53
8529e88
8328963
662e32f
0ddc75a
448986f
c82e8c2
d283e69
a42ad9d
e0eee75
c9cacaf
bf84a5b
2bab2ba
d2be577
e7c0d93
f8a02ce
e0aa49f
7171f62
52bc5b5
062bb5f
2d67c67
0bb812a
411ea55
c391acc
3558a7a
bf552af
9faeadc
e77c532
7a32e42
76cf2f7
e80fa8b
d48415c
3fa52b9
76f4953
46c3596
0bf4683
66f65c0
073ae1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
||
# Using relative paths behavior | ||
if(POLICY CMP0076) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
hugueskamba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
add_library(mbed-os INTERFACE) | ||
hugueskamba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't we just use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
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() | ||
|
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 | ||
) |
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 | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.