diff --git a/.github/workflows/basic_checks.yml b/.github/workflows/basic_checks.yml index 8180f057f9f..d58449b6611 100644 --- a/.github/workflows/basic_checks.yml +++ b/.github/workflows/basic_checks.yml @@ -231,13 +231,7 @@ jobs: | while read file; do python ./hal/tests/pinvalidate/pinvalidate.py -vvvfp "${file}"; done git diff --exit-code --diff-filter=d --color - cmake-checks: - env: - NAME: mbed-test-mode-check - ROOT: tools/cmake/tests/mbed_test_mode/ - TOOLCHAIN: GCC_ARM - TARGET_NAME: K64F - PROFILE: develop + cmake-native-unit-tests: runs-on: ubuntu-latest container: image: ghcr.io/armmbed/mbed-os-env:master-latest @@ -252,14 +246,7 @@ jobs: apt-get install -y python3-venv - - name: cmake build - run: | - set -x - 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 }} - cmake --build ${{ env.ROOT }}/cmake_build/${{ env.TARGET_NAME }}/${{ env.PROFILE }}/${{ env.TOOLCHAIN }}/ - - - - name: cmake unittest + name: Build and run unit tests run: | set -x ctest --build-and-test . build --build-generator Ninja --build-options -DMBED_ENABLE_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON --test-command ctest diff --git a/CMakeLists.txt b/CMakeLists.txt index ecfbca1c53a..146b01eeb90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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: @@ -56,7 +56,14 @@ if(MBED_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD) set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "") # Initialize Mbed build system - include(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/app.cmake) + include(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/mbed_toolchain_setup.cmake) +endif() + +# Create project and find compilers (if not already found) +project(mbed-os LANGUAGES C CXX ASM) + +if(MBED_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD) + include(mbed_project_setup) endif() if(MBED_IS_NATIVE_BUILD) @@ -85,9 +92,6 @@ endif() # Create core Mbed OS targets and set up build flags ---------------------------------------------------------------------------------- -# Create project and find compilers (if not already found) -project(mbed-os LANGUAGES C CXX ASM) - # Add all paths to the module files within Mbed OS list(APPEND CMAKE_MODULE_PATH ${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts @@ -291,19 +295,3 @@ if(NOT MBED_IS_NATIVE_BUILD) mbed_extract_flags(${MBED_TARGET_CMAKE_NAME}-flags ${MBED_TARGET_CMAKE_NAME}) target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-flags) endif() - -# Ninja requires to be forced for response files -if ("${CMAKE_GENERATOR}" MATCHES "Ninja") - # known issue ARMClang and Ninja with response files for windows - # https://gitlab.kitware.com/cmake/cmake/-/issues/21093 - # This gets fixed in newer cmake version - # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6484 - if((CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") AND ((${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.22.0") OR (NOT CMAKE_CXX_COMPILER_ID MATCHES "ARMClang"))) - set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "") - endif() -endif() - -# If this is the top-level buildscript, run finalize tasks -if(MBED_IS_STANDALONE AND (NOT MBED_IS_NATIVE_BUILD)) - mbed_finalize_build() -endif() \ No newline at end of file diff --git a/tools/cmake/app.cmake b/tools/cmake/app.cmake index 6ab3bec629b..22cc329ecad 100644 --- a/tools/cmake/app.cmake +++ b/tools/cmake/app.cmake @@ -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. For more info, see https://github.com/mbed-ce/mbed-os/pull/421") -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) \ No newline at end of file diff --git a/tools/cmake/mbed_ide_debug_cfg_generator.cmake b/tools/cmake/mbed_ide_debug_cfg_generator.cmake index 3e9de26300f..720be3acfad 100644 --- a/tools/cmake/mbed_ide_debug_cfg_generator.cmake +++ b/tools/cmake/mbed_ide_debug_cfg_generator.cmake @@ -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 # ------------------------------------------------------------- @@ -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 @@ -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} @@ -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() diff --git a/tools/cmake/mbed_project_setup.cmake b/tools/cmake/mbed_project_setup.cmake new file mode 100644 index 00000000000..d3102850910 --- /dev/null +++ b/tools/cmake/mbed_project_setup.cmake @@ -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() diff --git a/tools/cmake/mbed_python_interpreter.cmake b/tools/cmake/mbed_python_interpreter.cmake index c3005b7d7a1..57691a2546b 100644 --- a/tools/cmake/mbed_python_interpreter.cmake +++ b/tools/cmake/mbed_python_interpreter.cmake @@ -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) diff --git a/tools/cmake/mbed_target_functions.cmake b/tools/cmake/mbed_target_functions.cmake index a2a7d299c14..44eb0d9d1fc 100644 --- a/tools/cmake/mbed_target_functions.cmake +++ b/tools/cmake/mbed_target_functions.cmake @@ -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) diff --git a/tools/cmake/mbed_toolchain.cmake b/tools/cmake/mbed_toolchain.cmake index fd5f85d1e92..9a287e84d5b 100644 --- a/tools/cmake/mbed_toolchain.cmake +++ b/tools/cmake/mbed_toolchain.cmake @@ -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) diff --git a/tools/cmake/mbed_toolchain_setup.cmake b/tools/cmake/mbed_toolchain_setup.cmake new file mode 100644 index 00000000000..741d50590de --- /dev/null +++ b/tools/cmake/mbed_toolchain_setup.cmake @@ -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) diff --git a/tools/cmake/tests/mbed_test_mode/CMakeLists.txt b/tools/cmake/tests/mbed_test_mode/CMakeLists.txt deleted file mode 100644 index 073d18ddcfc..00000000000 --- a/tools/cmake/tests/mbed_test_mode/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# 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 "") - -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 -) diff --git a/tools/cmake/tests/mbed_test_mode/main.cpp b/tools/cmake/tests/mbed_test_mode/main.cpp deleted file mode 100644 index dc16f658508..00000000000 --- a/tools/cmake/tests/mbed_test_mode/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2021 Arm Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if MBED_ENABLE_TESTING && !defined(MBED_TEST_MODE) -#error "MBED_TEST_MODE not defined with MBED_ENABLE_TESTING on" -#else -int main(){ - return 0; -} -#endif diff --git a/tools/cmake/tests/multiple_executables/CMakeLists.txt b/tools/cmake/tests/multiple_executables/CMakeLists.txt index fd4d6246181..b0b320b4c5e 100644 --- a/tools/cmake/tests/multiple_executables/CMakeLists.txt +++ b/tools/cmake/tests/multiple_executables/CMakeLists.txt @@ -5,9 +5,9 @@ cmake_minimum_required(VERSION 3.19.0) set(MBED_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../..") -include("${MBED_PATH}/tools/cmake/app.cmake") - +include(${MBED_PATH}/tools/cmake/mbed_toolchain_setup.cmake) project(multiple_executables) +include(mbed_project_setup) add_subdirectory("${MBED_PATH}" "mbed-os-build") diff --git a/tools/cmake/toolchains/GCC_ARM.cmake b/tools/cmake/toolchains/GCC_ARM.cmake index 5341f910934..8669f03eed2 100644 --- a/tools/cmake/toolchains/GCC_ARM.cmake +++ b/tools/cmake/toolchains/GCC_ARM.cmake @@ -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 diff --git a/tools/python/memap/memap.py b/tools/python/memap/memap.py index e098265ca50..df86bf7b95e 100644 --- a/tools/python/memap/memap.py +++ b/tools/python/memap/memap.py @@ -51,6 +51,7 @@ from typing import Optional, TextIO from abc import abstractmethod, ABC from sys import stdout, exit, argv, path +import sys from os import sep from os.path import (basename, dirname, join, relpath, abspath, commonprefix, splitext) @@ -60,7 +61,15 @@ from argparse import ArgumentParser from copy import deepcopy from collections import defaultdict -from prettytable import PrettyTable, HEADER +from prettytable import PrettyTable + +# prettytable moved this constant into an enum in the Python 3.9 release. +if sys.version_info >= (3, 9): + from prettytable import HRuleStyle + HEADER = HRuleStyle.HEADER +else: + from prettytable import HEADER + from jinja2 import FileSystemLoader, StrictUndefined from jinja2.environment import Environment diff --git a/tools/requirements.txt b/tools/requirements.txt index 44ea556e748..89c71f23719 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -1,5 +1,8 @@ -PrettyTable<=1.0.1; python_version < '3.6' -prettytable>=2.0,<4.0; python_version >= '3.6' + +# 3.12.0 both added HRuleStyle and deprecated the old constants in one single release :/ +prettytable>=2.0,<3.12.0; python_version < '3.9' +prettytable>=3.12.0; python_version >= '3.9' + future>=0.18.0,<1.0 jinja2>=2.11.3 intelhex>=2.3.0,<3.0.0