diff --git a/tools/cmake/README.md b/tools/cmake/README.md index 7ea03c8ad05..50ef9531d35 100644 --- a/tools/cmake/README.md +++ b/tools/cmake/README.md @@ -87,25 +87,17 @@ cmake -S -B -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 -m --mbed-os-path /path/to/mbed-os ``` * Build the test binary with the full profile ``` - cd cmake_build//// && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-os && cmake --build . - ``` - To build the test binary with the baremetal profile - ``` - cd cmake_build//// && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal && cmake --build . + cd cmake_build//// && 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//// && cmake ../../../.. -G Ninja -D"MBED_TEST_LINK_LIBRARIES=mbed-os XYZ" && cmake --build . + cd cmake_build//// && cmake ../../../.. -G Ninja -DMBED_TEST_BAREMETAL=ON && cmake --build . ``` Notes: diff --git a/tools/cmake/app.cmake b/tools/cmake/app.cmake index 79021127817..500e477a4c4 100644 --- a/tools/cmake/app.cmake +++ b/tools/cmake/app.cmake @@ -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() diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index c108712c53b..a493ea1f6ee 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -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}