Skip to content

Commit 42d24a8

Browse files
author
Jamie Smith
authored
Split app.cmake into two parts to fix CMake deprecation warning (#421)
* Split app.cmake into two parts to fix CMake deprecation warning * Use old version if that's all we have * Fix import, update more CMakeLists.txt files * augh * Simplify unit tests CI job
1 parent a468f27 commit 42d24a8

File tree

15 files changed

+188
-178
lines changed

15 files changed

+188
-178
lines changed

.github/workflows/basic_checks.yml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,7 @@ jobs:
231231
| while read file; do python ./hal/tests/pinvalidate/pinvalidate.py -vvvfp "${file}"; done
232232
git diff --exit-code --diff-filter=d --color
233233
234-
cmake-checks:
235-
env:
236-
NAME: mbed-test-mode-check
237-
ROOT: tools/cmake/tests/mbed_test_mode/
238-
TOOLCHAIN: GCC_ARM
239-
TARGET_NAME: K64F
240-
PROFILE: develop
234+
cmake-native-unit-tests:
241235
runs-on: ubuntu-latest
242236
container:
243237
image: ghcr.io/armmbed/mbed-os-env:master-latest
@@ -252,14 +246,7 @@ jobs:
252246
apt-get install -y python3-venv
253247
254248
-
255-
name: cmake build
256-
run: |
257-
set -x
258-
cmake -S ${{env.ROOT}} -B ${{ env.ROOT }}/cmake_build/${{env.TARGET_NAME}}/${{ env.PROFILE }}/${{ env.TOOLCHAIN }}/ -GNinja -DCMAKE_BUILD_TYPE=${{ env.PROFILE }} -DMBED_TARGET=${{ env.TARGET_NAME }}
259-
cmake --build ${{ env.ROOT }}/cmake_build/${{ env.TARGET_NAME }}/${{ env.PROFILE }}/${{ env.TOOLCHAIN }}/
260-
261-
-
262-
name: cmake unittest
249+
name: Build and run unit tests
263250
run: |
264251
set -x
265252
ctest --build-and-test . build --build-generator Ninja --build-options -DMBED_ENABLE_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON --test-command ctest

CMakeLists.txt

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This is the boilerplate for Mbed OS
55

66
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
7-
cmake_policy(VERSION 3.16...3.22)
7+
cmake_policy(VERSION 3.19...3.22)
88

99
# Setup build type (target type, tests/unit tests/real build) ----------------------------------------------------------------------------------
1010
# This block sets up the following variables for all subdirs to use:
@@ -56,7 +56,14 @@ if(MBED_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD)
5656
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "")
5757

5858
# Initialize Mbed build system
59-
include(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/app.cmake)
59+
include(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/mbed_toolchain_setup.cmake)
60+
endif()
61+
62+
# Create project and find compilers (if not already found)
63+
project(mbed-os LANGUAGES C CXX ASM)
64+
65+
if(MBED_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD)
66+
include(mbed_project_setup)
6067
endif()
6168

6269
if(MBED_IS_NATIVE_BUILD)
@@ -85,9 +92,6 @@ endif()
8592

8693
# Create core Mbed OS targets and set up build flags ----------------------------------------------------------------------------------
8794

88-
# Create project and find compilers (if not already found)
89-
project(mbed-os LANGUAGES C CXX ASM)
90-
9195
# Add all paths to the module files within Mbed OS
9296
list(APPEND CMAKE_MODULE_PATH
9397
${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts
@@ -309,19 +313,3 @@ if(NOT MBED_IS_NATIVE_BUILD)
309313
mbed_extract_flags(${MBED_TARGET_CMAKE_NAME}-flags ${MBED_TARGET_CMAKE_NAME})
310314
target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-flags)
311315
endif()
312-
313-
# Ninja requires to be forced for response files
314-
if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
315-
# known issue ARMClang and Ninja with response files for windows
316-
# https://gitlab.kitware.com/cmake/cmake/-/issues/21093
317-
# This gets fixed in newer cmake version
318-
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6484
319-
if((CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") AND ((${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.22.0") OR (NOT CMAKE_CXX_COMPILER_ID MATCHES "ARMClang")))
320-
set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "")
321-
endif()
322-
endif()
323-
324-
# If this is the top-level buildscript, run finalize tasks
325-
if(MBED_IS_STANDALONE AND (NOT MBED_IS_NATIVE_BUILD))
326-
mbed_finalize_build()
327-
endif()

tools/cmake/app.cmake

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,10 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
# Add our CMake list files to CMake default module path
5-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
4+
message(WARNING "Mbed: Deprecated: Instead of including app.cmake, include mbed_toolchain_setup.cmake, then call project(), then include mbed_project_setup.cmake. For more info, see https://github.com/mbed-ce/mbed-os/pull/421")
65

