Skip to content

Commit da34eec

Browse files
authored
Merge pull request ARMmbed#14247 from rajkan01/refactor_greentea_cmakelist
CMake: Refactor Greentea test CMakeLists.txt
2 parents 34627b7 + c93901a commit da34eec

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

tools/cmake/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,24 @@ $ mbedtools configure -t <TOOLCHAIN> -m <MBED_TARGET>
9494
```
9595
* Copy `.mbedbuild/` into the test suite directory.
9696
* Set your current directory to the test suite directory
97+
98+
* 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.
99+
100+
For example:
101+
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.
102+
97103
* Run the following command to build the test binary with the full profile
98104
99105
```
100-
touch mbed-os.lib && mkdir cmake_build && cd cmake_build && cmake .. -G Ninja && cmake --build .
106+
mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-os && cmake --build .
101107
```
102108
* Run the following command to build the test binary with the baremetal profile
103109
```
104-
touch mbed-os.lib && mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -DMBED_BAREMETAL_GREENTEA_TEST=ON && cmake --build .
110+
mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal && cmake --build .
111+
```
112+
* Run the following command to build the test binary with the full profile and XYZ library
113+
```
114+
mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -D"MBED_TEST_LINK_LIBRARIES=mbed-os XYZ" && cmake --build .
105115
```
106116
107117
Notes:

tools/cmake/mbed_greentea.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,17 @@ macro(mbed_greentea_add_test)
5555
${MBED_GREENTEA_TEST_SOURCES}
5656
)
5757

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

6471
target_link_libraries(${TEST_NAME}

0 commit comments

Comments
 (0)