From eb733925dcd03008fbaf8cc03eb41106ff24da89 Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Thu, 10 Jun 2021 15:19:35 +0100 Subject: [PATCH 1/5] CMake: Remove trailing whitespace from CMakeLists.txt --- CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7290a3b03f..f85615fc9cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,14 +13,14 @@ endif() project(mbed-os) # Add all paths to the list files within Mbed OS -list(APPEND CMAKE_MODULE_PATH +list(APPEND CMAKE_MODULE_PATH "${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_Cypress/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NXP/scripts" ) option(BUILD_TESTING "Run unit tests only." OFF) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - include(CTest) + include(CTest) add_subdirectory(UNITTESTS) endif() @@ -68,19 +68,19 @@ if(${CMAKE_CROSSCOMPILING}) "Invalid printf library type '${MBED_PRINTF_LIB}'. Possible values:\n ${MBED_PRINTF_LIB_TYPES}" ) endif() - + mbed_set_cpu_core_definitions(mbed-core) if(${MBED_TOOLCHAIN_FILE_USED}) mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN}) mbed_set_c_lib(mbed-core ${MBED_C_LIB}) mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB}) - + target_compile_features(mbed-core INTERFACE c_std_11 cxx_std_14 ) - + endif() target_compile_definitions(mbed-core @@ -98,7 +98,7 @@ if(${CMAKE_CROSSCOMPILING}) endif() # We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker - # script, because of path le ngth limitations on Windows. We set the response file and bind the path + # script, because of path length limitations on Windows. We set the response file and bind the path # to a global property here. The MBED_TARGET being built queries this global property when it sets # the linker script. # @@ -110,7 +110,7 @@ if(${CMAKE_CROSSCOMPILING}) # using response files or global properties. mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH) set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH}) - + # Add compile definitions for backward compatibility with the toolchain # supported. New source files should instead check for __GNUC__ and __clang__ # for the GCC_ARM and ARM toolchains respectively. @@ -164,7 +164,7 @@ if(${CMAKE_CROSSCOMPILING}) string(TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED) string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED}) string(PREPEND MBED_TARGET_CONVERTED "mbed-") - + target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED}) endif() From c761049903c4ccf60bf037a30256c3f00fb6875d Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Thu, 10 Jun 2021 23:22:07 +0100 Subject: [PATCH 2/5] CMake: unit-tests: Remove trailing whitespace --- platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt b/platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt index d2bc69e55bf..eeda6edee16 100644 --- a/platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt +++ b/platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt @@ -14,8 +14,8 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-headers + mbed-stubs-platform gmock_main ) From 314d224b30fd730f19463f49aa6454aa13d44312 Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Thu, 10 Jun 2021 15:06:02 +0100 Subject: [PATCH 3/5] CMake: unit-tests: Remove trailing whitespace from stubs/CMakeLists.txt --- UNITTESTS/stubs/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 942adbcbf8e..2a66ebd9cb5 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -45,13 +45,13 @@ target_include_directories(mbed-headers-base ) target_include_directories(mbed-headers-storage - INTERFACE + INTERFACE ${mbed-os_SOURCE_DIR}/storage/filesystem/fat/include ${mbed-os_SOURCE_DIR}/storage/filesystem/fat/ChaN ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/include ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefsv2/littlefs - ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefsv2/littlefs/bd + ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefsv2/littlefs/bd ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/littlefs ${mbed-os_SOURCE_DIR}/storage/blockdevice/include ${mbed-os_SOURCE_DIR}/storage/filesystem/include @@ -91,7 +91,7 @@ target_include_directories(mbed-headers-drivers INTERFACE ${mbed-os_SOURCE_DIR}/drivers ${mbed-os_SOURCE_DIR}/drivers/include - ${mbed-os_SOURCE_DIR}/drivers/include/drivers + ${mbed-os_SOURCE_DIR}/drivers/include/drivers ) target_include_directories(mbed-headers-events @@ -100,7 +100,7 @@ target_include_directories(mbed-headers-events ${mbed-os_SOURCE_DIR}/events/tests/UNITTESTS/target_h/equeue ${mbed-os_SOURCE_DIR}/events/include ${mbed-os_SOURCE_DIR}/events/include/events - ${mbed-os_SOURCE_DIR}/events/include/events/internal + ${mbed-os_SOURCE_DIR}/events/include/events/internal ) target_include_directories(mbed-headers-hal From d4f01818b4136893cac28fc47eaef33e26bdd624 Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Thu, 10 Jun 2021 14:50:46 +0100 Subject: [PATCH 4/5] CMake: unit-tests: Fetch googletest master googletest now follows the "Abseil Live at HEAD" philosophy, which means they recommend using the latest commit on the master branch and always compiling from source. They recommend this to avoid version mismatch issues and "diamond dependency" problems which are common in dependency graphs with pinned versions. Google make the "promise" that future changes won't break downstream code if it follows the "Abseil compatability guidelines". Upping the version to master also fixes some CMake configure time warnings that were present with the older tagged releases of googletest: CMake Deprecation Warning at __build/_deps/googletest-src/CMakeLists.txt:4 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at __build/_deps/googletest-src/googlemock/CMakeLists.txt:45 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at __build/_deps/googletest-src/googletest/CMakeLists.txt:56 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions. --- UNITTESTS/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UNITTESTS/CMakeLists.txt b/UNITTESTS/CMakeLists.txt index bb00da96e39..edfad748ba1 100644 --- a/UNITTESTS/CMakeLists.txt +++ b/UNITTESTS/CMakeLists.txt @@ -19,7 +19,7 @@ include(FetchContent) # Download and unpack googletest FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.10.0 + GIT_TAG master ) FetchContent_MakeAvailable(googletest) From a0befae2d4662a1596c611d5acb749a300fd218c Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Thu, 10 Jun 2021 21:43:58 +0100 Subject: [PATCH 5/5] CMake: Only build unit tests if Mbed OS is the current project Typically when adding a unit test directory to a CMake project a check will be used to ensure the subdirectory is added only if the following are true: * The BUILD_TESTING option is set to ON. * The current CMake project is the top-level project. The reason being, if a downstream project includes our project they generally don't want to build our unit tests. In mbed-os, we do correctly specify the above condition before adding the central UNITTEST subdirectory, which fetches googletest and adds the "stub" libraries the unit tests depend on. However, we only check if CMAKE_CROSSCOMPILING is OFF (or undefined) before actually adding the unit tests. This mismatched logic would lead to unexpected build failures in various scenarios. One likely case could be: a downstream project including mbed-os happens to set CMAKE_CROSSCOMPILING to OFF/undefined for any reason (possibly to build its own unit tests). mbed-os would go ahead and attempt to build its tests without fetching googletest or adding the required stub targets. To fix the issue replace the check for CMAKE_CROSSCOMPILING in the unit tests with the same BUILD_TESTING idiom we use for adding the central UNITTESTS subdirectory. --- connectivity/cellular/CMakeLists.txt | 2 +- connectivity/lorawan/CMakeLists.txt | 2 +- connectivity/netsocket/CMakeLists.txt | 2 +- drivers/CMakeLists.txt | 2 +- events/CMakeLists.txt | 3 ++- platform/CMakeLists.txt | 2 +- storage/blockdevice/CMakeLists.txt | 2 +- storage/kvstore/filesystemstore/CMakeLists.txt | 2 +- storage/kvstore/tdbstore/CMakeLists.txt | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-) diff --git a/connectivity/cellular/CMakeLists.txt b/connectivity/cellular/CMakeLists.txt index 8455c59b4c0..d7ce11f90d4 100644 --- a/connectivity/cellular/CMakeLists.txt +++ b/connectivity/cellular/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif() diff --git a/connectivity/lorawan/CMakeLists.txt b/connectivity/lorawan/CMakeLists.txt index 552a72a6fee..941b01e04e5 100644 --- a/connectivity/lorawan/CMakeLists.txt +++ b/connectivity/lorawan/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif() diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index 0ce8a2f466e..62bea8cc636 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif() diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 4d26ac6dec1..9079d3d75ac 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif() diff --git a/events/CMakeLists.txt b/events/CMakeLists.txt index 1cda3156d39..da4d6935112 100644 --- a/events/CMakeLists.txt +++ b/events/CMakeLists.txt @@ -1,9 +1,10 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) else() + add_library(mbed-events INTERFACE) target_include_directories(mbed-events diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index b79a4a28cbe..df83719fc69 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif() diff --git a/storage/blockdevice/CMakeLists.txt b/storage/blockdevice/CMakeLists.txt index cbbb76f0aae..9f847d43604 100644 --- a/storage/blockdevice/CMakeLists.txt +++ b/storage/blockdevice/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif() diff --git a/storage/kvstore/filesystemstore/CMakeLists.txt b/storage/kvstore/filesystemstore/CMakeLists.txt index aeb8aef1912..7289fe8b8df 100644 --- a/storage/kvstore/filesystemstore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif() diff --git a/storage/kvstore/tdbstore/CMakeLists.txt b/storage/kvstore/tdbstore/CMakeLists.txt index a1cb048ad93..d4f8d92ed59 100644 --- a/storage/kvstore/tdbstore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if(NOT ${CMAKE_CROSSCOMPILING}) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests/UNITTESTS) endif()