7-
find_program(CCACHE "ccache")
8-
if(CCACHE)
9-
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
10-
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
11-
endif()
12-
13-
# Figure out path to Mbed source
14-
get_filename_component(MBED_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. REALPATH)
15-
16-
# Find Python (needed to generate configurations)
17-
include(mbed_python_interpreter)
18-
19-
include(mbed_generate_config_header)
20-
include(mbed_target_functions)
21-
include(mbed_create_distro)
22-
23-
# Load toolchain and mbed configuration, generating it if needed
24-
include(mbed_generate_configuration)
25-
26-
# Load toolchain file
27-
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
28-
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
29-
# We want to bring CMP0123 we set in mbed_toolchain.cmake
30-
# to the whole Mbed OS.
31-
include(mbed_toolchain NO_POLICY_SCOPE)
32-
endif()
33-
34-
# Specify available build profiles and add options for the selected build profile
35-
include(mbed_profile)
6+
include(${CMAKE_CURRENT_LIST_DIR}/mbed_toolchain_setup.cmake)
367

378
enable_language(C CXX ASM)
389

39-
# set executable suffix (has to be done after enabling languages)
40-
# Note: This is nice in general, but is also required because STM32Cube will only work on files with a .elf extension
41-
set(CMAKE_EXECUTABLE_SUFFIX .elf)
42-
43-
# Find the GDB server, assuming it will be in the same path as the compiler.
44-
get_filename_component(CMAKE_COMPILER_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
45-
find_program(MBED_GDB
46-
NAMES arm-none-eabi-gdb gdb-multiarch
47-
HINTS ${CMAKE_COMPILER_BIN_DIR}
48-
DOC "Path to the GDB client program to use when debugging.")
49-
50-
if(EXISTS "${MBED_GDB}")
51-
set(MBED_GDB_FOUND TRUE)
52-
else()
53-
message(STATUS "Mbed: Could not find arm-none-eabi-gdb or gdb-mutiarch. Debugging will be unavailable. Set the MBED_GDB variable to specify its path.")
54-
set(MBED_GDB_FOUND FALSE)
55-
endif()
56-
57-
# Load upload method configuration defaults for this target.
58-
# Loading the settings here makes sure they are set at global scope, and also makes sure that
59-
# the user can override them by changing variable values after including app.cmake.
60-
#
61-
# default expected paths
62-
set(EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH ${CMAKE_SOURCE_DIR}/custom_targets/upload_method_cfg/${MBED_TARGET}.cmake)
63-
set(EXPECTED_MBED_UPLOAD_CFG_FILE_PATH ${MBED_SOURCE_DIR}/targets/upload_method_cfg/${MBED_TARGET}.cmake)
64-
65-
# check if a custom upload config path is defined in top lvl cmake
66-
if((DEFINED CUSTOM_UPLOAD_CFG_PATH))
67-
# Make path absolute, as required by EXISTS
68-
get_filename_component(CUSTOM_UPLOAD_CFG_PATH "${CUSTOM_UPLOAD_CFG_PATH}" ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR})
69-
if(EXISTS ${CUSTOM_UPLOAD_CFG_PATH})
70-
include(${CUSTOM_UPLOAD_CFG_PATH})
71-
message(STATUS "Mbed: Custom upload config included from ${CUSTOM_UPLOAD_CFG_PATH}")
72-
else()
73-
message(FATAL_ERROR "Mbed: Custom upload config is defined but files was not found here - ${CUSTOM_UPLOAD_CFG_PATH}")
74-
endif()
75-
76-
# check if a custom upload config is present in custom_targets/YOUR_TARGET folder
77-
elseif(EXISTS ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
78-
include(${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
79-
message(STATUS "Mbed: Custom upload config included from ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH}")
80-
81-
# check for build in upload config
82-
elseif(EXISTS ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
83-
include(${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
84-
message(STATUS "Mbed: Loading default upload method configuration from ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH}")
85-
else()
86-
message(STATUS "Mbed: Target does not have any upload method configuration. 'make flash-' commands will not be available unless configured by the upper-level project.")
87-
set(UPLOAD_METHOD_DEFAULT "NONE")
88-
endif()
10+
include(${CMAKE_CURRENT_LIST_DIR}/mbed_project_setup.cmake)

tools/cmake/mbed_ide_debug_cfg_generator.cmake

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ elseif(MBED_UPLOAD_SUPPORTS_DEBUG)
2929
message(STATUS "Mbed: No IDE detected, will generate configurations for command-line debugging (e.g. ninja gdbserver, then ninja debug-SomeProgram)")
3030
endif()
3131

32+
# Default no-op function declarations (to be overridden below)
33+
# -------------------------------------------------------------
34+
35+
function(mbed_generate_ide_debug_configuration CMAKE_TARGET)
36+
endfunction()
37+
38+
function(mbed_finalize_ide_debug_configurations)
39+
endfunction()
40+
41+
# Make sure we have the path to GDB
42+
# -------------------------------------------------------------
43+
if(NOT EXISTS "${MBED_GDB}")
44+
message(STATUS "Mbed: Could not find arm-none-eabi-gdb or gdb-multiarch. Debugging will be unavailable. Set the MBED_GDB variable to specify its path.")
45+
return()
46+
endif()
47+
48+
3249
# CLion generator
3350
# -------------------------------------------------------------
3451

@@ -239,6 +256,7 @@ elseif(MBED_GENERATE_VS_CODE_DEBUG_CFGS)
239256
# -------------------------------------------------------------
240257
elseif(MBED_UPLOAD_SUPPORTS_DEBUG)
241258

259+
242260
function(mbed_generate_ide_debug_configuration CMAKE_TARGET)
243261

244262
# create init file for GDB client
@@ -258,7 +276,7 @@ c"
258276
)
259277

260278
# add debug target
261-
if(MBED_UPLOAD_SUPPORTS_DEBUG AND MBED_GDB_FOUND)
279+
if(MBED_UPLOAD_SUPPORTS_DEBUG)
262280
add_custom_target(debug-${target}
263281
COMMENT "Starting GDB to debug ${target}..."
264282
COMMAND ${MBED_GDB}
@@ -278,14 +296,4 @@ c"
278296
USES_TERMINAL
279297
VERBATIM)
280298
endfunction(mbed_finalize_ide_debug_configurations)
281-
282-
else()
283-
284-
# No-ops
285-
function(mbed_generate_ide_debug_configuration CMAKE_TARGET)
286-
endfunction()
287-
288-
function(mbed_finalize_ide_debug_configurations)
289-
endfunction()
290-
291299
endif()

tools/cmake/mbed_project_setup.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# This script should be included after the top-level script calls project().
5+
# It sets up some global variables for project and upload method configuration.
6+
7+
8+
# Enable languages used by Mbed, in case the top level script didn't enable them
9+
enable_language(C CXX ASM)
10+
11+
# set executable suffix (has to be done after enabling languages)
12+
# Note: This is nice in general, but is also required because STM32Cube will only work on files with a .elf extension
13+
set(CMAKE_EXECUTABLE_SUFFIX .elf)
14+
15+
# Load upload method configuration defaults for this target.
16+
# Loading the settings here makes sure they are set at global scope, and also makes sure that
17+
# the user can override them by changing variable values after including app.cmake.
18+
#
19+
# default expected paths
20+
set(EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH ${CMAKE_SOURCE_DIR}/custom_targets/upload_method_cfg/${MBED_TARGET}.cmake)
21+
set(EXPECTED_MBED_UPLOAD_CFG_FILE_PATH ${MBED_SOURCE_DIR}/targets/upload_method_cfg/${MBED_TARGET}.cmake)
22+
23+
# check if a custom upload config path is defined in top lvl cmake
24+
if((DEFINED CUSTOM_UPLOAD_CFG_PATH))
25+
# Make path absolute, as required by EXISTS
26+
get_filename_component(CUSTOM_UPLOAD_CFG_PATH "${CUSTOM_UPLOAD_CFG_PATH}" ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR})
27+
if(EXISTS ${CUSTOM_UPLOAD_CFG_PATH})
28+
include(${CUSTOM_UPLOAD_CFG_PATH})
29+
message(STATUS "Mbed: Custom upload config included from ${CUSTOM_UPLOAD_CFG_PATH}")
30+
else()
31+
message(FATAL_ERROR "Mbed: Custom upload config is defined but files was not found here - ${CUSTOM_UPLOAD_CFG_PATH}")
32+
endif()
33+
34+
# check if a custom upload config is present in custom_targets/YOUR_TARGET folder
35+
elseif(EXISTS ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
36+
include(${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
37+
message(STATUS "Mbed: Custom upload config included from ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH}")
38+
39+
# check for build in upload config
40+
elseif(EXISTS ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
41+
include(${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
42+
message(STATUS "Mbed: Loading default upload method configuration from ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH}")
43+
else()
44+
message(STATUS "Mbed: Target does not have any upload method configuration. 'make flash-' commands will not be available unless configured by the upper-level project.")
45+
set(UPLOAD_METHOD_DEFAULT "NONE")
46+
endif()

tools/cmake/mbed_python_interpreter.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ if(MBED_CREATE_PYTHON_VENV)
1515
set(VENV_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-venv.stamp)
1616
set(MBED_REQUIREMENTS_TXT_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../requirements.txt")
1717

18+
# Make it so modifying requirements.txt will trigger a reconfigure
19+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${MBED_REQUIREMENTS_TXT_LOCATION})
20+
1821
# Find Python3, using the venv if it already exists
1922
set (ENV{VIRTUAL_ENV} ${MBED_VENV_LOCATION})
2023
set (Python3_FIND_VIRTUALENV FIRST)

tools/cmake/mbed_target_functions.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,23 @@ endfunction()
206206
# writing out debug configurations.
207207
#
208208
function(mbed_finalize_build)
209+
# Issue a warning if this is called multiple times (calling it manually used to be required).
210+
get_property(FINALIZE_BUILD_CALLED GLOBAL PROPERTY MBED_FINALIZE_BUILD_CALLED SET)
211+
if("${FINALIZE_BUILD_CALLED}")
212+
message(WARNING "Mbed: Deprecated: mbed_finalize_build() is now automatically called, so you don't need to call it in CMakeLists.txt")
213+
endif()
214+
209215
mbed_finalize_ide_debug_configurations()
216+
217+
set_property(GLOBAL PROPERTY MBED_FINALIZE_BUILD_CALLED TRUE)
210218
endfunction(mbed_finalize_build)
211219

220+
# Defer a call to mbed_finalize_build() when execution of the top level CMakeLists.txt ends.
221+
cmake_language(DEFER
222+
DIRECTORY ${CMAKE_SOURCE_DIR}
223+
ID mbed_finalize_build
224+
CALL mbed_finalize_build)
225+
212226
# Lists that mbed_disable_mcu_target_file stores data in
213227
set(MBED_DISABLE_MCU_TARGET_FILE_TARGETS "" CACHE INTERNAL "" FORCE)
214228
set(MBED_DISABLE_MCU_TARGET_FILE_FILES "" CACHE INTERNAL "" FORCE)

tools/cmake/mbed_toolchain.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ list_to_space_separated(CMAKE_CXX_FLAGS_INIT ${common_options} ${c_cxx_compile_o
8585
list_to_space_separated(CMAKE_ASM_FLAGS_INIT ${common_options} ${asm_compile_options})
8686
list_to_space_separated(CMAKE_EXE_LINKER_FLAGS_INIT ${link_options})
8787

88-
# due to a bug in ARMClang CMake compiler file, all _INIT flags must end with a space.
89-
# (this line: https://github.com/Kitware/CMake/blob/7d4a6ce714a9213ffd34b13a3debcb31a2430e04/Modules/Compiler/ARMClang.cmake#L97)
90-
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ")
91-
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ")
92-
set(CMAKE_ASM_FLAGS_INIT "${CMAKE_ASM_FLAGS_INIT} ")
93-
9488
# Set language standards
9589
set(CMAKE_C_STANDARD 11)
9690
set(CMAKE_C_EXTENSIONS TRUE)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2020 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# This CMake script shall be included first:
5+
# - before project() (or enable_languages()) is called by the application
6+
# - before any other Mbed CMake scripts are included and before the mbed-os subdir is added
7+
# - before any upload method config variables are set
8+
# Its goal is to configure CMake to execute the ARM compilers.
9+
# The only thing that should be done before including this script is to set the MBED_APP_JSON_PATH and
10+
# MBED_CUSTOM_TARGETS_JSON_PATH variables.
11+
12+
# Add our CMake list files to CMake default module path
13+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
14+
15+
find_program(CCACHE "ccache")
16+
if(CCACHE)
17+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
18+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
19+
endif()
20+
21+
# Figure out path to Mbed source
22+
get_filename_component(MBED_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. REALPATH)
23+
24+
# Find Python (needed to generate configurations)
25+
include(mbed_python_interpreter)
26+
27+
include(mbed_generate_config_header)
28+
include(mbed_target_functions)
29+
include(mbed_create_distro)
30+
31+
# Load toolchain and mbed configuration, generating it if needed
32+
include(mbed_generate_configuration)
33+
34+
# Load toolchain file
35+
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
36+
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
37+
# We want to bring CMP0123 we set in mbed_toolchain.cmake
38+
# to the whole Mbed OS.
39+
include(mbed_toolchain NO_POLICY_SCOPE)
40+
endif()
41+
42+
# Specify available build profiles and add options for the selected build profile
43+
include(mbed_profile)

tools/cmake/tests/mbed_test_mode/CMakeLists.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)