Skip to content

Commit ae31d20

Browse files
authored
Merge branch 'master' into master
2 parents 6318e3a + 77927d0 commit ae31d20

File tree

478 files changed

+20701
-10832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

478 files changed

+20701
-10832
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ DELIVERY/
102102
CMakeCache.txt
103103
cmake_install.cmake
104104
CMakeFiles/
105+
cmake_build/
106+
Testing/

.travis.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ addons:
3939
- sourceline: 'deb https://apt.kitware.com/ubuntu/ focal main'
4040
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
4141
packages:
42-
- cmake
43-
- ninja-build
44-
- libncursesw5
42+
- cmake
43+
- ninja-build
44+
- gcovr
45+
- libncursesw5
46+
- g++-7
4547

4648
matrix:
4749
include:
@@ -321,3 +323,23 @@ matrix:
321323
- mbedtools configure -p ${ROOT} -t ${TOOLCHAIN} -m ${TARGET_NAME} --mbed-os-path .
322324
- cmake -S ${ROOT} -B ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/ -GNinja -DCMAKE_BUILD_TYPE=${PROFILE}
323325
- cmake --build ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/
326+
327+
### Mbed OS unittest ###
328+
- &cmake-build-run-unittest
329+
stage: "CMake"
330+
name: "CMake unittest build"
331+
env: NAME=cmake_unittest
332+
install:
333+
# Hide Travis-preinstalled CMake
334+
# The Travis-preinstalled CMake is unfortunately not installed via apt, so we
335+
# can't replace it with an apt-supplied version very easily. Additionally, we
336+
# can't permit the Travis-preinstalled copy to survive, as the Travis default
337+
# path lists the Travis CMake install location ahead of any place where apt
338+
# would install CMake to. Instead of apt removing or upgrading to a new CMake
339+
# version, we must instead delete the Travis copy of CMake.
340+
- sudo rm -rf /usr/local/cmake*
341+
script:
342+
- echo ctest --build-and-test . build --build-generator Ninja --build-options -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON -DCMAKE_CXX_COMPILER=g++-7 -DCMAKE_C_COMPILER=gcc-7 --test-command ctest
343+
- ctest --build-and-test . build --build-generator Ninja --build-options -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON -DCMAKE_CXX_COMPILER=g++-7 -DCMAKE_C_COMPILER=gcc-7 --test-command ctest
344+
- gcovr --gcov-executable gcov-7 -r . ./build -s -e ".*\.h" --exclude-directories=$TRAVIS_BUILD_DIR/build/UNITTESTS --exclude-directories=$TRAVIS_BUILD_DIR/build/_deps
345+
- ccache -s

CMakeLists.txt

Lines changed: 99 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
77

8-
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
9-
include(mbed_set_linker_script)
8+
if(${CMAKE_CROSSCOMPILING})
9+
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
10+
include(mbed_set_linker_script)
11+
endif()
1012

1113
project(mbed-os)
1214

@@ -15,6 +17,13 @@ list(APPEND CMAKE_MODULE_PATH
1517
"${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_Cypress/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NXP/scripts"
1618
)
1719

20+
option(BUILD_TESTING "Run unit tests only." OFF)
21+
22+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
23+
include(CTest)
24+
add_subdirectory(UNITTESTS)
25+
endif()
26+
1827
add_library(mbed-core INTERFACE)
1928

2029
add_library(mbed-os INTERFACE)
@@ -33,88 +42,91 @@ target_link_libraries(mbed-baremetal
3342
)
3443
# Validate selected C library type
3544
# The C library type selected has to match the library that the target can support
36-
if(${MBED_C_LIB} STREQUAL "small")
37-
if(NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
38-
if("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
39-
message(WARNING
40-
"We noticed that target.c_lib is set to `${MBED_C_LIB}`."
41-
" As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
42-
" we are using the standard C library instead."
43-
)
44-
set(MBED_C_LIB "std" CACHE STRING "")
45+
if(${CMAKE_CROSSCOMPILING})
46+
if(${MBED_C_LIB} STREQUAL "small")
47+
if(NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
48+
if("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
49+
message(WARNING
50+
"We noticed that target.c_lib is set to `${MBED_C_LIB}`."
51+
" As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
52+
" we are using the standard C library instead."
53+
)
54+
set(MBED_C_LIB "std" CACHE STRING "")
55+
endif()
4556
endif()
57+
elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
58+
message(FATAL_ERROR
59+
"Invalid `target.c_lib` ('${MBED_C_LIB}') for '${MBED_TARGET}' target."
60+
"\nPossible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS}"
61+
)
4662
endif()
47-
elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
48-
message(FATAL_ERROR
49-
"Invalid `target.c_lib` ('${MBED_C_LIB}') for '${MBED_TARGET}' target."
50-
"\nPossible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS}"
51-
)
52-
endif()
5363

54-
# Validate selected printf library
55-
set(MBED_PRINTF_LIB_TYPES std minimal-printf)
56-
if(NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
57-
message(FATAL_ERROR
58-
"Invalid printf library type '${MBED_PRINTF_LIB}'. Possible values:\n ${MBED_PRINTF_LIB_TYPES}"
59-
)
60-
endif()
61-
62-
mbed_set_cpu_core_definitions(mbed-core)
63-
if(${MBED_TOOLCHAIN_FILE_USED})
64-
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN})
65-
mbed_set_c_lib(mbed-core ${MBED_C_LIB})
66-
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB})
64+
# Validate selected printf library
65+
set(MBED_PRINTF_LIB_TYPES std minimal-printf)
66+
if(NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
67+
message(FATAL_ERROR
68+
"Invalid printf library type '${MBED_PRINTF_LIB}'. Possible values:\n ${MBED_PRINTF_LIB_TYPES}"
69+
)
70+
endif()
71+
72+
mbed_set_cpu_core_definitions(mbed-core)
73+
if(${MBED_TOOLCHAIN_FILE_USED})
74+
message(STATUS ${MBED_TOOLCHAIN})
75+
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN})
76+
mbed_set_c_lib(mbed-core ${MBED_C_LIB})
77+
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB})
78+
79+
target_compile_features(mbed-core
80+
INTERFACE
81+
c_std_11
82+
cxx_std_14
83+
)
84+
85+
endif()
6786

