Skip to content

Commit 9ec92f1

Browse files
authored
Merge pull request #14874 from LDong-Arm/optional_MBED_TEST_LINK_LIBRARIES
CMake: Replace `MBED_TEST_LINK_LIBRARIES` with `MBED_TEST_BAREMETAL`
2 parents 8d3fc33 + f4d551e commit 9ec92f1

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
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/app.cmake

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@ include(CheckPythonPackage)
3434
# Check python packages from requirements.txt
3535
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/requirements.txt PYTHON_REQUIREMENTS)
3636
foreach(REQUIREMENT ${PYTHON_REQUIREMENTS})
37-
# Look for a string from the start of each line that does not contain "<", ">", "=", or " ".
38-
if(REQUIREMENT MATCHES "^([^<>= ]+)")
39-
set(PACKAGE_NAME ${CMAKE_MATCH_1})
40-
string(TOUPPER ${PACKAGE_NAME} PACKAGE_NAME_UCASE) # Ucase name needed for CMake variable
41-
string(TOLOWER ${PACKAGE_NAME} PACKAGE_NAME_LCASE) # Lcase name needed for import statement
42-
43-
check_python_package(${PACKAGE_NAME_LCASE} HAVE_PYTHON_${PACKAGE_NAME_UCASE})
44-
if(NOT HAVE_PYTHON_${PACKAGE_NAME_UCASE})
45-
message(WARNING "Missing Python dependency ${PACKAGE_NAME}")
46-
endif()
47-
else()
48-
message(FATAL_ERROR "Cannot parse line \"${REQUIREMENT}\" in requirements.txt")
49-
endif()
37+
# Look for a string from the start of each line that does not contain "<", ">", "=", or " ".
38+
if(REQUIREMENT MATCHES "^([^<>= ]+)")
39+
set(PACKAGE_NAME ${CMAKE_MATCH_1})
40+
string(TOUPPER ${PACKAGE_NAME} PACKAGE_NAME_UCASE) # Ucase name needed for CMake variable
41+
string(TOLOWER ${PACKAGE_NAME} PACKAGE_NAME_LCASE) # Lcase name needed for import statement
42+
43+
check_python_package(${PACKAGE_NAME_LCASE} HAVE_PYTHON_${PACKAGE_NAME_UCASE})
44+
if(NOT HAVE_PYTHON_${PACKAGE_NAME_UCASE})
45+
message(WARNING "Missing Python dependency ${PACKAGE_NAME}")
46+
endif()
47+
else()
48+
message(FATAL_ERROR "Cannot parse line \"${REQUIREMENT}\" in requirements.txt")
49+
endif()
5050

5151
endforeach()
5252

5353
# Check deps for memap
5454
if(Python3_FOUND AND HAVE_PYTHON_INTELHEX AND HAVE_PYTHON_PRETTYTABLE)
55-
set(HAVE_MEMAP_DEPS TRUE)
55+
set(HAVE_MEMAP_DEPS TRUE)
5656
else()
57-
set(HAVE_MEMAP_DEPS FALSE)
58-
message(STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed")
57+
set(HAVE_MEMAP_DEPS FALSE)
58+
message(STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed")
5959
endif()
6060

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)