From fca7323f732d7f5caff3054d9a4a66afc5239ad6 Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 15 Sep 2021 11:17:21 +0100 Subject: [PATCH] CMake: QSPIFBlockDevice: Guard unit test directory In the QSPIFBlockDevice component we checked if BUILD_TESTING was enabled before adding the QSPIFBlockDevice/UNITTESTS subdirectory. In the parent blockdevice/CMakeLists.txt we added the QSPIFBlockDevice subdirectory to the build under two separate conditions: * when "QSPIF" is present in MBED_TARGET_LABELS * when building only unit tests This wasn't quite enough, as when we build greentea tests for some targets QSPIF is enabled in MBED_TARGET_LABELS, causing the QSPIFBlockDevice subdirectory and its unit tests to be added when building greentea tests. This caused a test failure on targets which enable QSPIF: ``` The following tests FAILED: 40 - qspif-unittest_NOT_BUILT (Not Run) ``` To fix this we need to specifically check that we're not building greentea tests before adding the QSPIFBlockDevice/UNITTESTS directory to the project. Part of this issue is our reliance on MBED_TARGET_LABELS to pull features in to the build. We should refactor our usage of MBED_TARGET_LABELS and use CMake target dependencies where possible. Then we wouldn't need to add subdirectories under various, often conflicting, scenarios. Instead the targets would always be available and we would just choose which ones to actually build in different cases using CMake target linking. --- storage/blockdevice/COMPONENT_QSPIF/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storage/blockdevice/COMPONENT_QSPIF/CMakeLists.txt b/storage/blockdevice/COMPONENT_QSPIF/CMakeLists.txt index f92553fe989..54b7d11b377 100644 --- a/storage/blockdevice/COMPONENT_QSPIF/CMakeLists.txt +++ b/storage/blockdevice/COMPONENT_QSPIF/CMakeLists.txt @@ -13,5 +13,7 @@ target_sources(mbed-storage-qspif ) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(UNITTESTS) + if (NOT BUILD_GREENTEA_TESTS) + add_subdirectory(UNITTESTS) + endif() endif()