Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split app.cmake into two parts to fix CMake deprecation warning #421

Merged
merged 5 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 2 additions & 15 deletions .github/workflows/basic_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
30 changes: 9 additions & 21 deletions 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 Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
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. 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)
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)
20 changes: 0 additions & 20 deletions tools/cmake/tests/mbed_test_mode/CMakeLists.txt

This file was deleted.

Loading
Loading