Skip to content

Cmake: Add MBED_TEST_MODE macro #14538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ before_install:

addons:
apt:
sources:
- sourceline: 'deb https://apt.kitware.com/ubuntu/ focal main'
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
packages:
- cmake
- ninja-build
- libncursesw5

Expand Down Expand Up @@ -279,3 +283,41 @@ matrix:
| while read file; do python ./hal/tests/pinvalidate/pinvalidate.py -vfp "${file}"; done
- git diff --exit-code --diff-filter=d --color

### CMake Check ###
- &cmake-vm
stage: "CMake Check"
name: "Backward compatiblity check - MBED_TEST_MODE"
env: NAME=mbed-test-mode-check ROOT=tools/cmake/tests/mbed_test_mode/ TOOLCHAIN=GCC_ARM TARGET_NAME=K64F PROFILE=develop
language: python
python: 3.8
install:
# Hide Travis-preinstalled CMake
# The Travis-preinstalled CMake is unfortunately not installed via apt, so we
# can't replace it with an apt-supplied version very easily. Additionally, we
# can't permit the Travis-preinstalled copy to survive, as the Travis default
# path lists the Travis CMake install location ahead of any place where apt
# would install CMake to. Instead of apt removing or upgrading to a new CMake
# version, we must instead delete the Travis copy of CMake.
- sudo rm -rf /usr/local/cmake*
# Setup ccache
- ccache -o compiler_check=content
- ccache -M 1G
- pushd /usr/lib/ccache
- sudo ln -s ../../bin/ccache arm-none-eabi-gcc
- sudo ln -s ../../bin/ccache arm-none-eabi-g++
- export PATH="/usr/lib/ccache:$PATH"
- popd
# Install arm-none-eabi-gcc
- pushd /home/travis/build && mkdir arm-gcc && cd arm-gcc
- curl -L0 "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A" --output gcc-arm-none-eabi-9-2020-q2-update.tar.bz2
- tar xf gcc-arm-none-eabi-9-2020-q2-update.tar.bz2
- export PATH="$PATH:${PWD}/gcc-arm-none-eabi-9-2020-q2-update/bin"
- popd
- arm-none-eabi-gcc --version
# Install python modules
- pip install --upgrade mbed-tools
- pip install -r tools/cmake/requirements.txt
script:
- mbedtools configure -p ${ROOT} -t ${TOOLCHAIN} -m ${TARGET_NAME} --mbed-os-path .
- cmake -S ${ROOT} -B ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/ -GNinja -DCMAKE_BUILD_TYPE=${PROFILE}
- cmake --build ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ target_compile_definitions(mbed-core
${MBED_CONFIG_DEFINITIONS}
)

# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
MBED_TEST_MODE
)
endif()

# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
# 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
Expand Down
3 changes: 3 additions & 0 deletions tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ macro(mbed_greentea_add_test)

add_executable(${TEST_NAME})

# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
set(BUILD_TESTING ON)

mbed_configure_app_target(${TEST_NAME})

target_include_directories(${TEST_NAME}
Expand Down
21 changes: 21 additions & 0 deletions tools/cmake/tests/mbed_test_mode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../.. CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STATIC "")

include(${MBED_PATH}/tools/cmake/app.cmake)

add_test(NAME mbed-test-mode-check COMMAND mbed-test-mode-check)
add_executable(mbed-test-mode-check)
project(mbed-test-mode-check)

set(PROJECT_NAME ${CMAKE_PROJECT_NAME} CACHE INTERNAL "")
include(CTest)

target_sources(mbed-test-mode-check
PRIVATE
main.cpp
)
13 changes: 13 additions & 0 deletions tools/cmake/tests/mbed_test_mode/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* mbed Microcontroller Library
* Copyright (c) 2021 Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

#if BUILD_TESTING && !defined(MBED_TEST_MODE)
#error "MBED_TEST_MODE not defined with BUILD_TESTING on"
#else
int main(){
return 0;
}
#endif