Skip to content

Commit e25e94e

Browse files
authored
Merge pull request #14538 from harmut01/cmake-test-mode
Cmake: Add MBED_TEST_MODE macro
2 parents 5a121b9 + 5a18172 commit e25e94e

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

.travis.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ before_install:
3535

3636
addons:
3737
apt:
38+
sources:
39+
- sourceline: 'deb https://apt.kitware.com/ubuntu/ focal main'
40+
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
3841
packages:
42+
- cmake
3943
- ninja-build
4044
- libncursesw5
4145

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

286+
### CMake Check ###
287+
- &cmake-vm
288+
stage: "CMake Check"
289+
name: "Backward compatiblity check - MBED_TEST_MODE"
290+
env: NAME=mbed-test-mode-check ROOT=tools/cmake/tests/mbed_test_mode/ TOOLCHAIN=GCC_ARM TARGET_NAME=K64F PROFILE=develop
291+
language: python
292+
python: 3.8
293+
install:
294+
# Hide Travis-preinstalled CMake
295+
# The Travis-preinstalled CMake is unfortunately not installed via apt, so we
296+
# can't replace it with an apt-supplied version very easily. Additionally, we
297+
# can't permit the Travis-preinstalled copy to survive, as the Travis default
298+
# path lists the Travis CMake install location ahead of any place where apt
299+
# would install CMake to. Instead of apt removing or upgrading to a new CMake
300+
# version, we must instead delete the Travis copy of CMake.
301+
- sudo rm -rf /usr/local/cmake*
302+
# Setup ccache
303+
- ccache -o compiler_check=content
304+
- ccache -M 1G
305+
- pushd /usr/lib/ccache
306+
- sudo ln -s ../../bin/ccache arm-none-eabi-gcc
307+
- sudo ln -s ../../bin/ccache arm-none-eabi-g++
308+
- export PATH="/usr/lib/ccache:$PATH"
309+
- popd
310+
# Install arm-none-eabi-gcc
311+
- pushd /home/travis/build && mkdir arm-gcc && cd arm-gcc
312+
- 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
313+
- tar xf gcc-arm-none-eabi-9-2020-q2-update.tar.bz2
314+
- export PATH="$PATH:${PWD}/gcc-arm-none-eabi-9-2020-q2-update/bin"
315+
- popd
316+
- arm-none-eabi-gcc --version
317+
# Install python modules
318+
- pip install --upgrade mbed-tools
319+
- pip install -r tools/cmake/requirements.txt
320+
script:
321+
- mbedtools configure -p ${ROOT} -t ${TOOLCHAIN} -m ${TARGET_NAME} --mbed-os-path .
322+
- cmake -S ${ROOT} -B ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/ -GNinja -DCMAKE_BUILD_TYPE=${PROFILE}
323+
- cmake --build ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ target_compile_definitions(mbed-core
7979
${MBED_CONFIG_DEFINITIONS}
8080
)
8181

82+
# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
83+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
84+
target_compile_definitions(${PROJECT_NAME}
85+
PUBLIC
86+
MBED_TEST_MODE
87+
)
88+
endif()
89+
8290
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
8391
# script, because of path length limitations on Windows. We set the response file and bind the path
8492
# to a global property here. The MBED_TARGET being built queries this global property when it sets

tools/cmake/mbed_greentea.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ macro(mbed_greentea_add_test)
4141

4242
add_executable(${TEST_NAME})
4343

44+
# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
45+
set(BUILD_TESTING ON)
46+
4447
mbed_configure_app_target(${TEST_NAME})
4548

4649
target_include_directories(${TEST_NAME}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2020 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5+
6+
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../.. CACHE INTERNAL "")
7+
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STATIC "")
8+
9+
include(${MBED_PATH}/tools/cmake/app.cmake)
10+
11+
add_test(NAME mbed-test-mode-check COMMAND mbed-test-mode-check)
12+
add_executable(mbed-test-mode-check)
13+
project(mbed-test-mode-check)
14+
15+
set(PROJECT_NAME ${CMAKE_PROJECT_NAME} CACHE INTERNAL "")
16+
include(CTest)
17+
18+
target_sources(mbed-test-mode-check
19+
PRIVATE
20+
main.cpp
21+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 Arm Limited and Contributors. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#if BUILD_TESTING && !defined(MBED_TEST_MODE)
8+
#error "MBED_TEST_MODE not defined with BUILD_TESTING on"
9+
#else
10+
int main(){
11+
return 0;
12+
}
13+
#endif

0 commit comments

Comments
 (0)