From b1c4c446d2be34e4d1773d28e8e359a635284d9a Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Mon, 8 Feb 2021 08:58:30 -0800 Subject: [PATCH 1/2] CMake: Greentea test CMakeLists.txt refactoring - Added the new CMake `MBED_TEST_LINK_LIBRARIES` command-line argument support to receive all dependent libraries for the particular greentea test suite. 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 external error logging library to the test with -D "MBED_TEST_LINK_LIBRARIES=mbed-baremetal ext-errorlogging" --- tools/cmake/mbed_greentea.cmake | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index dca5c6b634..920c5f0466 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -55,10 +55,17 @@ macro(mbed_greentea_add_test) ${MBED_GREENTEA_TEST_SOURCES} ) - if(MBED_BAREMETAL_GREENTEA_TEST) - list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal mbed-greentea) - else() - list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os mbed-greentea) + # 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) + else() + list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-greentea) endif() target_link_libraries(${TEST_NAME} From c93901a804f4596287b68d45b4ff2bb7ab50b23e Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Thu, 11 Feb 2021 11:28:51 -0800 Subject: [PATCH 2/2] CMake: Update readme about new MBED_TEST_LINK_LIBRARIES command line argument --- tools/cmake/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/cmake/README.md b/tools/cmake/README.md index 2e80761759..cb653340c8 100644 --- a/tools/cmake/README.md +++ b/tools/cmake/README.md @@ -87,14 +87,24 @@ $ mbedtools configure -t -m ``` * Copy `.mbedbuild/` into the test suite directory. * 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 to build the test binary with the full profile ``` - touch mbed-os.lib && mkdir cmake_build && cd cmake_build && cmake .. -G Ninja && cmake --build . + mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-os && cmake --build . ``` * Run the following command to build the test binary with the baremetal profile ``` - touch mbed-os.lib && mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -DMBED_BAREMETAL_GREENTEA_TEST=ON && cmake --build . + mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal && cmake --build . + ``` +* Run the following command to build the test binary with the full profile and XYZ library + ``` + mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -D"MBED_TEST_LINK_LIBRARIES=mbed-os XYZ" && cmake --build . ``` Notes: