Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This is the boilerplate for Mbed OS

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
cmake_policy(VERSION 3.16...3.22)
cmake_policy(VERSION 3.19...3.22)

# Setup build type (target type, tests/unit tests/real build) ----------------------------------------------------------------------------------
# This block sets up the following variables for all subdirs to use:
Expand Down
84 changes: 3 additions & 81 deletions tools/cmake/app.cmake
Original file line number Diff line number Diff line change
@@ -1,88 +1,10 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Add our CMake list files to CMake default module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
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().")

find_program(CCACHE "ccache")
if(CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
endif()

# Figure out path to Mbed source
get_filename_component(MBED_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. REALPATH)

# Find Python (needed to generate configurations)
include(mbed_python_interpreter)

include(mbed_generate_config_header)
include(mbed_target_functions)
include(mbed_create_distro)

# Load toolchain and mbed configuration, generating it if needed
include(mbed_generate_configuration)

# Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
# We want to bring CMP0123 we set in mbed_toolchain.cmake
# to the whole Mbed OS.
include(mbed_toolchain NO_POLICY_SCOPE)
endif()

# Specify available build profiles and add options for the selected build profile
include(mbed_profile)
include(${CMAKE_CURRENT_LIST_DIR}/mbed_toolchain_setup.cmake)

enable_language(C CXX ASM)

# set executable suffix (has to be done after enabling languages)
# Note: This is nice in general, but is also required because STM32Cube will only work on files with a .elf extension
set(CMAKE_EXECUTABLE_SUFFIX .elf)

# Find the GDB server, assuming it will be in the same path as the compiler.
get_filename_component(CMAKE_COMPILER_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
find_program(MBED_GDB
NAMES arm-none-eabi-gdb gdb-multiarch
HINTS ${CMAKE_COMPILER_BIN_DIR}
DOC "Path to the GDB client program to use when debugging.")

if(EXISTS "${MBED_GDB}")
set(MBED_GDB_FOUND TRUE)
else()
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.")
set(MBED_GDB_FOUND FALSE)
endif()

# Load upload method configuration defaults for this target.
# Loading the settings here makes sure they are set at global scope, and also makes sure that
# the user can override them by changing variable values after including app.cmake.
#
# default expected paths
set(EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH ${CMAKE_SOURCE_DIR}/custom_targets/upload_method_cfg/${MBED_TARGET}.cmake)
set(EXPECTED_MBED_UPLOAD_CFG_FILE_PATH ${MBED_SOURCE_DIR}/targets/upload_method_cfg/${MBED_TARGET}.cmake)

# check if a custom upload config path is defined in top lvl cmake
if((DEFINED CUSTOM_UPLOAD_CFG_PATH))
# Make path absolute, as required by EXISTS
get_filename_component(CUSTOM_UPLOAD_CFG_PATH "${CUSTOM_UPLOAD_CFG_PATH}" ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR})
if(EXISTS ${CUSTOM_UPLOAD_CFG_PATH})
include(${CUSTOM_UPLOAD_CFG_PATH})
message(STATUS "Mbed: Custom upload config included from ${CUSTOM_UPLOAD_CFG_PATH}")
else()
message(FATAL_ERROR "Mbed: Custom upload config is defined but files was not found here - ${CUSTOM_UPLOAD_CFG_PATH}")
endif()

# check if a custom upload config is present in custom_targets/YOUR_TARGET folder
elseif(EXISTS ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
include(${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
message(STATUS "Mbed: Custom upload config included from ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH}")

# check for build in upload config
elseif(EXISTS ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
include(${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
message(STATUS "Mbed: Loading default upload method configuration from ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH}")
else()
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.")
set(UPLOAD_METHOD_DEFAULT "NONE")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/mbed_project_setup.cmake)
30 changes: 19 additions & 11 deletions tools/cmake/mbed_ide_debug_cfg_generator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ elseif(MBED_UPLOAD_SUPPORTS_DEBUG)
message(STATUS "Mbed: No IDE detected, will generate configurations for command-line debugging (e.g. ninja gdbserver, then ninja debug-SomeProgram)")
endif()

# Default no-op function declarations (to be overridden below)
# -------------------------------------------------------------

function(mbed_generate_ide_debug_configuration CMAKE_TARGET)
endfunction()

function(mbed_finalize_ide_debug_configurations)
endfunction()

# Make sure we have the path to GDB
# -------------------------------------------------------------
if(NOT EXISTS "${MBED_GDB}")
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.")
return()
endif()


# CLion generator
# -------------------------------------------------------------

Expand Down Expand Up @@ -239,6 +256,7 @@ elseif(MBED_GENERATE_VS_CODE_DEBUG_CFGS)
# -------------------------------------------------------------
elseif(MBED_UPLOAD_SUPPORTS_DEBUG)


function(mbed_generate_ide_debug_configuration CMAKE_TARGET)

# create init file for GDB client
Expand All @@ -258,7 +276,7 @@ c"
)

# add debug target
if(MBED_UPLOAD_SUPPORTS_DEBUG AND MBED_GDB_FOUND)
if(MBED_UPLOAD_SUPPORTS_DEBUG)
add_custom_target(debug-${target}
COMMENT "Starting GDB to debug ${target}..."
COMMAND ${MBED_GDB}
Expand All @@ -278,14 +296,4 @@ c"
USES_TERMINAL
VERBATIM)
endfunction(mbed_finalize_ide_debug_configurations)

else()

# No-ops
function(mbed_generate_ide_debug_configuration CMAKE_TARGET)
endfunction()

function(mbed_finalize_ide_debug_configurations)
endfunction()

endif()
46 changes: 46 additions & 0 deletions tools/cmake/mbed_project_setup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# This script should be included after the top-level script calls project().
# It sets up some global variables for project and upload method configuration.


# Enable languages used by Mbed, in case the top level script didn't enable them
enable_language(C CXX ASM)

# set executable suffix (has to be done after enabling languages)
# Note: This is nice in general, but is also required because STM32Cube will only work on files with a .elf extension
set(CMAKE_EXECUTABLE_SUFFIX .elf)

# Load upload method configuration defaults for this target.
# Loading the settings here makes sure they are set at global scope, and also makes sure that
# the user can override them by changing variable values after including app.cmake.
#
# default expected paths
set(EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH ${CMAKE_SOURCE_DIR}/custom_targets/upload_method_cfg/${MBED_TARGET}.cmake)
set(EXPECTED_MBED_UPLOAD_CFG_FILE_PATH ${MBED_SOURCE_DIR}/targets/upload_method_cfg/${MBED_TARGET}.cmake)

# check if a custom upload config path is defined in top lvl cmake
if((DEFINED CUSTOM_UPLOAD_CFG_PATH))
# Make path absolute, as required by EXISTS
get_filename_component(CUSTOM_UPLOAD_CFG_PATH "${CUSTOM_UPLOAD_CFG_PATH}" ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR})
if(EXISTS ${CUSTOM_UPLOAD_CFG_PATH})
include(${CUSTOM_UPLOAD_CFG_PATH})
message(STATUS "Mbed: Custom upload config included from ${CUSTOM_UPLOAD_CFG_PATH}")
else()
message(FATAL_ERROR "Mbed: Custom upload config is defined but files was not found here - ${CUSTOM_UPLOAD_CFG_PATH}")
endif()

# check if a custom upload config is present in custom_targets/YOUR_TARGET folder
elseif(EXISTS ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
include(${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH})
message(STATUS "Mbed: Custom upload config included from ${EXPECTED_CUSTOM_UPLOAD_CFG_FILE_PATH}")

# check for build in upload config
elseif(EXISTS ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
include(${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
message(STATUS "Mbed: Loading default upload method configuration from ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH}")
else()
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.")
set(UPLOAD_METHOD_DEFAULT "NONE")
endif()
3 changes: 3 additions & 0 deletions tools/cmake/mbed_python_interpreter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ if(MBED_CREATE_PYTHON_VENV)
set(VENV_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-venv.stamp)
set(MBED_REQUIREMENTS_TXT_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../requirements.txt")

# Make it so modifying requirements.txt will trigger a reconfigure
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${MBED_REQUIREMENTS_TXT_LOCATION})

# Find Python3, using the venv if it already exists
set (ENV{VIRTUAL_ENV} ${MBED_VENV_LOCATION})
set (Python3_FIND_VIRTUALENV FIRST)
Expand Down
14 changes: 14 additions & 0 deletions tools/cmake/mbed_target_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,23 @@ endfunction()
# writing out debug configurations.
#
function(mbed_finalize_build)
# Issue a warning if this is called multiple times (calling it manually used to be required).
get_property(FINALIZE_BUILD_CALLED GLOBAL PROPERTY MBED_FINALIZE_BUILD_CALLED SET)
if("${FINALIZE_BUILD_CALLED}")
message(WARNING "Mbed: Deprecated: mbed_finalize_build() is now automatically called, so you don't need to call it in CMakeLists.txt")
endif()

mbed_finalize_ide_debug_configurations()

set_property(GLOBAL PROPERTY MBED_FINALIZE_BUILD_CALLED TRUE)
endfunction(mbed_finalize_build)

# Defer a call to mbed_finalize_build() when execution of the top level CMakeLists.txt ends.
cmake_language(DEFER
DIRECTORY ${CMAKE_SOURCE_DIR}
ID mbed_finalize_build
CALL mbed_finalize_build)

# Lists that mbed_disable_mcu_target_file stores data in
set(MBED_DISABLE_MCU_TARGET_FILE_TARGETS "" CACHE INTERNAL "" FORCE)
set(MBED_DISABLE_MCU_TARGET_FILE_FILES "" CACHE INTERNAL "" FORCE)
Expand Down
6 changes: 0 additions & 6 deletions tools/cmake/mbed_toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ list_to_space_separated(CMAKE_CXX_FLAGS_INIT ${common_options} ${c_cxx_compile_o
list_to_space_separated(CMAKE_ASM_FLAGS_INIT ${common_options} ${asm_compile_options})
list_to_space_separated(CMAKE_EXE_LINKER_FLAGS_INIT ${link_options})

# due to a bug in ARMClang CMake compiler file, all _INIT flags must end with a space.
# (this line: https://github.com/Kitware/CMake/blob/7d4a6ce714a9213ffd34b13a3debcb31a2430e04/Modules/Compiler/ARMClang.cmake#L97)
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ")
set(CMAKE_ASM_FLAGS_INIT "${CMAKE_ASM_FLAGS_INIT} ")

# Set language standards
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS TRUE)
Expand Down
43 changes: 43 additions & 0 deletions tools/cmake/mbed_toolchain_setup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# This CMake script shall be included first:
# - before project() (or enable_languages()) is called by the application
# - before any other Mbed CMake scripts are included and before the mbed-os subdir is added
# - before any upload method config variables are set
# Its goal is to configure CMake to execute the ARM compilers.
# The only thing that should be done before including this script is to set the MBED_APP_JSON_PATH and
# MBED_CUSTOM_TARGETS_JSON_PATH variables.

# Add our CMake list files to CMake default module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

find_program(CCACHE "ccache")
if(CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
endif()

# Figure out path to Mbed source
get_filename_component(MBED_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. REALPATH)

# Find Python (needed to generate configurations)
include(mbed_python_interpreter)

include(mbed_generate_config_header)
include(mbed_target_functions)
include(mbed_create_distro)

# Load toolchain and mbed configuration, generating it if needed
include(mbed_generate_configuration)

# Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
# We want to bring CMP0123 we set in mbed_toolchain.cmake
# to the whole Mbed OS.
include(mbed_toolchain NO_POLICY_SCOPE)
endif()

# Specify available build profiles and add options for the selected build profile
include(mbed_profile)
38 changes: 32 additions & 6 deletions tools/cmake/toolchains/GCC_ARM.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# specify the cross compiler. Use cache variables so that VS Code can detect the compiler from the cache.
set(CMAKE_C_COMPILER arm-none-eabi-gcc CACHE FILEPATH "C Compiler")
set(CMAKE_CXX_COMPILER arm-none-eabi-g++ CACHE FILEPATH "CXX Compiler")
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc CACHE FILEPATH "ASM Compiler")
set(GCC_ELF2BIN "arm-none-eabi-objcopy")
set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
# Find the cross compiler. Use cache variables so that VS Code can detect the compiler from the cache.
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
file(GLOB ARM_NONE_EABI_TOOLCHAIN_HINTS "C:/Program Files*/Arm GNU Toolchain arm-none-eabi/*/bin")
else()
set(ARM_NONE_EABI_TOOLCHAIN_HINTS "")
endif()

find_program(CMAKE_C_COMPILER NAMES arm-none-eabi-gcc
DOC "C Compiler"
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
REQUIRED)

# Now that we have the C compiler location, also use it to find the ASM compiler and objcopy
get_filename_component(ARM_NONE_EABI_TOOLCHAIN_HINTS ${CMAKE_C_COMPILER} DIRECTORY)
find_program(CMAKE_CXX_COMPILER NAMES arm-none-eabi-g++
DOC "CXX Compiler"
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
REQUIRED)
find_program(CMAKE_ASM_COMPILER NAMES arm-none-eabi-gcc
DOC "ASM Compiler"
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
REQUIRED)
find_program(CMAKE_OBJCOPY NAMES arm-none-eabi-objcopy
DOC "Elf to bin/hex conversion program"
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
REQUIRED)
find_program(MBED_GDB
NAMES arm-none-eabi-gdb gdb-multiarch
HINTS ${ARM_NONE_EABI_TOOLCHAIN_HINTS}
DOC "Path to the GDB client program to use when debugging.")

set_property(GLOBAL PROPERTY ELF2BIN ${CMAKE_OBJCOPY})

# build toolchain flags that get passed to everything (including CMake compiler checks)
list(APPEND link_options
Expand Down
4 changes: 2 additions & 2 deletions tools/python/memap/memap.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from argparse import ArgumentParser
from copy import deepcopy
from collections import defaultdict
from prettytable import PrettyTable, HEADER
from prettytable import PrettyTable, HRuleStyle
from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment

Expand Down Expand Up @@ -689,7 +689,7 @@ def generate_table(self, file_desc):
columns = ['Module']
columns.extend(self.print_sections)

table = PrettyTable(columns, junction_char="|", hrules=HEADER)
table = PrettyTable(columns, junction_char="|", hrules=HRuleStyle.HEADER)
table.align["Module"] = "l"
for col in self.print_sections:
table.align[col] = 'r'
Expand Down
3 changes: 1 addition & 2 deletions tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PrettyTable<=1.0.1; python_version < '3.6'
prettytable>=2.0,<4.0; python_version >= '3.6'
prettytable>=3.12.0 # 3.12.0 both added HRuleStyle and deprecated the old constants in one single release :/
future>=0.18.0,<1.0
jinja2>=2.11.3
intelhex>=2.3.0,<3.0.0
Expand Down
Loading