Skip to content

Commit 3b2cc49

Browse files
Split app.cmake into two parts to fix CMake deprecation warning
1 parent ceee63f commit 3b2cc49

File tree

11 files changed

+164
-109
lines changed

11 files changed

+164
-109
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
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:

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. Including app.cmake will unavoidably trigger a warning from CMake due to calling enable_language() before project().")
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()
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
@@ -195,9 +195,23 @@ endfunction()
195195
# writing out debug configurations.
196196
#
197197
function(mbed_finalize_build)
198+
# Issue a warning if this is called multiple times (calling it manually used to be required).
199+
get_property(FINALIZE_BUILD_CALLED GLOBAL PROPERTY MBED_FINALIZE_BUILD_CALLED SET)
200+
if("${FINALIZE_BUILD_CALLED}")
201+
message(WARNING "Mbed: Deprecated: mbed_finalize_build() is now automatically called, so you don't need to call it in CMakeLists.txt")
202+
endif()
203+
198204
mbed_finalize_ide_debug_configurations()
205+
206+
set_property(GLOBAL PROPERTY MBED_FINALIZE_BUILD_CALLED TRUE)
199207
endfunction(mbed_finalize_build)
200208

209+
# Defer a call to mbed_finalize_build() when execution of the top level CMakeLists.txt ends.
210+
cmake_language(DEFER
211+
DIRECTORY ${CMAKE_SOURCE_DIR}
212+
ID mbed_finalize_build
213+
CALL mbed_finalize_build)
214+
201215
# Lists that mbed_disable_mcu_target_file stores data in
202216
set(MBED_DISABLE_MCU_TARGET_FILE_TARGETS "" CACHE INTERNAL "" FORCE)
203217
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/toolchains/GCC_ARM.cmake

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

4-
# specify the cross compiler. Use cache variables so that VS Code can detect the compiler from the cache.
5-
set(CMAKE_C_COMPILER arm-none-eabi-gcc CACHE FILEPATH "C Compiler")
6-
set(CMAKE_CXX_COMPILER arm-none-eabi-g++ CACHE FILEPATH "CXX Compiler")
7-
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc CACHE FILEPATH "ASM Compiler")
8-
set(GCC_ELF2BIN "arm-none-eabi-objcopy")
9-
set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
4+
# Find the cross compiler. Use cache variables so that VS Code can detect the compiler from the cache.
5+
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
6+
file(GLOB ARM_NONE_EABI_TOOLCHAIN_HINTS "C:/Program Files*/Arm GNU Toolchain arm-none-eabi/*/bin")
7+
else()
8+
set(ARM_NONE_EABI_TOOLCHAIN_HINTS "")
9+
endif()
10+
11+
find_program(CMAKE_C_COMPILER NAMES arm-none-eabi-gcc
12+
DOC "C Compiler"
13+
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
14+
REQUIRED)
15+
16+
# Now that we have the C compiler location, also use it to find the ASM compiler and objcopy
17+
get_filename_component(ARM_NONE_EABI_TOOLCHAIN_HINTS ${CMAKE_C_COMPILER} DIRECTORY)
18+
find_program(CMAKE_CXX_COMPILER NAMES arm-none-eabi-g++
19+
DOC "CXX Compiler"
20+
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
21+
REQUIRED)
22+
find_program(CMAKE_ASM_COMPILER NAMES arm-none-eabi-gcc
23+
DOC "ASM Compiler"
24+
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
25+
REQUIRED)
26+
find_program(CMAKE_OBJCOPY NAMES arm-none-eabi-objcopy
27+
DOC "Elf to bin/hex conversion program"
28+
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
29+
REQUIRED)
30+
find_program(MBED_GDB
31+
NAMES arm-none-eabi-gdb gdb-multiarch
32+
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
33+
DOC "Path to the GDB client program to use when debugging.")
34+
35+
set_property(GLOBAL PROPERTY ELF2BIN ${CMAKE_OBJCOPY})
1036

1137
# build toolchain flags that get passed to everything (including CMake compiler checks)
1238
list(APPEND link_options

tools/python/memap/memap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from argparse import ArgumentParser
6161
from copy import deepcopy
6262
from collections import defaultdict
63-
from prettytable import PrettyTable, HEADER
63+
from prettytable import PrettyTable, HRuleStyle
6464
from jinja2 import FileSystemLoader, StrictUndefined
6565
from jinja2.environment import Environment
6666

@@ -689,7 +689,7 @@ def generate_table(self, file_desc):
689689
columns = ['Module']
690690
columns.extend(self.print_sections)
691691

692-
table = PrettyTable(columns, junction_char="|", hrules=HEADER)
692+
table = PrettyTable(columns, junction_char="|", hrules=HRuleStyle.HEADER)
693693
table.align["Module"] = "l"
694694
for col in self.print_sections:
695695
table.align[col] = 'r'

0 commit comments

Comments
 (0)