68-
target_compile_features(mbed-core
87+
target_compile_definitions(mbed-core
6988
INTERFACE
70-
c_std_11
71-
cxx_std_14
89+
${MBED_TARGET_DEFINITIONS}
90+
${MBED_CONFIG_DEFINITIONS}
7291
)
7392

74-
endif()
75-
76-
target_compile_definitions(mbed-core
77-
INTERFACE
78-
${MBED_TARGET_DEFINITIONS}
79-
${MBED_CONFIG_DEFINITIONS}
80-
)
81-
82-
# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
83-
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
84-
target_compile_definitions(${PROJECT_NAME}
85-
PUBLIC
86-
MBED_TEST_MODE
87-
)
88-
endif()
93+
# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
94+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
95+
target_compile_definitions(${PROJECT_NAME}
96+
PUBLIC
97+
MBED_TEST_MODE
98+
)
99+
endif()
89100

90-
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
91-
# script, because of path length limitations on Windows. We set the response file and bind the path
92-
# to a global property here. The MBED_TARGET being built queries this global property when it sets
93-
# the linker script.
94-
#
95-
# We must set this global property before the targets subdirectory is added to the project. This is
96-
# required because the MBED_TARGET depends on the response file. If the path to the response file
97-
# is not defined when the target requests it the config definitions will not be passed to CPP.
98-
#
99-
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
100-
# using response files or global properties.
101-
mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH)
102-
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH})
103-
104-
# Add compile definitions for backward compatibility with the toolchain
105-
# supported. New source files should instead check for __GNUC__ and __clang__
106-
# for the GCC_ARM and ARM toolchains respectively.
107-
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
108-
target_compile_definitions(mbed-core
109-
INTERFACE
110-
TOOLCHAIN_GCC_ARM
111-
TOOLCHAIN_GCC
112-
)
113-
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
114-
target_compile_definitions(mbed-core
115-
INTERFACE
116-
TOOLCHAIN_ARM
117-
)
101+
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
102+
# script, because of path le ngth limitations on Windows. We set the response file and bind the path
103+
# to a global property here. The MBED_TARGET being built queries this global property when it sets
104+
# the linker script.
105+
#
106+
# We must set this global property before the targets subdirectory is added to the project. This is
107+
# required because the MBED_TARGET depends on the response file. If the path to the response file
108+
# is not defined when the target requests it the config definitions will not be passed to CPP.
109+
#
110+
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
111+
# using response files or global properties.
112+
mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH)
113+
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH})
114+
115+
# Add compile definitions for backward compatibility with the toolchain
116+
# supported. New source files should instead check for __GNUC__ and __clang__
117+
# for the GCC_ARM and ARM toolchains respectively.
118+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
119+
target_compile_definitions(mbed-core
120+
INTERFACE
121+
TOOLCHAIN_GCC_ARM
122+
TOOLCHAIN_GCC
123+
)
124+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
125+
target_compile_definitions(mbed-core
126+
INTERFACE
127+
TOOLCHAIN_ARM
128+
)
129+
endif()
118130
endif()
119131

120132
# Include mbed.h and config from generate folder
@@ -136,23 +148,26 @@ add_subdirectory(hal)
136148
add_subdirectory(platform)
137149
add_subdirectory(rtos)
138150
add_subdirectory(targets)
151+
add_subdirectory(storage)
152+
add_subdirectory(events)
153+
add_subdirectory(connectivity)
139154

140155
# The directories below contain optional target libraries
141-
add_subdirectory(events EXCLUDE_FROM_ALL)
142-
add_subdirectory(connectivity EXCLUDE_FROM_ALL)
143-
add_subdirectory(storage EXCLUDE_FROM_ALL)
144156
add_subdirectory(drivers/device_key EXCLUDE_FROM_ALL)
145157
add_subdirectory(drivers/usb EXCLUDE_FROM_ALL)
146158
add_subdirectory(features EXCLUDE_FROM_ALL)
147159
add_subdirectory(cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL)
148160
add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
149161

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

155-
target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
163+
if(${CMAKE_CROSSCOMPILING})
164+
# Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
165+
string(TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED)
166+
string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED})
167+
string(PREPEND MBED_TARGET_CONVERTED "mbed-")
168+
169+
target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
170+
endif()
156171

157172
#
158173
# Converts output file of `target` to binary file and to Intel HEX file.

TESTS/configs/baremetal.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"storage_filesystem",
1919
"storage_tdb_external",
2020
"fat_chan",
21+
"cordio-stm32wb",
2122
"lora",
2223
"sx1276-lora-driver",
2324
"stm32wl-lora-driver",

0 commit comments

Comments
 (0)