Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions tools/cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
```
To 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 .
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja && cmake --build .
```
To build the test binary with the full profile and a "XYZ" library
Or build the test binary with the baremetal profile
```
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:
Expand Down
32 changes: 16 additions & 16 deletions tools/cmake/app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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

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()
# 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()

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()

18 changes: 8 additions & 10 deletions tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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}
Expand Down