diff --git a/tools/cmake/README.md b/tools/cmake/README.md index 7ea03c8ad0..50ef9531d3 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 . + cd cmake_build//// && 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//// && 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//// && 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/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index c108712c53..a493ea1f6e 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}