Merge pull request #14874 from LDong-Arm/optional_MBED_TEST_LINK_LIBRARIES

CMake: Replace `MBED_TEST_LINK_LIBRARIES` with `MBED_TEST_BAREMETAL`
pull/14887/head
Jaeden Amero 2021-07-06 16:42:25 +01:00 committed by GitHub
commit 9ec92f1486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 36 deletions

View File

@ -87,25 +87,17 @@ cmake -S <source-dir> -B <build-dir> -DCMAKE_BUILD_TYPE=debug
Install prerequisites suggested in the previous section and follow the below steps to build:
* Set your current directory to the test suite directory
* 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.
For example:
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.
* Run the following command for the configuration CMake module to be generated
```
mbedtools configure -t <TOOLCHAIN> -m <MBED_TARGET> --mbed-os-path /path/to/mbed-os
```
* Build the test binary with the full profile
```
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-os && cmake --build .
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja && cmake --build .
```
To build the test binary with the baremetal profile
Or build the test binary with the baremetal profile
```
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal && cmake --build .
```
To build the test binary with the full profile and a "XYZ" library
```
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -D"MBED_TEST_LINK_LIBRARIES=mbed-os XYZ" && cmake --build .
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_BAREMETAL=ON && cmake --build .
```
Notes:

View File

@ -34,27 +34,27 @@ include(CheckPythonPackage)
# Check python packages from requirements.txt
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/requirements.txt PYTHON_REQUIREMENTS)
foreach(REQUIREMENT ${PYTHON_REQUIREMENTS})
# Look for a string from the start of each line that does not contain "<", ">", "=", or " ".
if(REQUIREMENT MATCHES "^([^<>= ]+)")
set(PACKAGE_NAME ${CMAKE_MATCH_1})
string(TOUPPER ${PACKAGE_NAME} PACKAGE_NAME_UCASE) # Ucase name needed for CMake variable
string(TOLOWER ${PACKAGE_NAME} PACKAGE_NAME_LCASE) # Lcase name needed for import statement
# Look for a string from the start of each line that does not contain "<", ">", "=", or " ".
if(REQUIREMENT MATCHES "^([^<>= ]+)")
set(PACKAGE_NAME ${CMAKE_MATCH_1})
string(TOUPPER ${PACKAGE_NAME} PACKAGE_NAME_UCASE) # Ucase name needed for CMake variable
string(TOLOWER ${PACKAGE_NAME} PACKAGE_NAME_LCASE) # Lcase name needed for import statement
check_python_package(${PACKAGE_NAME_LCASE} HAVE_PYTHON_${PACKAGE_NAME_UCASE})
if(NOT HAVE_PYTHON_${PACKAGE_NAME_UCASE})
message(WARNING "Missing Python dependency ${PACKAGE_NAME}")
endif()
else()
message(FATAL_ERROR "Cannot parse line \"${REQUIREMENT}\" in requirements.txt")
endif()
check_python_package(${PACKAGE_NAME_LCASE} HAVE_PYTHON_${PACKAGE_NAME_UCASE})
if(NOT HAVE_PYTHON_${PACKAGE_NAME_UCASE})
message(WARNING "Missing Python dependency ${PACKAGE_NAME}")
endif()
else()
message(FATAL_ERROR "Cannot parse line \"${REQUIREMENT}\" in requirements.txt")
endif()
endforeach()
# Check deps for memap
if(Python3_FOUND AND HAVE_PYTHON_INTELHEX AND HAVE_PYTHON_PRETTYTABLE)
set(HAVE_MEMAP_DEPS TRUE)
set(HAVE_MEMAP_DEPS TRUE)
else()
set(HAVE_MEMAP_DEPS FALSE)
message(STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed")
set(HAVE_MEMAP_DEPS FALSE)
message(STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed")
endif()

View File

@ -1,5 +1,8 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
option(MBED_TEST_BAREMETAL OFF)
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
@ -52,19 +55,14 @@ macro(mbed_greentea_add_test)
${MBED_GREENTEA_TEST_SOURCES}
)
# The CMake MBED_TEST_LINK_LIBRARIES command-line argument is to get greentea test all dependent libraries.
# For example:
# - To select mbed-os library, use cmake with -DMBED_TEST_LINK_LIBRARIES=mbed-os
# - To select baremetal library, use cmake with -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal
# - To select baremetal with extra external error logging library to the test, use cmake with
# -D "MBED_TEST_LINK_LIBRARIES=mbed-baremetal ext-errorlogging"
if (DEFINED MBED_TEST_LINK_LIBRARIES)
separate_arguments(MBED_TEST_LINK_LIBRARIES)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS ${MBED_TEST_LINK_LIBRARIES} mbed-greentea)
if(MBED_TEST_BAREMETAL)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal)
else()
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-greentea)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os)
endif()
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-greentea)
target_link_libraries(${MBED_GREENTEA_TEST_NAME}
PRIVATE
${MBED_GREENTEA_TEST_REQUIRED_LIBS}