Skip to content

Commit f4d551e

Browse files
committed
CMake: Replace MBED_TEST_LINK_LIBRARIES with MBED_TEST_BAREMETAL
Currently we have `MBED_TEST_LINK_LIBRARIES` for specifying * Whether to link `mbed-os` or `mbed-baremetal` * Any additional libraries we want tests to link It's not fit for purpose anymore, because * No flavor of Mbed OS is selected by default, but we should've really defaulted to `mbed-os`, the full RTOS version. Build doesn't work unless `-DMBED_TEST_LINK_LIBRARIES=<...>` is passed, which is redundant. * A test should never need additional libraries passed via command line - its `CMakeLists.txt` should specify what it links. This commit replaces `MBED_TEST_LINK_LIBRARIES` with a new option `MBED_TEST_BAREMETAL` to build a test with either RTOS (default) or without it (by passing `-DMBED_TEST_BAREMETAL=ON`).
1 parent 2a1d50f commit f4d551e

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

tools/cmake/README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,17 @@ cmake -S <source-dir> -B <build-dir> -DCMAKE_BUILD_TYPE=debug
8787
Install prerequisites suggested in the previous section and follow the below steps to build:
8888
* Set your current directory to the test suite directory
8989
90-
* CMake `MBED_TEST_LINK_LIBRARIES` command-line argument config must be passed either `mbed-os` or `mbed-baremetal` when you are building a greentea test. In addition to that, you must pass any extra library along if that library source is not maintained as part of mbed os source tree.
91-
92-
For example:
93-
kvstore greentea test is dependent on `mbed-storage` and `mbed-storage-filesystemstore` library however you don't need to pass it via `MBED_TEST_LINK_LIBRARIES` as it is already target linked in greentea test CMakeLists.txt, at the same time some libraries and test cases are private to the application and if you want to use it with kvstore test then pass it with `MBED_TEST_LINK_LIBRARIES` command-line argument.
9490
* Run the following command for the configuration CMake module to be generated
9591
```
9692
mbedtools configure -t <TOOLCHAIN> -m <MBED_TARGET> --mbed-os-path /path/to/mbed-os
9793
```
9894
* Build the test binary with the full profile
9995
```
100-
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-os && cmake --build .
101-
```
102-
To build the test binary with the baremetal profile
103-
```
104-
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal && cmake --build .
96+
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja && cmake --build .
10597
```
106-
To build the test binary with the full profile and a "XYZ" library
98+
Or build the test binary with the baremetal profile
10799
```
108-
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -D"MBED_TEST_LINK_LIBRARIES=mbed-os XYZ" && cmake --build .
100+
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_BAREMETAL=ON && cmake --build .
109101
```
110102
111103
Notes:

tools/cmake/mbed_greentea.cmake

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
4+
option(MBED_TEST_BAREMETAL OFF)
5+
36
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
47

58
include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
@@ -52,19 +55,14 @@ macro(mbed_greentea_add_test)
5255
${MBED_GREENTEA_TEST_SOURCES}
5356
)
5457

55-
# The CMake MBED_TEST_LINK_LIBRARIES command-line argument is to get greentea test all dependent libraries.
56-
# For example:
57-
# - To select mbed-os library, use cmake with -DMBED_TEST_LINK_LIBRARIES=mbed-os
58-
# - To select baremetal library, use cmake with -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal
59-
# - To select baremetal with extra external error logging library to the test, use cmake with
60-
# -D "MBED_TEST_LINK_LIBRARIES=mbed-baremetal ext-errorlogging"
61-
if (DEFINED MBED_TEST_LINK_LIBRARIES)
62-
separate_arguments(MBED_TEST_LINK_LIBRARIES)
63-
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS ${MBED_TEST_LINK_LIBRARIES} mbed-greentea)
58+
if(MBED_TEST_BAREMETAL)
59+
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal)
6460
else()
65-
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-greentea)
61+
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os)
6662
endif()
6763

64+
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-greentea)
65+
6866
target_link_libraries(${MBED_GREENTEA_TEST_NAME}
6967
PRIVATE
7068
${MBED_GREENTEA_TEST_REQUIRED_LIBS}

0 commit comments

Comments
 (0)